本文整理汇总了Java中org.springframework.security.core.userdetails.UserDetails.isCredentialsNonExpired方法的典型用法代码示例。如果您正苦于以下问题:Java UserDetails.isCredentialsNonExpired方法的具体用法?Java UserDetails.isCredentialsNonExpired怎么用?Java UserDetails.isCredentialsNonExpired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.userdetails.UserDetails
的用法示例。
在下文中一共展示了UserDetails.isCredentialsNonExpired方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
String account = token.getName();
//从数据库找到的用户
UserDetails userDetails = null;
if (account != null) {
userDetails = userDetailsService.loadUserByUsername(account);
}
//
if (userDetails == null) {
throw new UsernameNotFoundException("用户名/密码无效");
} else if (!userDetails.isEnabled()) {
throw new DisabledException("用户已被禁用");
} else if (!userDetails.isAccountNonExpired()) {
throw new AccountExpiredException("账号已过期");
} else if (!userDetails.isAccountNonLocked()) {
throw new LockedException("账号已被锁定");
} else if (!userDetails.isCredentialsNonExpired()) {
throw new LockedException("凭证已过期");
}
//数据库用户的密码
String password = userDetails.getPassword();
//与authentication里面的credentials相比较
if (!password.equals(MD5Tools.md5EncodePassword(token.getCredentials().toString(),token.getName()))) {
throw new BadCredentialsException("Invalid username/password");
}
//授权
return new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities());
}