本文整理匯總了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());
}