Spring Boot HttpSecurity always 403 forbidden

Eray Tuncer :

I always get http status 403. I have this security configuration:

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity
        .cors().and().csrf().disable()
        .authorizeRequests()
        .antMatchers("/api/users/login/").permitAll()
        .anyRequest().authenticated();
}


@Bean
CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(Arrays.asList("*"));
    configuration.setAllowedMethods(Arrays.asList("*"));
    configuration.setAllowedHeaders(Arrays.asList("*"));
    configuration.setAllowCredentials(true);
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
}

I cannot post to /api/users/login

2019-10-15 12:25:49.567[0;39m [32mDEBUG[0;39m [35m7423[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m "ERROR" dispatch for POST "/error", parameters={} [2m2019-10-15 12:25:49.576[0;39m [32mDEBUG[0;39m [35m7423[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) [2m2019-10-15 12:25:49.605[0;39m [32mDEBUG[0;39m [35m7423[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.w.s.m.m.a.HttpEntityMethodProcessor [0;39m [2m:[0;39m Using 'application/json', given [/] and supported [application/json, application/+json, application/json, application/+json] [2m2019-10-15 12:25:49.608[0;39m [32mDEBUG[0;39m [35m7423[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.w.s.m.m.a.HttpEntityMethodProcessor [0;39m [2m:[0;39m Writing [{timestamp=Tue Oct 15 12:25:49 CEST 2019, status=403, error=Forbidden, message=Access Denied, path=/ (truncated)...] [2m2019-10-15 12:25:49.661[0;39m [32mDEBUG[0;39m [35m7423[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Exiting from "ERROR" dispatch, status 403

Patel Romil :

Try .antMatchers(HttpMethod.POST,"/api/users/login").permitAll(), also note that you have .antMatchers("/api/users/login/") and you are makin an request to /api/users/login note extra / in your antMatchers.

You can also use configure(WebSecurity web) which will bypass the Spring Security filter chain as described here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring Boot: @PreAuthorize gives 403 forbidden AccessDeniedException

Websocket in Spring Boot app - Getting 403 Forbidden

403 forbidden - Spring Security

spring boot return 403 forbidden when POST request with Keyclaok

HTTP 403 forbidden error in spring boot security

How to resolve HTTP-403 Forbidden Spring Boot basic authentication using Postman

Spring boot - return 403 Forbidden instead of redirect to login page

Spring Boot - KeyCloak directed to 403 forbidden

Getting a Post 403 Forbidden with Spring Boot (VueJS and Axios Frontend)

Cannot configure spring boot security - always 403

always 403 Forbidden with Nginx .htpasswd

How to configure HttpSecurity for this situation (Spring Boot)

403 forbidden error when using Spring boot - security

Why does Spring Security always respond with 403 Forbidden on all form Posts?

Power BI always returnig 403 Forbidden

Spring Boot JWT : Forbidden 403 error for GET API

Office Graph TrendingAround always return 403 Forbidden

header(location:) always shows up 403 forbidden

Spring Boot HttpSecurity fluent api order?

Spring Boot HttpSecurity - @PreAuthorize - How to set AuthenticationFilter?

Error CORS Forbidden 403 Spring Boot With Spring Security when using Path Variable

403 Forbidden when introducing authorization on spring boot rest

403 Forbidden for OpenApiSwagger in Spring Boot Security

Jwt authorization always giving 403 Forbidden

Spring security config requestMatchers.hasRole() is always giving 403 forbidden status

Spring Security basic authentication throws always 403 Forbidden

Spring Boot Security login success but always return forbidden

Spring Boot Security - Every endpoint is 403 forbidden and Spring logs a BasicErrorController#error(HttpServletRequest)

Spring Boot HttpSecurity problem with exceptionHandling

TOP Ranking

HotTag

Archive