admin管理员组

文章数量:1399762

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();
    }
}

本文标签: Spring Security JWT Returns 403 Forbidden on EndpointsStack Overflow