zoukankan      html  css  js  c++  java
  • 关于拦截器是用注解方便,还是用配置文件写死方便的总结。

    总结:

    1.用注解的话,第一次写接口时 需要增加很多注解,但是也是很方便,复制粘贴就可。后期维护灵活度非常大。

    2.用写死的方式的话,拦截器越多,后期维护难度越大,针对/abc接口,可能 a拦截器排除,b拦截器也排除,c拦截器来拦截,那么需要写多次,后期及难维护。举例如下:

    /**
     * 拼多多接口的拦截器配置
     * 1.token
     * 2.shopid
     */
    @Configuration
    public class PinduoduoWebMvcConfigurer_back extends CommonWebMvcConfigurer {
    
        @Autowired
        VerifyRsaTokenInterceptor verifyRsaTokenInterceptor;
    
        @Autowired
        VerifyShopIdInterceptor verifyShopIdInterceptor;
    
        @Autowired
        VerifyAesTokenInterceptor verifyAesTokenInterceptor;
    
    
        /**
         * 将拦截器注册到此项目中.
         */
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
    
            /*
             1.验证token
             */
            registry.addInterceptor(verifyRsaTokenInterceptor).addPathPatterns("/**")
                    .excludePathPatterns("/buildToken") //这里需要写多次,拦截器越多,重复写的次数越多,后期越难维护
                    .excludePathPatterns("/importShopId")
                    .excludePathPatterns("/PinduoduoShopStatusGet")
                    .excludePathPatterns("/slb.html")
    
                    /*
                     1.TaobaoJushitaJdpUsersGet 需要这个来统计活跃度。这个接口需要的安全度不高,delphi和guanli模块都有调用,完全开放。
                     2.TaobaoJushitaJdpUserDelete 需要用这个来定时关闭 数据推送,不可拦截。用下面的Aes128拦截器拦截。
                     */
                    .excludePathPatterns("/PddDdyPdpUsersGet")
                    .excludePathPatterns("/PddDdyPdpUserDelete")
    
                    .order(1);
    
    
            /*
             2.验证shopId
             */
            registry.addInterceptor(verifyShopIdInterceptor).addPathPatterns("/**")
                    .excludePathPatterns("/buildToken")
                    .excludePathPatterns("/importShopId")
                    .excludePathPatterns("/PinduoduoShopStatusGet")
                    .excludePathPatterns("/slb.html")
    
                    /*
                     1.TaobaoJushitaJdpUsersGet 需要这个来统计活跃度。这个接口需要的安全度不高,delphi和guanli模块都有调用,完全开放。
                     2.TaobaoJushitaJdpUserDelete  需要用这个来定时关闭 数据推送,不可拦截。用下面的Aes128拦截器拦截。
                     */
                    .excludePathPatterns("/PddDdyPdpUsersGet")
                    .excludePathPatterns("/PddDdyPdpUserDelete")
    
                    .order(2);
    
    
            /*
             3.有一些接口,无法验证颁发的token,为了安全,避免接口完全开放,
               这类接口利用对称秘钥,验证固定字符串,只增加需要拦截的。多数不需要这个拦截器拦截。
               TaobaoJushitaJdpUserDelete -- 场景为,需要 guanli 模块定时调用,其它模块基本用不到。
             */
            registry.addInterceptor(verifyAesTokenInterceptor).addPathPatterns("/PddDdyPdpUserDelete").order(3);
        }
    @Configuration
    public class TaobaoWebMvcConfigurer extends CommonWebMvcConfigurer {
    
        @Autowired
        VerifyRsaTokenInterceptor verifyRsaTokenInterceptor;
    
        @Autowired
        VerifyShopIdInterceptor verifyShopIdInterceptor;
    
        @Autowired
        VerifyAesTokenInterceptor verifyAesTokenInterceptor;
    
        /**
         * 将拦截器注册到此项目中.
         */
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
    
            /*
             1.验证token
             */
            registry.addInterceptor(verifyRsaTokenInterceptor).addPathPatterns("/**")
                    .excludePathPatterns("/buildToken")
                    .excludePathPatterns("/importShopId")
                    .excludePathPatterns("/TaobaoShopStatusGet")
                    .excludePathPatterns("/slb.html")
    
                    /*
                     1.TaobaoJushitaJdpUsersGet 需要这个来统计活跃度。这个接口需要的安全度不高,delphi和guanli模块都有调用,完全开放。
                     2.TaobaoJushitaJdpUserDelete 需要用这个来定时关闭 数据推送,不可拦截。用下面的Aes128拦截器拦截。
                     */
                    .excludePathPatterns("/TaobaoJushitaJdpUsersGet")
                    .excludePathPatterns("/TaobaoJushitaJdpUserDelete")
    
    
                    /*
                     御城河日志的,这个比较特殊,因为登录前,登录失败的需要对接日志,而此时并没有http协议头的token。所以这个接口放行。
                     */
                    .excludePathPatterns("/YchLogLogin")
                    .order(1);
    
    
            /*
             2.验证shopId
             */
            registry.addInterceptor(verifyShopIdInterceptor).addPathPatterns("/**")
                    .excludePathPatterns("/buildToken")
                    .excludePathPatterns("/importShopId")
                    .excludePathPatterns("/TaobaoShopStatusGet")
                    .excludePathPatterns("/slb.html")
    
                    /*
                     1.TaobaoJushitaJdpUsersGet 需要这个来统计活跃度。这个接口需要的安全度不高,delphi和guanli模块都有调用,完全开放。
                     2.TaobaoJushitaJdpUserDelete  需要用这个来定时关闭 数据推送,不可拦截。用下面的Aes128拦截器拦截。
                     */
                    .excludePathPatterns("/TaobaoJushitaJdpUsersGet")
                    .excludePathPatterns("/TaobaoJushitaJdpUserDelete")
    
    
                    /*
                     御城河日志相关的5个接口,不做shopId校验,让这5个接口通过。
                     */
                    .excludePathPatterns("/YchLogTop")
                    .excludePathPatterns("/YchLogSql")
                    .excludePathPatterns("/YchLogLogin")
                    .excludePathPatterns("/YchLogOrder")
                    .excludePathPatterns("/YchLogSendOrder")
                    .order(2);
    
    
            /*
             3.有一些接口,无法验证颁发的token,为了安全,避免接口完全开放,
               这类接口利用对称秘钥,验证固定字符串,只增加需要拦截的。多数不需要这个拦截器拦截。
               TaobaoJushitaJdpUserDelete -- 场景为,需要 guanli 模块定时调用,其它模块基本用不到。
             */
            registry.addInterceptor(verifyAesTokenInterceptor).addPathPatterns("/TaobaoJushitaJdpUserDelete").order(3);
        }
    }
  • 相关阅读:
    poj 2049 Let it Bead(polya模板)
    poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
    poj 2226 Muddy Fields(最小点覆盖+巧妙构图)
    poj 3692 Kindergarten (最大独立集之逆匹配)
    poj 1466 Girls and Boys(二分匹配之最大独立集)
    poj 1486 Sorting Slides(二分图匹配的查找应用)
    poj 2112 Optimal Milking (二分图匹配的多重匹配)
    PHP访问控制
    OO(Object Oriented)
    重载与重写以及重构
  • 原文地址:https://www.cnblogs.com/del88/p/13169010.html
Copyright © 2011-2022 走看看