拦截改为动态配置

master
jiakun.lin 4 years ago
parent 32fe3af1fd
commit a966e1ba7f
  1. 36
      src/main/java/com/yipin/liuwanr/config/AuthConfig.java
  2. 7
      src/main/resources/application-keda.properties
  3. 7
      src/main/resources/application-prod.properties
  4. 7
      src/main/resources/application-test.properties
  5. 7
      src/main/resources/application-test_keda.properties

@ -1,20 +1,42 @@
package com.yipin.liuwanr.config; package com.yipin.liuwanr.config;
/**
* @description
* @author: Mr.JK
* @create: 2021-06-03 16:24
**/
import com.yipin.liuwanr.filter.AuthInterceptor; import com.yipin.liuwanr.filter.AuthInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/**
* @description
* @author: Mr.JK
* @create: 2021-06-03 16:24
**/
@Configuration @Configuration
@ConfigurationProperties(prefix = "auth")
public class AuthConfig implements WebMvcConfigurer { public class AuthConfig implements WebMvcConfigurer {
//开启拦截字符串
public static String openInterceptStr;
//放行url
public static List<String> permitUrl;
@Value("${auth.openInterceptStr}")
public void setOpenInterceptStr(String openInterceptStr) {
AuthConfig.openInterceptStr = openInterceptStr;
}
@Value("${auth.permitUrl}")
public void setPermitUrl(List<String> permitUrl) {
AuthConfig.permitUrl = permitUrl;
}
@Bean @Bean
public AuthInterceptor initAuthInterceptor(){ public AuthInterceptor initAuthInterceptor(){
return new AuthInterceptor(); return new AuthInterceptor();
@ -22,8 +44,8 @@ public class AuthConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/**") registry.addInterceptor(initAuthInterceptor()).addPathPatterns(openInterceptStr)
.excludePathPatterns("/userInfo/adminLogins/**","/userInfo/loginSchoolClient/**","/userInfo/logins/**","/userInfo/updateLogInNumber/**"); .excludePathPatterns(permitUrl);
} }
} }

@ -47,3 +47,10 @@ spring.servlet.multipart.maxRequestSize=10240MB
pagehelper.reasonable=false pagehelper.reasonable=false
#开启全局拦截,为空不开启拦截
#auth.openInterceptStr=
auth.openInterceptStr=/**
#放行Url
auth.permitUrl=/userInfo/adminLogins/**,/userInfo/loginSchoolClient/**,/province/queryProvince/**,/city/queryCity/**,/customer/querySchool/**,/userInfo/queryPhone/**

@ -47,3 +47,10 @@ spring.servlet.multipart.maxRequestSize=10240MB
pagehelper.reasonable=false pagehelper.reasonable=false
#开启全局拦截,为空不开启拦截
#auth.openInterceptStr=
auth.openInterceptStr=/**
#放行Url
auth.permitUrl=/userInfo/adminLogins/**,/userInfo/loginSchoolClient/**,/province/queryProvince/**,/city/queryCity/**,/customer/querySchool/**,/userInfo/queryPhone/**

@ -47,3 +47,10 @@ spring.servlet.multipart.maxRequestSize=10240MB
pagehelper.reasonable=false pagehelper.reasonable=false
#开启全局拦截,为空不开启拦截
#auth.openInterceptStr=
auth.openInterceptStr=/**
#放行Url
auth.permitUrl=/userInfo/adminLogins/**,/userInfo/loginSchoolClient/**,/province/queryProvince/**,/city/queryCity/**,/customer/querySchool/**,/userInfo/queryPhone/**

@ -47,3 +47,10 @@ spring.servlet.multipart.maxRequestSize=10240MB
pagehelper.reasonable=false pagehelper.reasonable=false
#开启全局拦截,为空不开启拦截
#auth.openInterceptStr=
auth.openInterceptStr=/**
#放行Url
auth.permitUrl=/userInfo/adminLogins/**,/userInfo/loginSchoolClient/**,/province/queryProvince/**,/city/queryCity/**,/customer/querySchool/**,/userInfo/queryPhone/**

Loading…
Cancel
Save