JavaSpring安全性:包含AuthenticationManager的方法。authenticate()引发异常
我有一个方法在里面使用了authenticate()
方法,我发现令人困惑的是AuthenticationManager.authenticate()
在身份验证失败时会抛出AuthenticationException,但是authenticateUser
方法不会抛出任何异常,也不会触发编译错误
@PostMapping("/signin")
public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginForm loginRequest){
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword()));
SecurityContextHolder.getContext().setAuthentication(authentication);
}
共 (0) 个答案