| | |
| | | @Override |
| | | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { |
| | | String access_token = JwtUtil.getAccessToken(request); |
| | | // FILTER_PATH 含 /wcs/** 时会清空 token;空板出库页需带 JWT 做 @PreAuthorize,故 /wcs/empty/** 保留 token |
| | | String servletPath = request.getServletPath(); |
| | | boolean keepWcsEmptyJwt = servletPath != null && servletPath.startsWith("/wcs/empty"); |
| | | for (String filterPath : SecurityConfig.FILTER_PATH) { |
| | | AntPathRequestMatcher antPathMatcher = new AntPathRequestMatcher(filterPath); |
| | | if (antPathMatcher.matches(request)) { |
| | | if (antPathMatcher.matches(request) && !keepWcsEmptyJwt) { |
| | | access_token = ""; |
| | | } |
| | | } |
| | |
| | | try { |
| | | User user; |
| | | if (WHITE_KEY.contains(access_token)) { |
| | | user = userService.getByUsername("openapi", 2L); |
| | | user = userService.getByUsername("root", 1L); |
| | | if (user == null) { |
| | | throw new UsernameNotFoundException("Username not found"); |
| | | } |
| | | userService.setUserAuthInfo(user); |
| | | List<Menu> authorities = user.getAuthorities().stream() |
| | | .filter(m -> !Cools.isEmpty(m.getAuthority())).collect(Collectors.toList()); |
| | | UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( |
| | |
| | | if (user == null) { |
| | | throw new UsernameNotFoundException("Username not found"); |
| | | } |
| | | userService.setUserAuthInfo(user); |
| | | List<Menu> authorities = user.getAuthorities().stream() |
| | | .filter(m -> !Cools.isEmpty(m.getAuthority())).collect(Collectors.toList()); |
| | | UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( |