我想基于tutorial通过Spring Boot实施JWT身份验证。
端点:
@PostMapping("/authorize")
public String login(@Valid @RequestBody AuthenticationDTO resetDTO) {
return userRestService.authorize(resetDTO.getName(), resetDTO.getPassword());
}
public String authorize(String username, String password) {
try {
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
Optional<Users> user = userService.findByLogin(username);
if(!user.isPresent()){
throw new EngineException(ErrorDetail.NOT_FOUND);
}
return jwtTokenProvider.createToken(username, Collections.singletonList(user.get().getRole()));
} catch (AuthenticationException e) {
throw new EngineException(ErrorDetail.NOT_FOUND);
}
}
完整代码:Github
当我发出POST请求以验证用户身份时:
{
"name": "admin",
"password": "qwerty"
}
我得到这个full log
我看不到从数据库中获取凭证的任何SQL查询。似乎authenticationManager.authenticate
没有进行身份验证。
您知道什么可能导致此问题以及如何解决此问题吗?