首页 > 其他分享 >springboot 接口返回数据统一加密

springboot 接口返回数据统一加密

时间:2024-06-06 16:44:45浏览次数:13  
标签:methodName springboot 接口 method log 加密 response pjp String

 

 

@Aspect
@Component
@Slf4j
public class AESTimeAspect {

    @Around("execution(* com.trt.sea.xxserx.controller*..*Controller.*(..))")
    public Object handleAroundControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = sra.getRequest();
        String method = request.getMethod();
        String className = pjp.getTarget().getClass().getSimpleName();
        String methodName = pjp.getSignature().getName();
        Object[] args = pjp.getArgs();
        // 解决部分参数不能序列化问题 It is illegal to call this method if the current request is not in asynchronous mode
        List<Object> logArgs = (ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.stream(args)).filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
                .collect(Collectors.toList());
        String contentType = request.getHeader("Content-Type")+"";
        if("GET".equalsIgnoreCase(method)){
            log.info("^^ enter {}.{} receive data with : {} ^", className,methodName,logArgs);
        }else
        {
            if(contentType.contains("x-www-form-urlencoded")){
                log.info("^^ enter {}.{} ^^", className,methodName);
            }else {
                //multipart/form-data    text/xml (xml)
                log.info("^^ enter {}.{} receive data with : {} ^^", className,methodName, JSON.toJSONString(logArgs));
            }
        }
        Object object = pjp.proceed();
        String costTime = (System.currentTimeMillis() - start) + "";
        log.info("*** end  run the method --> {} total cost time is {} ms ***", methodName, costTime);


        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();

        // 我的所有响应数据都属JSONObject  统一加密
        if (response != null && (object instanceof JSONObject)) {
            String resTs = System.currentTimeMillis() + "";
            JSONObject resJson = (JSONObject) object;
            // 加密  todo  然后返回数据
            response.addHeader("res-ts",resTs);
            response.setHeader("Access-Control-Expose-Headers","res-ts");
        }
        return object;
    }
}

 

标签:methodName,springboot,接口,method,log,加密,response,pjp,String
From: https://www.cnblogs.com/lshan/p/18235587

相关文章

  • jenkins接入钉钉api接口自动化测试报告自动发送
    一些同学的公司在做接口自动化测试时,难免会要求进行持续集成以及需要将可视化报告发送到诸如钉钉工作群等地方,于是便编写下列相关教程。jenkins上进行持续集成以及接入钉钉前提条件准备好自动化脚本持续集成源代码管理模块安装插件:Gitplugin获取凭证:http拉取链接对应:登录......
  • SpringBoot启动流程分析之准备应用上下文refreshContext()(八)
    SpringBoot启动流程分析之准备应用上下文refreshContext()(八)文章目录SpringBoot启动流程分析之准备应用上下文refreshContext()(八)1、准备刷新1.1、子类prepareRefresh()方法1.2父类prepareRefresh()方法2、通知子类刷新内部bean工厂3、准备bean工厂4、允许上下文子类对b......
  • golang接口请求结构体验证器Validator实现
    一、前提:认识reflect.TypeOf及reflect.ValueOfTypeOf:动态的获取从函数接口中传进去的变量的类型,如果为空则返回值为nil(获取类型对象)可以从该方法获取的对象中拿到字段的所属类型,字段名,以及该字段是否是匿名字段等信息。还可以获取到与该字段进行绑定的tag。ValueO......
  • SpringBoot+Vue房屋租赁网站(前后端分离)
    技术栈JavaSpringBootMavenMySQLVueElement-UIShiroMybatis-Plus系统角色用户管理员房东系统功能截图......
  • SendGrid发送邮件时如何调用API接口群发?
    SendGrid发送邮件模板如何定制?邮件发送限制有哪些?SendGrid发送邮件是一种方便快捷的方式,可以在应用程序或网站中轻松地发送大量邮件。通过调用SendGrid的API接口,您可以实现群发邮件,无论是通知用户、发送营销邮件还是其他目的,都能够高效完成。SendGrid发送邮件:调用接口通过S......
  • kube-platform平台可视化的第一个接口-namespace列表
    目录概述实践代码启动概述  此文完成kube-platform平台的第一个接口namespace列表返回。  kube-platform从平台搭建至完成第一个接口,至此基本框架就已成型,在此对几篇文章做整理。1.kube-plaform-gin框架使用2.kube-plaform-viper框架使用kube-plaform-cl......
  • 企业级数据保护:华企盾DSC敏感内容识别与加密技术
    在当今数字化时代,企业面临的数据安全挑战日益严峻。敏感数据的泄露不仅会导致经济损失,还可能损害企业的声誉和客户信任。因此,采用先进的敏感内容识别和加密技术,例如华企盾DSC敏感内容识别,对企业数据进行有效保护至关重要。一、敏感内容识别的重要性企业内部的敏感数据,如商业机......
  • Java中所有的集合可以分为两大类:接口和实现类。
     接口:Collection:是所有集合的根接口,定义了一组操作集合的基本方法,如添加、删除、遍历等。List:是有序的、可重复的集合,继承自Collection接口。Set:是无序的、不可重复的集合,继承自Collection接口。Queue:是队列接口,用于存储按一定顺序访问的元素。Deque:是双端队列接口,可以......
  • 【第7章】SpringBoot实战篇之用户详细信息
    文章目录前言一、获取用户详细信息1.ThreadLocalUtil2.LoginInceptor3.UserController14.测试二、更新用户基本信息1.ValidatedGroups2.User3.UserController14.service5.测试1.参数校验2.更新测试三、更新用户头像1.UserController12.测试四、更新用户密......
  • 【第8章】SpringBoot实战篇之文章分类(上)
    文章目录前言一、后端代码1.CategoryController2.service3.CategoryMapper4.Category二、测试1.失败(校验)2.正常总结前言从这开始进入文章相关的接口开发,本章主要介绍定义文章分类接口和新增文章分类建表语句和测试用例,在SpringBoot专栏首页,此处只涉及后......