# WebConfig.java

    package cloud.wconnect.rateshop.config;

    import cloud.wconnect.commonlib.interceptor.*;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

    /**
     * 配置类：Spring MVC相关配置
     *
     * @author chenx
     * @date 2021/3/1
     */
    @Configuration
    public class WebConfig implements WebMvcConfigurer {
        @Value("${cors.ips}")
        private String[] corsIps;
        @Value("${cors.methods}")
        private String[] corsMethods;
        @Value("${cors.headers}")
        private String[] corsHeaders;

        /**
         * 认证拦截器
         */
        @Bean
        public CertificationInterceptor certificationInterceptor() {
            return new CertificationInterceptor();
        }

        /**
         * 鉴权拦截器
         */
        @Bean
        public AuthorizationInterceptor authorizationInterceptor() {
            return new AuthorizationInterceptor();
        }

        /**
         * 系统版本检测拦截器
         */
        @Bean
        public VersionCheckInterceptor versionCheckInterceptor() {
            return new VersionCheckInterceptor();
        }

        /**
         * 权限变更检测拦截器
         */
        @Bean
        public AclChangedInterceptor aclChangedInterceptor() {
            return new AclChangedInterceptor();
        }

        /**
         * 请求参数检测拦截器
         */
        @Bean
        public RequestParameterInterceptor requestParameterInterceptor() {
            return new RequestParameterInterceptor();
        }

        /**
         * 校验资产开通功能拦截器
         */
        @Bean
        public CheckPropertyOpenFunInterceptor checkPropertyOpenFunInterceptor(){
            return new CheckPropertyOpenFunInterceptor();
        }

        /**
         * 添加拦截器
         *
         * @param registry 拦截器注册器
         * @author chenx
         * @date 2021/3/25
         */
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            String errorUri = "/error";
            String internalUri = "/internal/**";
            String thirdPartyUri = "/3p-integration/**";
            String moduleEventUri = "/module-integration/**";

            String[] excludePathArr = new String[]{errorUri, internalUri, thirdPartyUri, moduleEventUri};

            // 系统版本检测拦截器
            /*registry.addInterceptor(versionCheckInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(excludePathArr);*/

            // 认证拦截器
            registry.addInterceptor(certificationInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(excludePathArr);
            // 权限变更检测拦截器
            registry.addInterceptor(aclChangedInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(excludePathArr);
            // 请求参数拦截器
            registry.addInterceptor(requestParameterInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(excludePathArr);
            // 资产开通功能拦截器
            registry.addInterceptor(checkPropertyOpenFunInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(excludePathArr);
            // 鉴权拦截器
            registry.addInterceptor(authorizationInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(excludePathArr);
        }

        /**
         * 跨域请求处理
         */
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins(corsIps)
                    .allowedMethods(corsMethods)
                    .allowedHeaders(corsHeaders)
                    .allowCredentials(true)
                    .maxAge(3600);
        }
    }