Example usage for org.springframework.security.core.userdetails UserDetails getPassword

List of usage examples for org.springframework.security.core.userdetails UserDetails getPassword

Introduction

In this page you can find the example usage for org.springframework.security.core.userdetails UserDetails getPassword.

Prototype

String getPassword();

Source Link

Document

Returns the password used to authenticate the user.

Usage

From source file:com.minlia.cloud.framework.common.security.SpringSecurityUtil.java

/**
 * Calculates an authorization key for user.
 *
 * @param userDetails//from   www  .  j av a2 s  . co  m
 *            the user details.
 * @return the calculated authorization key.
 */
public static String encodeAuthorizationKey(final UserDetails userDetails) {
    return encodeAuthorizationKey(userDetails.getUsername(), userDetails.getPassword());
}

From source file:com.lll.util.SpringSecurityUtils.java

/**
 * UserDetails?Security Context.//from ww  w  .j a v a  2s.co  m
 * 
 * @param userDetails ??.
 * @param request ?IP??.
 */
public static void saveUserDetailsToContext(UserDetails userDetails, HttpServletRequest request) {
    PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(userDetails,
            userDetails.getPassword(), userDetails.getAuthorities());

    authentication.setDetails(new WebAuthenticationDetails(request));

    SecurityContextHolder.getContext().setAuthentication(authentication);
}

From source file:com.rosy.bill.security.SpringSecurityUtils.java

/**
 * UserDetails?Security Context./*from w ww .j  ava 2 s  . c  om*/
 * 
 * @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);
}

From source file:com.seyren.core.security.Token.java

public static String computeSignature(UserDetails userDetails, long expires) {
    StringBuilder signatureBuilder = new StringBuilder();
    signatureBuilder.append(userDetails.getUsername());
    signatureBuilder.append(":");
    signatureBuilder.append(expires);//from ww w.  j  av a 2 s .c o  m
    signatureBuilder.append(":");
    signatureBuilder.append(userDetails.getPassword());
    signatureBuilder.append(":");
    signatureBuilder.append(Token.MAGIC_KEY);

    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("No MD5 algorithm available!");
    }

    return new String(Hex.encode(digest.digest(signatureBuilder.toString().getBytes())));
}

From source file:org.openwms.client.security.TokenUtils.java

/**
 * Concatenate credentials with <code>expires</code>, add a salt and hash
 * this String./*from   w w w .j  a  va  2s .  c om*/
 * 
 * @param userDetails
 *            Where to take the credentials from
 * @param expires
 *            Expiration lease
 * @return The hashed String
 */
public static String computeSignature(UserDetails userDetails, long expires) {
    StringBuilder signatureBuilder = new StringBuilder();
    signatureBuilder.append(userDetails.getUsername());
    signatureBuilder.append(":");
    signatureBuilder.append(expires);
    signatureBuilder.append(":");
    signatureBuilder.append(userDetails.getPassword());
    signatureBuilder.append(":");
    signatureBuilder.append(TokenUtils.MAGIC_KEY);
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("No MD5 algorithm found on platform!");
    }
    return new String(Sha512DigestUtils.shaHex(digest.digest(signatureBuilder.toString().getBytes())));
}

From source file:grails.plugin.springsecurity.SpringSecurityUtils.java

/**
 * Rebuild an Authentication for the given username and register it in the security context.
 * Typically used after updating a user's authorities or other auth-cached info.
 * <p/>//from  ww w.j  a  v  a 2 s.  c  o m
 * Also removes the user from the user cache to force a refresh at next login.
 *
 * @param username the user's login name
 * @param password optional
 */
public static void reauthenticate(final String username, final String password) {
    UserDetailsService userDetailsService = getBean("userDetailsService");
    UserCache userCache = getBean("userCache");

    UserDetails userDetails = userDetailsService.loadUserByUsername(username);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(userDetails,
            password == null ? userDetails.getPassword() : password, userDetails.getAuthorities()));
    userCache.removeUserFromCache(username);
}

From source file:de.knightsoftnet.validationexample.server.converter.impl.UserDetailsConverterImpl.java

@Override
public User convert(final UserDetails psource) {
    return new UserData(psource.getUsername(), psource.getPassword());
}

From source file:org.businessmanager.dao.security.UserDetailsDaoImpl.java

@Override
public UserDetails loadUserByUsername(String username) {
    UserDetails userDetails = super.loadUserByUsername(username);
    String password = userDetails.getPassword();
    boolean enabled = userDetails.isEnabled();
    boolean accountNonExpired = userDetails.isAccountNonExpired();
    boolean credentialsNonExpired = userDetails.isCredentialsNonExpired();
    boolean accountNonLocked = userDetails.isAccountNonLocked();
    Collection<GrantedAuthority> authorities = userDetails.getAuthorities();

    UserDetailsImpl userDetailsImpl = new UserDetailsImpl(userDetails.getUsername(), password, enabled,
            accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
    User user = getUserByName(username);
    List<String> grantedGroups = retrieveGroupsForUser(user);
    userDetailsImpl.setGrantedGroups(grantedGroups);
    userDetailsImpl.setSalt(user.getSalt());

    return userDetailsImpl;
}

From source file:at.ac.univie.isc.asio.security.RoleUserServiceTest.java

@Theory
public void should_set_password_to__NA(final Role role) {
    final TestingAuthenticationToken token = new TestingAuthenticationToken(role.name(), "N/A");
    final UserDetails user = subject.loadUserDetails(token);
    assertThat(user.getPassword(), equalTo("N/A"));
}

From source file:org.opentides.bean.user.SessionUser.java

public SessionUser(UserDetails user) {
    super(user.getUsername(), user.getPassword(), user.isEnabled(), user.isAccountNonExpired(),
            user.isCredentialsNonExpired(), user.isAccountNonLocked(), user.getAuthorities());
}