|
|
@ -15,6 +15,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.opsli.core.security.filter;
|
|
|
|
package org.opsli.core.security.filter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import org.opsli.core.base.dto.LoginUserDto;
|
|
|
|
import org.opsli.core.base.dto.LoginUserDto;
|
|
|
|
import org.opsli.core.security.service.UidUserDetailDetailServiceImpl;
|
|
|
|
import org.opsli.core.security.service.UidUserDetailDetailServiceImpl;
|
|
|
@ -22,6 +23,8 @@ import org.opsli.core.utils.UserTokenUtil;
|
|
|
|
import org.opsli.plugins.security.authentication.AfterAuthenticationToken;
|
|
|
|
import org.opsli.plugins.security.authentication.AfterAuthenticationToken;
|
|
|
|
import org.opsli.plugins.security.exception.AuthException;
|
|
|
|
import org.opsli.plugins.security.exception.AuthException;
|
|
|
|
import org.opsli.plugins.security.exception.errorcode.AuthErrorCodeEnum;
|
|
|
|
import org.opsli.plugins.security.exception.errorcode.AuthErrorCodeEnum;
|
|
|
|
|
|
|
|
import org.opsli.plugins.security.utils.WebUtils;
|
|
|
|
|
|
|
|
import org.opsli.plugins.security.vo.AuthResultWrapper;
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@ -56,6 +59,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
// 验证Token
|
|
|
|
// 验证Token
|
|
|
|
UserTokenUtil.verify(token);
|
|
|
|
UserTokenUtil.verify(token);
|
|
|
|
|
|
|
|
|
|
|
@ -72,10 +76,24 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
|
|
|
|
|
|
|
|
|
|
AfterAuthenticationToken authenticationToken =
|
|
|
|
AfterAuthenticationToken authenticationToken =
|
|
|
|
new AfterAuthenticationToken(userDetails, null, userDetails.getAuthorities());
|
|
|
|
new AfterAuthenticationToken(userDetails, null, userDetails.getAuthorities());
|
|
|
|
|
|
|
|
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
|
|
|
|
|
}catch (AuthException ae){
|
|
|
|
|
|
|
|
// 权校验Token异常
|
|
|
|
|
|
|
|
Integer code = ae.getCode();
|
|
|
|
|
|
|
|
String errorMessage = ae.getErrorMessage();
|
|
|
|
|
|
|
|
AuthResultWrapper<?> customResultWrapper =
|
|
|
|
|
|
|
|
AuthResultWrapper.getCustomResultWrapper(code, errorMessage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebUtils.renderString(request, response, JSONUtil.toJsonStr(customResultWrapper));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
// 其他异常
|
|
|
|
|
|
|
|
AuthResultWrapper<?> customResultWrapper = AuthResultWrapper.getErrorResultWrapper();
|
|
|
|
|
|
|
|
WebUtils.renderString(request, response, JSONUtil.toJsonStr(customResultWrapper));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
//放行
|
|
|
|
//放行
|
|
|
|
filterChain.doFilter(request, response);
|
|
|
|
filterChain.doFilter(request, response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|