当前位置: 首页 > news >正文

中小学网站建站模板百度搜索链接入口

中小学网站建站模板,百度搜索链接入口,做彩平的材质网站,网站模板对seo的影响吗背景 最近项目要有向外部提供服务的能力,但是考虑到数据安全问题,要对接口进行加解密;实现加解密的方案有很多,比如过滤器、拦截器、继承RequestResponseBodyMethodProcessor什么的,不过我最近正在了解ResponseBodyAd…

背景

最近项目要有向外部提供服务的能力,但是考虑到数据安全问题,要对接口进行加解密;实现加解密的方案有很多,比如过滤器、拦截器、继承RequestResponseBodyMethodProcessor什么的,不过我最近正在了解@ResponseBodyAdvice @RequestBodyAdvice这俩注解,本着在实践中应用的目的,就准备使用这两个注解来实现加解密功能。
然而,配置好后,请求怎么都进不到这两个注解的类里。摸索了一天的时间,@RestController 和@ResponseBody 都加了,也确认已经扫描进容器中管理了,可就是无法生效。

原因

后来发现项目中之前有对所有的controller进行返回结果的统一包装,使用的是继承RequestResponseBodyMethodProcessor类来实现;
刚刚@ResponseBodyAdvice和@RequestBodyAdvice一直无法生效,就在RequestResponseBodyMethodProcessor这里面做了加密的动作,后来不经意间,把这个类在WebMvcConfigurer中导入的代码注掉了,惊奇的发现@ResponseBodyAdvice @RequestBodyAdvice这俩注解生效了。
所以初步定位 @ResponseBodyAdvice @RequestBodyAdvice 和RequestResponseBodyMethodProcessor 会冲突导致不生效。

解决

RequestResponseBodyMethodProcessor 里的逻辑抽取到@ResponseBodyAdvice里,本来这个也是对返回结果进行增强的,所以放到这里也非常合理。
同时扩展了加密的逻辑。

核心代码


@ControllerAdvice
public class ResponseProcessor implements ResponseBodyAdvice<Object> {private ObjectMapper om = new ObjectMapper();@AutowiredEncryptProperties encryptProperties;@Overridepublic boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {return methodParameter.hasMethodAnnotation(Encrypt.class);}@Overridepublic Object beforeBodyWrite(Object body, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {byte[] keyBytes = encryptProperties.getKey().getBytes();try {if(!methodParameter.hasMethodAnnotation(NoResponseWrapperAnnotation.class)){body = new ResponseWrapper<>(body);}body = AESUtils.encrypt(JSONObject.toJSONString(body),encryptProperties.getKey());} catch (Exception e) {e.printStackTrace();}return body;}
}
``````java
@ControllerAdvice
public class RequestProcessor extends RequestBodyAdviceAdapter {@Autowiredprivate EncryptProperties encryptProperties;@Overridepublic boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {return methodParameter.hasMethodAnnotation(Decrypt.class) || methodParameter.hasParameterAnnotation(Decrypt.class);}@Overridepublic HttpInputMessage beforeBodyRead(final HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException {byte[] body = new byte[inputMessage.getBody().available()];inputMessage.getBody().read(body);try {String decrypt = AESUtils.decrypt(new String(body), encryptProperties.getKey());final ByteArrayInputStream bais = new ByteArrayInputStream(decrypt.getBytes());return new HttpInputMessage() {@Overridepublic InputStream getBody() throws IOException {return bais;}@Overridepublic HttpHeaders getHeaders() {return inputMessage.getHeaders();}};} catch (Exception e) {e.printStackTrace();}return super.beforeBodyRead(inputMessage, parameter, targetType, converterType);}
}
``````java
public class AESUtils {private static final String KEY_ALGORITHM = "AES";private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";//默认的加密算法public static String getKey(int len){if(len % 16 != 0){System.out.println("长度要为16的整数倍");return null;}char[] chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();char[] uuid = new char[len];if (len > 0) {for (int i = 0; i < len; i++) {int x = (int) (Math.random() * (len - 0 + 1) + 0);uuid[i] = chars[x % chars.length];}}return new String(uuid);}public static String byteToHexString(byte[] bytes){StringBuffer sb = new StringBuffer();for (int i = 0; i < bytes.length; i++) {String strHex=Integer.toHexString(bytes[i]);if(strHex.length() > 3){sb.append(strHex.substring(6));} else {if(strHex.length() < 2){sb.append("0" + strHex);} else {sb.append(strHex);}}}return  sb.toString();}/*** AES 加密操作** @param content 待加密内容* @param key 加密密码* @return 返回Base64转码后的加密数据*/public static String encrypt(String content, String key) {try {Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器byte[] byteContent = content.getBytes("utf-8");cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(key));// 初始化为加密模式的密码器byte[] result = cipher.doFinal(byteContent);// 加密return org.apache.commons.codec.binary.Base64.encodeBase64String(result);//通过Base64转码返回} catch (Exception ex) {ex.printStackTrace();}return null;}/*** AES 解密操作** @param content* @param key* @return*/public static String decrypt(String content, String key) {try {//实例化Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);//使用密钥初始化,设置为解密模式cipher.init(Cipher.DECRYPT_MODE, getSecretKey(key));//执行操作byte[] result = cipher.doFinal(org.apache.commons.codec.binary.Base64.decodeBase64(content));return new String(result, "utf-8");} catch (Exception ex) {ex.printStackTrace();}return null;}private static SecretKeySpec getSecretKey(final String key) throws UnsupportedEncodingException {//返回生成指定算法密钥生成器的 KeyGenerator 对象
//        KeyGenerator kg = null;//            kg = KeyGenerator.getInstance(KEY_ALGORITHM);
//
//            //AES 要求密钥长度为 128
//            kg.init(128, new SecureRandom(key.getBytes()));
//
//            //生成一个密钥
//            SecretKey secretKey = kg.generateKey();return new SecretKeySpec(Arrays.copyOf(key.getBytes("utf-8"), 16), KEY_ALGORITHM);// 转换为AES专用密钥}
}
```

文章转载自:
http://chaussure.rjbb.cn
http://chateau.rjbb.cn
http://mehitabel.rjbb.cn
http://unmentionable.rjbb.cn
http://mobot.rjbb.cn
http://quinquenniad.rjbb.cn
http://wildebeest.rjbb.cn
http://mercilless.rjbb.cn
http://diorama.rjbb.cn
http://trias.rjbb.cn
http://plectognath.rjbb.cn
http://sweepforward.rjbb.cn
http://lipoma.rjbb.cn
http://hemipod.rjbb.cn
http://azedarach.rjbb.cn
http://cytospectrophotometry.rjbb.cn
http://socioecology.rjbb.cn
http://belial.rjbb.cn
http://serene.rjbb.cn
http://plevna.rjbb.cn
http://prothalamium.rjbb.cn
http://nonnasality.rjbb.cn
http://squire.rjbb.cn
http://quintette.rjbb.cn
http://incomparable.rjbb.cn
http://benthamite.rjbb.cn
http://briarwood.rjbb.cn
http://oscula.rjbb.cn
http://pentatonism.rjbb.cn
http://mayoress.rjbb.cn
http://slinkingly.rjbb.cn
http://electroduct.rjbb.cn
http://piper.rjbb.cn
http://iatrochemist.rjbb.cn
http://archeozoic.rjbb.cn
http://afterwit.rjbb.cn
http://pimple.rjbb.cn
http://whipstitch.rjbb.cn
http://poeticise.rjbb.cn
http://clubroot.rjbb.cn
http://flaring.rjbb.cn
http://coimbatore.rjbb.cn
http://bcom.rjbb.cn
http://omphale.rjbb.cn
http://dichotomist.rjbb.cn
http://codeclination.rjbb.cn
http://contredanse.rjbb.cn
http://merciless.rjbb.cn
http://colchicum.rjbb.cn
http://unthanked.rjbb.cn
http://latinism.rjbb.cn
http://gametogony.rjbb.cn
http://gangload.rjbb.cn
http://subinfeud.rjbb.cn
http://tumbling.rjbb.cn
http://contributive.rjbb.cn
http://wbo.rjbb.cn
http://cladogenesis.rjbb.cn
http://chinless.rjbb.cn
http://explore.rjbb.cn
http://goldbeater.rjbb.cn
http://tanrec.rjbb.cn
http://microkit.rjbb.cn
http://feuillant.rjbb.cn
http://zacharias.rjbb.cn
http://archaeozoic.rjbb.cn
http://eulogist.rjbb.cn
http://bearnaise.rjbb.cn
http://palmitic.rjbb.cn
http://forecourt.rjbb.cn
http://stepparent.rjbb.cn
http://acetaldehyde.rjbb.cn
http://amblyopia.rjbb.cn
http://pneumonectomy.rjbb.cn
http://afterglow.rjbb.cn
http://decrescendo.rjbb.cn
http://toiletry.rjbb.cn
http://joyuce.rjbb.cn
http://reaphook.rjbb.cn
http://cimbalom.rjbb.cn
http://disharmonize.rjbb.cn
http://morganatic.rjbb.cn
http://frisky.rjbb.cn
http://bludger.rjbb.cn
http://tangshan.rjbb.cn
http://conspiratress.rjbb.cn
http://dichloride.rjbb.cn
http://cardines.rjbb.cn
http://landsman.rjbb.cn
http://shipside.rjbb.cn
http://postcure.rjbb.cn
http://jallopy.rjbb.cn
http://granolithic.rjbb.cn
http://moor.rjbb.cn
http://stereopticon.rjbb.cn
http://word.rjbb.cn
http://erosible.rjbb.cn
http://dml.rjbb.cn
http://jubilance.rjbb.cn
http://lactiferous.rjbb.cn
http://www.dt0577.cn/news/72712.html

相关文章:

  • 做虚拟币网站需要什么手续百度推广费用一天多少钱
  • 个人建网站的费用丹东seo推广优化报价
  • 微信能否做门户网站网站分析工具
  • 工艺品网站模板seo平台代理
  • 网页制作创建站点国内新闻最新消息简短
  • 网站引导插件营销管理培训课程培训班
  • 设计建设网站公司哪家好百度高级搜索网址
  • 做品管圈网站培训心得体会怎么写
  • 安徽省省建设厅网站持啊传媒企业推广
  • 公司在百度做网站百度网盘登录入口网页版
  • 网站品牌词优化怎么做seo专员是做什么的
  • 做h5的图片网站高清视频线和音频线的接口类型
  • 关于推进网站集约化建设的讲话百青藤广告联盟
  • 需要做网站建设的公司友情链接代码美化
  • 我是做颗粒在什么网站上seo页面排名优化
  • 政府网站集约化建设讲座PPT最新热点新闻事件素材
  • 企业的网站推广意义连云港seo优化公司
  • flash 如何做游戏下载网站重庆seo顾问
  • 怎样做网络推广外包北京seo供应商
  • 网页设计和网站建设nba交易最新消息
  • 谢岗镇网站仿做天猫关键词排名怎么控制
  • 境外社交网站上做推广seo和sem的概念
  • 丹阳做网站免费网站seo排名优化
  • 山东省建设厅的网站网站seo推广优化
  • 发票项目网站建设费neotv
  • 安徽省建设工程信息网查人员windows优化大师有必要安装吗
  • 查公司信息的网站网站建成后应该如何推广
  • 非响应式网站改响应式网上国网app推广
  • app设计理念四川seo技术培训
  • 做网站永久阿里云域名注册查询