|
@@ -1,12 +1,14 @@
|
|
package com.shkpr.service.alambizplugin.controllerfilter;
|
|
package com.shkpr.service.alambizplugin.controllerfilter;
|
|
|
|
+
|
|
import com.global.base.log.LogLevelFlag;
|
|
import com.global.base.log.LogLevelFlag;
|
|
import com.global.base.log.LogPrintMgr;
|
|
import com.global.base.log.LogPrintMgr;
|
|
import com.shkpr.service.alambizplugin.commtools.HttpTool;
|
|
import com.shkpr.service.alambizplugin.commtools.HttpTool;
|
|
|
|
+import com.shkpr.service.alambizplugin.constants.ApiURI;
|
|
import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
|
|
import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
|
|
|
|
+import com.shkpr.service.alambizplugin.constants.ResponseCode;
|
|
import com.shkpr.service.alambizplugin.controllercheck.JWTControllerCheck;
|
|
import com.shkpr.service.alambizplugin.controllercheck.JWTControllerCheck;
|
|
import com.shkpr.service.alambizplugin.exception.SelfAuthFilterException;
|
|
import com.shkpr.service.alambizplugin.exception.SelfAuthFilterException;
|
|
import com.shkpr.service.alambizplugin.globalcache.GlobalData;
|
|
import com.shkpr.service.alambizplugin.globalcache.GlobalData;
|
|
-import com.shkpr.service.alambizplugin.constants.ResponseCode;
|
|
|
|
import org.springframework.security.authentication.AccountExpiredException;
|
|
import org.springframework.security.authentication.AccountExpiredException;
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -16,6 +18,8 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
|
|
+import org.springframework.util.AntPathMatcher;
|
|
|
|
+import org.springframework.util.PathMatcher;
|
|
|
|
|
|
import javax.servlet.FilterChain;
|
|
import javax.servlet.FilterChain;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletException;
|
|
@@ -29,13 +33,15 @@ import java.io.IOException;
|
|
* 如果校验通过,就认为这是一个取得授权的合法请求
|
|
* 如果校验通过,就认为这是一个取得授权的合法请求
|
|
*/
|
|
*/
|
|
public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
|
|
public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
|
|
- private RequestMatcher mRequestMatcher = null;
|
|
|
|
protected String mStrThisSampleName = null;
|
|
protected String mStrThisSampleName = null;
|
|
protected JWTControllerCheck mControllerCheck = null;
|
|
protected JWTControllerCheck mControllerCheck = null;
|
|
|
|
+ private RequestMatcher mRequestMatcher = null;
|
|
|
|
+ private PathMatcher mPathMatcher = null;
|
|
|
|
|
|
public JWTAuthenticationFilter(AuthenticationManager authenticationManager){
|
|
public JWTAuthenticationFilter(AuthenticationManager authenticationManager){
|
|
super(authenticationManager);
|
|
super(authenticationManager);
|
|
this.mStrThisSampleName = this.getClass().getSimpleName();
|
|
this.mStrThisSampleName = this.getClass().getSimpleName();
|
|
|
|
+ mPathMatcher = new AntPathMatcher();
|
|
}
|
|
}
|
|
|
|
|
|
public JWTAuthenticationFilter(String url, AuthenticationManager authenticationManager){
|
|
public JWTAuthenticationFilter(String url, AuthenticationManager authenticationManager){
|
|
@@ -43,6 +49,7 @@ public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
|
|
this.mStrThisSampleName = this.getClass().getSimpleName();
|
|
this.mStrThisSampleName = this.getClass().getSimpleName();
|
|
if (url != null && !url.isEmpty())
|
|
if (url != null && !url.isEmpty())
|
|
this.mRequestMatcher = new AntPathRequestMatcher(url);
|
|
this.mRequestMatcher = new AntPathRequestMatcher(url);
|
|
|
|
+ mPathMatcher = new AntPathMatcher();
|
|
}
|
|
}
|
|
|
|
|
|
public void setControllerCheck(JWTControllerCheck mControllerCheck) {
|
|
public void setControllerCheck(JWTControllerCheck mControllerCheck) {
|
|
@@ -56,6 +63,17 @@ public class JWTAuthenticationFilter extends BasicAuthenticationFilter {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //系统检查结果放行
|
|
|
|
+ if (this.mPathMatcher != null &&
|
|
|
|
+ this.mPathMatcher.match(
|
|
|
|
+ String.format("%s%s", request.getContextPath(), ApiURI.URI_GIS_SURVEY_H + "/" + ApiURI.URI_XXX_SYS_CHECK_RESULTS + "/**"),
|
|
|
|
+ request.getRequestURI()
|
|
|
|
+ )
|
|
|
|
+ ) {
|
|
|
|
+ chain.doFilter(request, response);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (mControllerCheck != null && !mControllerCheck.checkRequest(request, response)) //当前URI已匹配成功,但Request请求格式不对,不再向后传递
|
|
if (mControllerCheck != null && !mControllerCheck.checkRequest(request, response)) //当前URI已匹配成功,但Request请求格式不对,不再向后传递
|
|
return;
|
|
return;
|
|
|
|
|