Change front-end connection address and rollback jwt filter

pull/949/head
chen.ma 2 years ago
parent b288b1f2ad
commit 344f629c74

2
.gitignore vendored

@ -3,6 +3,8 @@ target/
!.mvn/wrapper/maven-wrapper.jar !.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/
!**/src/test/**/target/ !**/src/test/**/target/
!**/node_modules/
!**/dist/
### STS ### ### STS ###
.apt_generated .apt_generated

@ -59,28 +59,22 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
protected void doFilterInternal(HttpServletRequest request, protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, HttpServletResponse response,
FilterChain chain) throws IOException, ServletException { FilterChain chain) throws IOException, ServletException {
boolean checkAccessTokenOrTokenHeader = false;
// Token when verifying client interaction. // Token when verifying client interaction.
String accessToken = request.getParameter(ACCESS_TOKEN); String accessToken = request.getParameter(ACCESS_TOKEN);
String tokenHeader = request.getHeader(JwtTokenUtil.TOKEN_HEADER);
if (StringUtil.isNotBlank(accessToken)) { if (StringUtil.isNotBlank(accessToken)) {
tokenManager.validateToken(accessToken); tokenManager.validateToken(accessToken);
Authentication authentication = this.tokenManager.getAuthentication(accessToken); Authentication authentication = this.tokenManager.getAuthentication(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
checkAccessTokenOrTokenHeader = true; chain.doFilter(request, response);
} else if (checkTokenHeader(tokenHeader)) { return;
// If there is no Authorization information in the request header, it will be released directly.
checkAccessTokenOrTokenHeader = true;
} }
if (checkAccessTokenOrTokenHeader) { // If there is no Authorization information in the request header, it will be released directly.
String tokenHeader = request.getHeader(JwtTokenUtil.TOKEN_HEADER);
if (tokenHeader == null || !tokenHeader.startsWith(JwtTokenUtil.TOKEN_PREFIX)) {
chain.doFilter(request, response); chain.doFilter(request, response);
} else { return;
filterInternal(request, response, chain, tokenHeader);
} }
} // If there is a Token in the request header, it is parsed and the authentication information is set.
private void filterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
String tokenHeader) throws IOException, ServletException {
try { try {
SecurityContextHolder.getContext().setAuthentication(getAuthentication(tokenHeader)); SecurityContextHolder.getContext().setAuthentication(getAuthentication(tokenHeader));
} catch (Exception ex) { } catch (Exception ex) {
@ -96,21 +90,17 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
return; return;
} }
try { try {
doFilterInternal(request, response, chain); super.doFilterInternal(request, response, chain);
} finally { } finally {
UserContext.clear(); UserContext.clear();
} }
} }
private boolean checkTokenHeader(String tokenHeader) {
return tokenHeader == null || !tokenHeader.startsWith(JwtTokenUtil.TOKEN_PREFIX);
}
/** /**
* Obtain user information from Token and create a new Token. * Obtain user information from Token and create a new Token.
* *
* @param tokenHeader tokenHeader * @param tokenHeader token header
* @return UsernamePasswordAuthenticationToken * @return username password authentication token
*/ */
private UsernamePasswordAuthenticationToken getAuthentication(String tokenHeader) { private UsernamePasswordAuthenticationToken getAuthentication(String tokenHeader) {
String token = tokenHeader.replace(JwtTokenUtil.TOKEN_PREFIX, ""); String token = tokenHeader.replace(JwtTokenUtil.TOKEN_PREFIX, "");

@ -46,6 +46,7 @@
"axios": ">=0.18.1", "axios": ">=0.18.1",
"clipboard": "2.0.4", "clipboard": "2.0.4",
"codemirror": "5.45.0", "codemirror": "5.45.0",
"core-js": "^3.26.0",
"echarts": "^5.2.2", "echarts": "^5.2.2",
"element-ui": "^2.15.7", "element-ui": "^2.15.7",
"fuse.js": "3.4.4", "fuse.js": "3.4.4",

@ -35,7 +35,7 @@ module.exports = {
}, },
proxy: { proxy: {
'/hippo4j/v1/cs': { '/hippo4j/v1/cs': {
target: `http://console.hippo4j.cn:80/hippo4j/v1/cs`, target: `http://127.0.0.1:6691/hippo4j/v1/cs`,
changOrigin: true, changOrigin: true,
secure: false, secure: false,
pathRewrite: { pathRewrite: {

Loading…
Cancel
Save