SO I am building a Spring Boot application using Spring Security with JWT authentication. I’ve implemented a JwtAuthenticationFilter and configured it in my SecurityConfiguration, but I keep getting 403 Forbidden responses when accessing protected endpoints with a valid JWT.
I am sending the /register user with no header. But when Accessing the register endpoint, I get 403 unauthorized error. I have authorized HTTP endpoints, disabled crsf but the issue persists without any error messages. How to fix this error or find it's cause?
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {
private final JwtAuthenticationFilter jwtAuthenticationFilter;
private final AuthenticationProvider authenticationProvider;
private final CustomerAccessDeniedHandler customerAccessDeniedHandler;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http, DefaultAuthenticationEventPublisher authenticationEventPublisher, JwtAuthenticationFilter jwtAuthenticationFilter) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/v1/auth/**").permitAll()
.anyRequest().authenticated())
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744230740a4564235.html
评论列表(0条)