No try catch tá sempre indo pro catch.. rsrs Alguém pode ajudar?
No caso após a linha do authManager.authenticate() ele já dá erro, mas não sei pq...
@RestController
@RequestMapping("/auth")
public class AuthenticationController {
@Autowired
private AuthenticationManager authManager;
@Autowired
private TokenService tokenService;
@PostMapping
public ResponseEntity<?> authenticate(@RequestBody @Valid LoginForm form) {
UsernamePasswordAuthenticationToken loginData = form.convertToUsernamePasswordAuthToken();
try {
Authentication authentication = authManager.authenticate(loginData);
String token = tokenService.generateToken(authentication);
System.out.println(token);
return ResponseEntity.ok().build();
} catch (AuthenticationException e) {
System.out.println("ERRO 400");
return ResponseEntity.badRequest().build();
}
}
O fato de eu não estar usando o email mas sim o CPF que chamo de idNumber, pode gerar esse erro?
public class LoginForm {
private String idNumber;
private String password;
public String getIdNumber() {
return idNumber;
}
public String getPassword() {
return password;
}
public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
}
public void setPassword(String password) {
this.password = password;
}
public UsernamePasswordAuthenticationToken convertToUsernamePasswordAuthToken() {
return new UsernamePasswordAuthenticationToken(idNumber, password);
}
}