Example usage for org.springframework.security.web.authentication.preauth PreAuthenticatedAuthenticationToken getCredentials

List of usage examples for org.springframework.security.web.authentication.preauth PreAuthenticatedAuthenticationToken getCredentials

Introduction

In this page you can find the example usage for org.springframework.security.web.authentication.preauth PreAuthenticatedAuthenticationToken getCredentials.

Prototype

public Object getCredentials() 

Source Link

Document

Get the credentials

Usage

From source file:com.mycompany.projetsportmanager.springsecurity.userdetailsservice.MyAuthenticationUserDetailsService.java

/**
 * Loads the user details from the token.
 *//*from   www  .java 2 s  . co  m*/
@SuppressWarnings("unchecked")
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken preAuthenticatedAuthenticationToken)
        throws UsernameNotFoundException {
    List<String> ldapProfiles = (List<String>) preAuthenticatedAuthenticationToken.getCredentials();

    // Injection des AK des profils du fichier JSON en fonction des profils "Habile" trouves
    // Boucle sur les profils Habile
    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    UserProfilesAccessKey userProfilesAccessKey = new UserProfilesAccessKey();
    for (String profil : ldapProfiles) {
        // Boucle sur tout les AccessKey du fichier JSON
        for (ProfileAccessKey pak : accessKeyConfiguration.getAccessKeyConfiguration()) {
            // Si profil Habile trouv dans AccessKeyConfiguration alors on injecte ses AK correspondant 
            if (profil.equalsIgnoreCase(pak.getProfile())) {
                userProfilesAccessKey.addProfileAccessKey(pak);
                for (AccessKey ak : pak.getAccessKeyLst()) {
                    authorities.add(new SimpleGrantedAuthority(ak.getAccessKey()));
                }
            }
        }
    }

    // BUild the user details.
    return new AuthenticatedUserDTO((String) preAuthenticatedAuthenticationToken.getPrincipal(), "none",
            authorities, userProfilesAccessKey);
}

From source file:org.apache.cxf.fediz.service.idp.STSPreAuthAuthenticationProvider.java

private Authentication handlePreAuthenticated(PreAuthenticatedAuthenticationToken preauthenticatedToken,
        IdpSTSClient sts) {//w ww .  jav a 2 s  . c  om
    X509Certificate cert = (X509Certificate) preauthenticatedToken.getCredentials();
    if (cert == null) {
        return null;
    }

    // Convert the received certificate to a DOM Element to write it out "OnBehalfOf"
    Document doc = DOMUtils.newDocument();
    X509Data certElem = new X509Data(doc);
    try {
        certElem.addCertificate(cert);
        sts.setOnBehalfOf(certElem.getElement());
    } catch (XMLSecurityException e) {
        LOG.debug("Error parsing a client certificate", e);
        return null;
    }

    try {
        // Line below may be uncommented for debugging    
        // setTimeout(sts.getClient(), 3600000L);

        SecurityToken token = sts.requestSecurityToken(this.appliesTo);

        List<GrantedAuthority> authorities = createAuthorities(token);

        STSUserDetails details = new STSUserDetails(preauthenticatedToken.getName(), "", authorities, token);

        preauthenticatedToken.setDetails(details);

        LOG.debug("[IDP_TOKEN={}] provided for user '{}'", token.getId(), preauthenticatedToken.getName());
        return preauthenticatedToken;

    } catch (Exception ex) {
        LOG.info("Failed to authenticate user '" + preauthenticatedToken.getName() + "'", ex);
        return null;
    }
}