@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName().trim();
String password = authentication.getCredentials().toString().trim();
try {
User storedCredentials = userService.testCredentials(username, password);
// if user is authenticated return Spring authentication
if (storedCredentials != null) {
return new UsernamePasswordAuthenticationToken(username, storedCredentials.getPassword(),
Arrays.asList(new SimpleGrantedAuthority(storedCredentials.getRole().toString())));
}
} catch (IOException e) {
logger.error("Error while accessing database", e);
}
throw new BadCredentialsException("Bad credentials");
}
CustomAuthenticationProvider.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:simple-hostel-management
作者:
评论列表
文章目录