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

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

Introduction

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

Prototype

public String getName() 

Source Link

Usage

From source file:org.apigw.authserver.x509.CertifiedClientAuthenticationUserDetailsService.java

@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException {
    if (token.getName() == null) {
        throw new UsernameNotFoundException("Username null not found");
    }//from ww  w.  j a v a2s  .com

    final X509ClientPrincipal principal = (X509ClientPrincipal) token.getPrincipal();

    CertifiedClient clientDetails = clientDetailsService.loadClientByX509Cert(principal.getIssuerDN(),
            principal.getSubjectDN());

    boolean expired = hasExpired(clientDetails);
    boolean enabled = !expired;
    return new User(clientDetails.getClientId(), "N/A", enabled, !expired, true, !clientDetails.isLocked(),
            clientDetails.getAuthorities());

}

From source file:jp.pigumer.app.UserDetailsServiceImpl.java

@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
    LOG.info(Objects.toString(token, "null"));
    return new User(token.getName(), "<abc123>", token.getAuthorities());
}

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

private Authentication handlePreAuthenticated(PreAuthenticatedAuthenticationToken preauthenticatedToken,
        IdpSTSClient sts) {/*from   w w w.j  ava 2 s.  co m*/
    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;
    }
}

From source file:org.springframework.security.extensions.portlet.PortletProcessingInterceptor.java

/**
 * Common preHandle method for both the action and render phases of the interceptor.
 *///  w w  w .  j a  va2  s. co  m
private boolean preHandle(PortletRequest request, PortletResponse response, Object handler) throws Exception {

    // get the SecurityContext
    SecurityContext ctx = SecurityContextHolder.getContext();

    if (logger.isDebugEnabled())
        logger.debug("Checking secure context token: " + ctx.getAuthentication());

    // if there is no existing Authentication object, then lets create one
    if (ctx.getAuthentication() == null) {

        try {

            // build the authentication request from the PortletRequest
            PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(
                    getPrincipalFromRequest(request), getCredentialsFromRequest(request));

            // put the PortletRequest into the authentication request as the "details"
            authRequest.setDetails(authenticationDetailsSource.buildDetails(request));

            if (logger.isDebugEnabled())
                logger.debug("Beginning authentication request for user '" + authRequest.getName() + "'");

            onPreAuthentication(request, response);

            // ask the authentication manager to authenticate the request
            // it will throw an AuthenticationException if it fails, otherwise it succeeded
            Authentication authResult = authenticationManager.authenticate(authRequest);

            // process a successful authentication
            if (logger.isDebugEnabled()) {
                logger.debug("Authentication success: " + authResult);
            }

            ctx.setAuthentication(authResult);
            onSuccessfulAuthentication(request, response, authResult);

        } catch (AuthenticationException failed) {
            // process an unsuccessful authentication
            if (logger.isDebugEnabled()) {
                logger.debug("Authentication failed - updating ContextHolder to contain null Authentication",
                        failed);
            }
            ctx.setAuthentication(null);
            request.getPortletSession().setAttribute(
                    AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY, failed,
                    PortletSession.APPLICATION_SCOPE);
            onUnsuccessfulAuthentication(request, response, failed);
        }
    }

    return true;
}