我有一个问题……我有这样的 SecurityConfig.class(这是一个扩展 WebSecurityConfigurerAdapter 的类):/** * This method define which resources are public and which are secured */@Overrideprotected void configure(HttpSecurity http) throws Exception { http.cors().and().csrf().disable().authorizeRequests() .antMatchers(HttpMethod.POST, SecurityConstants.SIGN_UP_URL).permitAll().anyRequest() .authenticated() .and().addFilter(new JWTAuthenticationFilter(authenticationManager())) .addFilter(new JWTAuthorizationFilter(authenticationManager())) .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);}但我的问题是,当我尝试访问 SIGN_UP_URL 时,应用程序正在尝试使用此过滤器对用户进行身份验证:@Overrideprotected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException { String header = req.getHeader(SecurityConstants.HEADER_STRING); if (header == null || !header.startsWith(SecurityConstants.TOKEN_PREFIX)) { chain.doFilter(req, res); res.sendError(HttpServletResponse.SC_UNAUTHORIZED,"Access Denied"); return; } UsernamePasswordAuthenticationToken authentication = getAuthentication(req); SecurityContextHolder.getContext().setAuthentication(authentication); chain.doFilter(req, res);}检查到那时为空的标头(因为该 URL 理论上不需要身份验证或任何令牌)这应该不会发生,有人可以帮我吗?当我在没有身份验证的情况下为所有用户打开安全性时,该方法成功执行
添加回答
举报
0/150
提交
取消