Example usage for org.springframework.security.core AuthenticationException initCause

List of usage examples for org.springframework.security.core AuthenticationException initCause

Introduction

In this page you can find the example usage for org.springframework.security.core AuthenticationException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

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

/**
 * Valida l’autenticazione persistente.
 * // w w w .  ja v  a 2  s .  c o m
 * @param  cookieTokens Componenti del cookie per l’autenticazione
 *                      persistente.
 * @param  req          Richiesta.
 * @param  resp         Risposta.
 * @return              Utente autenticato.
 */
@Override
protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest req,
        HttpServletResponse resp) {
    boolean newTGT;
    String tgt, ticket;
    UserDetails user;
    HttpSession session;
    AuthenticationException authEx;

    if (Strings.isNullOrEmpty(myUserName)) {
        throw new PropertyNotSetException(toString(), "userName");
    }
    if (Strings.isNullOrEmpty(myPwd)) {
        throw new PropertyNotSetException(toString(), "password");
    }
    if (myCasClient == null) {
        throw new PropertyNotSetException(toString(), "casClient");
    }

    user = super.processAutoLoginCookie(cookieTokens, req, resp);

    tgt = getTicketGrantingTicket(req, resp);
    newTGT = Strings.isNullOrEmpty(tgt);

    try {
        if (newTGT) {
            tgt = myCasClient.newTicketGrantingTicket(myUserName, new SecureString(myPwd));
        }

        ticket = myCasClient.newServiceTicket(tgt);
    } catch (Exception ex) {
        authEx = new RememberMeAuthenticationException(ApplicationException.toString(ex));
        authEx.initCause(ex);
        throw authEx;
    }

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

    if (newTGT) {
        tgt = tgt.concat(SsoRememberMeServices.TICKET_SUFFIX);
        myCasClient.addTicketGrantingTicket(req, resp, tgt);
    }

    myCasClient.addAuthenticatedSession(ticket, session);

    return user;
}