本文整理汇总了Java中org.springframework.security.core.userdetails.UserDetails.getPassword方法的典型用法代码示例。如果您正苦于以下问题:Java UserDetails.getPassword方法的具体用法?Java UserDetails.getPassword怎么用?Java UserDetails.getPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.userdetails.UserDetails
的用法示例。
在下文中一共展示了UserDetails.getPassword方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: targetUrl
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
protected String targetUrl(Authentication authentication) {
UserDetails p = (UserDetails )authentication.getPrincipal();
String username = p.getUsername();
String password = p.getPassword();
String url = "";
Collection<? extends GrantedAuthority> authorities = p.getAuthorities();
List<String> roles = new ArrayList<String>();
for (GrantedAuthority a : authorities) {
roles.add(a.getAuthority());
}
System.out.println("logout handler" + roles);
if (isUser(roles)) {
url = "/after_logout.html?message="+"Thank your, "+ username +" with password " + password +" and role(s): " + roles;
} else if (isAdmin(roles)){
url = "/after_logout.html?message="+"Thank your, "+ username +" with password " + password +" and role(s): " + roles;
} else if (isHrAdmin(roles)){
url = "/after_logout.html?message="+"Thank your, "+ username +" with password " + password +" and role(s): " + roles;
} else{
url = "/after_logout.html?message="+"Thank you, friend!";
}
return url;
}
示例2: 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());
}
示例3: loadUserByUsername
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserProfile principal = retrievePrincipal(username);
Set<GrantedAuthority> authorities = getAuthorities(principal);
UserDetails user;
try {
// amBuilder uses the InMemoryUserDetailsManager, because it is configured in BaseWebSecurityConfig
user = getAmBuilder().getDefaultUserDetailsService().loadUserByUsername(username);
UserData userData = new UserData(user.getUsername(), user.getPassword(), authorities);
userData.setUserProfile(principal);
return userData;
} catch (Exception e) {
e.printStackTrace();
UsernameNotFoundException exception = new UsernameNotFoundException("Authentication failed.", e);
LOG.warn("Failed to get user {}.", username, exception);
throw exception;
}
}
示例4: authentication
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
private UsernamePasswordAuthenticationToken authentication(ServletContext servletContext) {
ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
UserDetailsService userDetailsService = userDetailsService(context);
UserDetails userDetails = userDetailsService.loadUserByUsername(this.username);
return new UsernamePasswordAuthenticationToken(
userDetails, userDetails.getPassword(), userDetails.getAuthorities());
}
示例5: saveUserDetailsToContext
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
/**
* 将UserDetails保存到Security Context.
*
* @param userDetails
* 已初始化好的用户信息.
* @param request
* 用于获取用户IP地址信息,可为Null.
*/
public static void saveUserDetailsToContext(UserDetails userDetails,
HttpServletRequest request) {
PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(
userDetails, userDetails.getPassword(),
userDetails.getAuthorities());
if (request != null) {
authentication.setDetails(new WebAuthenticationDetails(request));
}
SecurityContextHolder.getContext().setAuthentication(authentication);
}
示例6: additionalAuthenticationChecks
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
@Override
protected void additionalAuthenticationChecks(final UserDetails userDetails, final UsernamePasswordAuthenticationToken token)
throws AuthenticationException {
if (token.getCredentials() == null || userDetails.getPassword() == null) {
throw new BadCredentialsException("Credentials may not be null.");
}
if (!passwordEncoder.matches((String) token.getCredentials(), userDetails.getPassword())) {
throw new BadCredentialsException("Invalid credentials.");
}
}
示例7: User
import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
public User(UserDetails userDetails){
this(userDetails.getUsername(),userDetails.getPassword());
}