Olá, estou com o mesmo problema do colega Marcos Rossoni. Mesmo usando .csrf().disable() não resolveu. Não libera o acesso para métodos POST.
/*
* Configurações de autorização
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(HttpMethod.POST, "/auth").permitAll()
.anyRequest().authenticated()
.and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
url
http://localhost:8081/auth
ResponseBody
{
"timestamp": "2022-08-19T13:39:45.592+0000",
"status": 403,
"error": "Forbidden",
"message": "Access Denied",
"path": "/auth"
}
Controller
package br.com.security.controller;
import javax.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import br.com.security.form.LoginForm;
@RestController
@RequestMapping("/auth")
public class AuthenticationController {
@PostMapping
public ResponseEntity<?> authentication(@RequestBody @Valid LoginForm loginForm) {
return ResponseEntity.status(HttpStatus.OK).body(loginForm);
}
}