Spring Security JWT Returns 403 Forbidden on Endpoints - Stack Overflow

SO I am building a Spring Boot application using Spring Security with JWT authentication. I’ve implemen

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

相关推荐

  • Spring Security JWT Returns 403 Forbidden on Endpoints - Stack Overflow

    SO I am building a Spring Boot application using Spring Security with JWT authentication. I’ve implemen

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信