Я пытаюсь протестировать метод аутентификации отдыха, но я застрял в некоторых ошибках в Почтальоне.Ошибка о заголовке HHTP, он не может прочитать сообщение из JSON, сообщение об исключении: HttpMessageNotReadableException
вот класс RestController:
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/auth")
public class AuthController {
@Autowired
AuthenticationManager authenticationManager;
@Autowired
EmployeRepository employeRepository;
@Autowired
PasswordEncoder passwordEncoder;
@Autowired
JwtTokenProvider tokenProvider;
/**
* METHODE D'AUTHENTIFICATION
*
* @param loginRequest
* @return
*/
@PostMapping("/signin")
@ApiImplicitParams(@ApiImplicitParam(name = "Authorization", value = "Bearer token", required = true, dataType = "String", paramType = "header"))
public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {
Optional<Employe> ListEmployees = employeRepository.findByMail(loginRequest.getEmail());
List<Employe> listEmpl = new ArrayList<>();
ListEmployees.ifPresent(listEmpl::add);
if (listEmpl.size() == 1) {
final Employe empl = listEmpl.stream().findFirst().get();
Boolean matches = passwordEncoder.matches(loginRequest.getPassword(),
listEmpl.stream().findFirst().get().getMp());
if (matches.equals(true)) {
if ( empl.getMail()!= null) {
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(
loginRequest.getEmail(), loginRequest.getPassword()));
SecurityContextHolder.getContext().setAuthentication(authentication);
String jwt = tokenProvider.generateToken(authentication);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("Authorization", new JwtAuthenticationResponse(jwt).getAccessToken());
return ResponseEntity.ok(new JwtAuthenticationResponse(jwt));
} else if (empl.getMp()!= null) {
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(
empl.getMail(), loginRequest.getPassword()));
SecurityContextHolder.getContext().setAuthentication(authentication);
String jwt = tokenProvider.generateToken(authentication);
return ResponseEntity.ok(new JwtAuthenticationResponse(jwt));
}
}
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}}
POSTMANURI:
http://localhost:8082/api/auth/signin
сообщение, которое я получаю:
{
"timestamp": 1548681879270,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Required request body is missing: public org.springframework.http.ResponseEntity<?> com.Cynapsys.Pointage.Controller.AuthController.authenticateUser(com.Cynapsys.Pointage.Model.LoginRequest)",
"path": "/api/auth/signin"
}