У меня есть собственный AuthenticationFilter, который реализует интерфейс AbstractAuthenticationProcessingFilter.Я установил AntPathRequestMatcher, но AntPathRequestMatcher не работает, когда я попытался подключиться, чтобы войти в систему возвращает 403
Мой класс фильтра
public class JWTAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
public JWTAuthenticationFilter() {
super(new AntPathRequestMatcher("/login", "POST"));
}
@Override
public Authentication attemptAuthentication (HttpServletRequest httpServletRequest, HttpServletResponse
httpServletResponse) throws AuthenticationException, IOException, ServletException {
String header = httpServletRequest.getHeader("Authorization");
if (header == null || !header.startsWith("Bearer ")) {
throw new RuntimeException("Token missing or invalid");
}
String authenticationToken = header.substring(7);
JWTAuthToken token = new JWTAuthToken(authenticationToken);
return getAuthenticationManager().authenticate(token);
}
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult)
throws IOException, ServletException {
super.successfulAuthentication(request, response, chain, authResult);
chain.doFilter(request, response);
}
}
Настроить метод
http.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/sign-up").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest().authenticated()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(authTokenFilter(), UsernamePasswordAuthenticationFilter.class);
http.headers().cacheControl();
Как я могуисправить это