当前位置: 首页>>代码示例>>Java>>正文


Java UserDetails.getPassword方法代码示例

本文整理汇总了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;
  }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:25,代码来源:CustomLogoutHandler.java

示例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());
}
 
开发者ID:ronger-x,项目名称:player,代码行数:31,代码来源:AuthenticationProviderCustom.java

示例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;
  }
}
 
开发者ID:oasp,项目名称:oasp-tutorial-sources,代码行数:20,代码来源:BaseUserDetailsService.java

示例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());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:8,代码来源:SecurityRequestPostProcessors.java

示例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);
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:21,代码来源:SpringSecurityUtils.java

示例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.");
    }
}
 
开发者ID:zeldan,项目名称:spring-boot-oauth2-password-flow,代码行数:11,代码来源:AccountAuthenticationProvider.java

示例7: User

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
public User(UserDetails userDetails){
    this(userDetails.getUsername(),userDetails.getPassword());
}
 
开发者ID:damingerdai,项目名称:web-qq,代码行数:4,代码来源:User.java


注:本文中的org.springframework.security.core.userdetails.UserDetails.getPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。