|
@@ -23,30 +23,36 @@ import java.io.IOException;
|
|
|
@Component
|
|
@Component
|
|
|
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
|
|
|
|
|
|
- private static final String SLASH = "/sp/";
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private TokenService tokenService;
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
|
|
|
|
- throws ServletException, IOException {
|
|
|
|
|
- String uri = request.getRequestURI();
|
|
|
|
|
- if (SLASH.equals(uri)) {
|
|
|
|
|
- response.setStatus(302);
|
|
|
|
|
- response.setHeader("location", request.getContextPath() + "/index.html");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
|
|
- if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) {
|
|
|
|
|
- tokenService.verifyToken(loginUser);
|
|
|
|
|
- UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
|
|
|
|
- authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
|
|
- //安全环境是通过调用 SecurityContextHolder.getContext().setAuthentication(…), 传递到返回的验证对象建立的。
|
|
|
|
|
- SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
|
|
- }
|
|
|
|
|
- chain.doFilter(request, response);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private static final String SLASH = "/sp/";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TokenService tokenService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
|
+ String uri = request.getRequestURI();
|
|
|
|
|
+ if (SLASH.equals(uri)) {
|
|
|
|
|
+ response.setStatus(302);
|
|
|
|
|
+ response.setHeader("location", request.getContextPath() + "/index.html");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String path = request.getRequestURI();
|
|
|
|
|
+ if (path.contains("sp/upload/uploadMinio")) {
|
|
|
|
|
+ chain.doFilter(request, response);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
|
|
+ if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) {
|
|
|
|
|
+ tokenService.verifyToken(loginUser);
|
|
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser,
|
|
|
|
|
+ null, loginUser.getAuthorities());
|
|
|
|
|
+ authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
|
|
+ // 安全环境是通过调用 SecurityContextHolder.getContext().setAuthentication(…),
|
|
|
|
|
+ // 传递到返回的验证对象建立的。
|
|
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
|
|
+ }
|
|
|
|
|
+ chain.doFilter(request, response);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|