title: Why permitAll() returns 403 spring security?
body: <p>I have created a method for persisting user details in the database and i also have a controller which is exposed at the endpoint /register. I wanted to make the /register endpoint available to all. I have used spring security and gave permit all for the /register end point.</p>
  <pre><code>
  @Configuration
  @EnableWebSecurity
  public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      private final UserDetailsServiceImpl userDetailsService;
  
      @Autowired
      public WebSecurityConfiguration(UserDetailsServiceImpl userDetailsService) {
          this.userDetailsService = userDetailsService;
      }
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests(
                  request -&gt; request.antMatchers(HttpMethod.POST,&quot;/register&quot;).permitAll()
                  .anyRequest().authenticated()
              );
      }
  
      @Bean
      public PasswordEncoder passwordEncoder() {
         return new BCryptPasswordEncoder();
      }
  }
  
  </code></pre>
  <p>Can someone please explain or help me out why permitAll is not working in my case. As per the code i have written the /register end point should return the user details but it returns 403. The /register endpoint is a rest endpoint which takes the user details as input and return the user details as output once the detal is persisted to the database.</p>
  <pre><code>@Slf4j
  @RestController
  public class RegistrationController {
  
      private final UserDetailsServiceImpl userDetailsService;
  
      @Autowired
      public RegistrationController(UserDetailsServiceImpl userDetailsService) {
          this.userDetailsService = userDetailsService;
      }
  
      @PostMapping(value = &quot;/register&quot;)
      public ResponseEntity&lt;Users&gt; registerNewUser(@Valid @RequestBody Users users) throws EmailAlreadyExistsException {
          Users usersDetails = userDetailsService.processRegistration(users);
          log.info(&quot;{}, Information: Successfully persisted new user&quot;,this.getClass().getSimpleName());
          return new ResponseEntity&lt;&gt;(usersDetails,HttpStatus.OK);
      }
  }
  
  </code></pre>