Example usage for org.springframework.security.authentication AbstractAuthenticationToken setDetails

List of usage examples for org.springframework.security.authentication AbstractAuthenticationToken setDetails

Introduction

In this page you can find the example usage for org.springframework.security.authentication AbstractAuthenticationToken setDetails.

Prototype

public void setDetails(Object details) 

Source Link

Usage

From source file:it.scoppelletti.programmerpower.web.security.SsoAuthenticationService.java

/**
 * Autenticazione SSO./*from  www  .  ja  v  a 2 s  .c o  m*/
 * 
 * @param  req  Richiesta.
 * @param  resp Risposta.
 * @return      Token autenticato. Se il SSO non avviene, restituisce
 *              {@code null}.  
 */
private Authentication singleSignOn(HttpServletRequest req, HttpServletResponse resp) {
    String tgt, ticket;
    HttpSession session;
    Authentication result;
    AbstractAuthenticationToken authRequest;

    tgt = getTicketGrantingTicket(req, resp);
    if (Strings.isNullOrEmpty(tgt)) {
        return null;
    }

    try {
        ticket = myCasClient.newServiceTicket(tgt);
    } catch (IOException ex) {
        myCasClient.removeTicketGrantingTicket(req, resp);
        throw new AuthenticationServiceException("Single Sing-On failed.", ex);
    }

    session = req.getSession(true);
    myLogger.debug("New ticket {} for session {}.", ticket, session.getId());

    authRequest = new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATEFUL_IDENTIFIER,
            ticket);
    authRequest.setDetails(myAuthDetailsSource.buildDetails(req));

    result = myAuthManager.authenticate(authRequest);
    if (result == null) {
        return null;
    }

    myCasClient.addAuthenticatedSession(ticket, session);

    return result;
}