Example usage for org.springframework.security.cas.web CasAuthenticationFilter CAS_STATELESS_IDENTIFIER

List of usage examples for org.springframework.security.cas.web CasAuthenticationFilter CAS_STATELESS_IDENTIFIER

Introduction

In this page you can find the example usage for org.springframework.security.cas.web CasAuthenticationFilter CAS_STATELESS_IDENTIFIER.

Prototype

String CAS_STATELESS_IDENTIFIER

To view the source code for org.springframework.security.cas.web CasAuthenticationFilter CAS_STATELESS_IDENTIFIER.

Click Source Link

Document

Used to identify a CAS request for a stateless user agent, such as a remoting protocol client (e.g.

Usage

From source file:org.fao.geonet.kernel.security.ecas.ECasAuthenticationProvider.java

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (!supports(authentication.getClass())) {
        return null;
    }/*www.  j  a  v  a  2s  .c  o m*/

    if (authentication instanceof UsernamePasswordAuthenticationToken
            && (!CasAuthenticationFilter.CAS_STATEFUL_IDENTIFIER
                    .equals(authentication.getPrincipal().toString())
                    && !CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER
                            .equals(authentication.getPrincipal().toString()))) {
        // UsernamePasswordAuthenticationToken not CAS related
        return null;
    }

    // If an existing CasAuthenticationToken, just check we created it
    if (authentication instanceof CasAuthenticationToken) {
        if (this.key.hashCode() == ((CasAuthenticationToken) authentication).getKeyHash()) {
            return authentication;
        } else {
            throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.incorrectKey",
                    "The presented CasAuthenticationToken does not contain the expected key"));
        }
    }

    // Ensure credentials are presented
    if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) {
        throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.noServiceTicket",
                "Failed to provide a CAS service ticket to validate"));
    }

    boolean stateless = false;

    if (authentication instanceof UsernamePasswordAuthenticationToken
            && CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER.equals(authentication.getPrincipal())) {
        stateless = true;
    }

    CasAuthenticationToken result = null;

    if (stateless) {
        // Try to obtain from cache
        result = statelessTicketCache.getByTicketId(authentication.getCredentials().toString());
    }

    if (result == null) {
        result = this.authenticateNow(authentication);
        result.setDetails(authentication.getDetails());
    }

    if (stateless) {
        // Add to cache
        statelessTicketCache.putTicketInCache(result);
    }

    return result;
}