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

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

Introduction

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

Prototype

public Object getDetails() 

Source Link

Usage

From source file:jp.pigumer.security.ExampleAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    PreAuthenticatedAuthenticationToken auth = (PreAuthenticatedAuthenticationToken) authentication;
    String username = (String) auth.getPrincipal();

    LOG.debug("authenticate: " + Objects.toString(auth, ""));

    User user = userDetailsService.loadUser(username);

    ExampleAuthentication result = new ExampleAuthentication(user, user.getAuthorities());
    result.setDetails(auth.getDetails());

    LOG.debug("authenticate: " + Objects.toString(result, ""));

    return result;
}

From source file:nl.surfnet.coin.api.AbstractApiController.java

protected ClientMetaData getClientMetaData() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    ClientMetaData metaData = null;//w ww  .  j ava2s  .  co m
    // oauth2
    if (authentication instanceof OAuth2Authentication) {
        OAuth2Authentication oauth2 = (OAuth2Authentication) authentication;
        String clientId = oauth2.getAuthorizationRequest().getClientId();
        ClientDetails clientDetails = janusClientDetailsService.loadClientByClientId(clientId);
        metaData = ((OpenConextClientDetails) clientDetails).getClientMetaData();
        registerApiVersion("oauth2");
    }
    // oauth1 3-legged
    else if (authentication instanceof PreAuthenticatedAuthenticationToken) {
        PreAuthenticatedAuthenticationToken preAuth = (PreAuthenticatedAuthenticationToken) authentication;
        Object principal = preAuth.getPrincipal();
        if (principal instanceof ClientMetaDataUser) {
            ClientMetaDataUser user = (ClientMetaDataUser) principal;
            metaData = user.getClientMetaData();
            if (metaData == null) {
                Object details = preAuth.getDetails();
                if (details instanceof OAuthAuthenticationDetails) {
                    OAuthAuthenticationDetails authDetails = (OAuthAuthenticationDetails) details;
                    ConsumerDetails consumerDetails = authDetails.getConsumerDetails();
                    if (consumerDetails instanceof OpenConextConsumerDetails) {
                        OpenConextConsumerDetails base = (OpenConextConsumerDetails) consumerDetails;
                        metaData = base.getClientMetaData();
                    }
                }
            }
            registerApiVersion("oauth1-3legged");
        }
    } // oauth1 2-legged
    else if (authentication instanceof ConsumerAuthentication) {
        ConsumerAuthentication conAuth = (ConsumerAuthentication) authentication;
        ConsumerDetails consumerDetails = conAuth.getConsumerDetails();
        if (consumerDetails instanceof OpenConextConsumerDetails) {
            OpenConextConsumerDetails details = (OpenConextConsumerDetails) consumerDetails;
            metaData = details.getClientMetaData();
            registerApiVersion("oauth1-2legged");
        }
    } else if (authentication instanceof SAMLAuthenticationToken) {
        SAMLAuthenticationToken samlToken = (SAMLAuthenticationToken) authentication;
        metaData = samlToken.getClientMetaData();
        registerApiVersion("oauth2");
    } else {
        throw new IllegalArgumentException("Authentication is of unknown class ('"
                + (authentication != null ? authentication.getClass() : "null") + "')");
    }
    Assert.notNull(metaData, "ClientMetaData may not be null for checking ACL's. Authentication is of class ('"
            + (authentication != null ? authentication.getClass() : "null") + "')");
    return metaData;
}

From source file:de.zib.gndms.gndms.security.HostAndUserDetailsService.java

@Override
public UserDetails loadUserDetails(
        final PreAuthenticatedAuthenticationToken preAuthenticatedAuthenticationToken)
        throws UsernameNotFoundException {

    String dn = (String) preAuthenticatedAuthenticationToken.getPrincipal();

    try {/* w  w w .  j a va2  s  .  co m*/
        if (GridMapUserDetailsService.searchInGridMapfile(allowedHostsFileName, dn)) {
            if (reverseDNSTest)
                try {
                    if (!reverseDNSLookup(X509DnConverter.openSslDnExtractCn(dn),
                            preAuthenticatedAuthenticationToken.getDetails())) {
                        logger.info("Host-CN revers DNS lookup failed for: " + dn);
                        throw new BadCredentialsException("Host-CN reverse DNS lookup failed.");
                    }
                } catch (UnknownHostException e) {
                    throw new BadCredentialsException("", e);
                }
            GNDMSUserDetails userDetails = new GNDMSUserDetails();
            userDetails.setAuthorities(Collections.<GrantedAuthority>emptyList());
            userDetails.setDn(dn);
            userDetails.setIsUser(false);
            return userDetails;
        } else {
            final SecurityContext context = SecurityContextHolder.getContext();
            if (context != null && context.getAuthentication() != null) {
                final Object principal = context.getAuthentication().getPrincipal();
                if (principal instanceof GNDMSUserDetails) {
                    // now this must be the Request header authentication
                    final GNDMSUserDetails gndmsUserDetails = (GNDMSUserDetails) principal;
                    if (gndmsUserDetails.isUser())
                        // the x509 cert from the previous filter must have been a user cert
                        // check if the dn's match
                        if (!dn.equals(gndmsUserDetails.getUsername()))
                            throw new UsernameNotFoundException("Certificate vs HttpHeader: dn mismatch ('" + dn
                                    + "' vs. '" + gndmsUserDetails.getUsername() + "'.");
                }
            }
            return userDetailsService.loadUserByUsername(dn);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}