Search in sources :

Example 21 with Assertion

use of org.jasig.cas.client.validation.Assertion in project ddf by codice.

the class CasHandlerTest method createServletRequest.

private HttpServletRequest createServletRequest(boolean shouldAddCas) {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    HttpSession session = mock(HttpSession.class);
    when(session.getId()).thenReturn(SESSION_ID);
    when(servletRequest.getSession()).thenReturn(session);
    when(servletRequest.getSession(any(Boolean.class))).thenReturn(session);
    if (shouldAddCas) {
        // Mock CAS items
        Assertion assertion = mock(Assertion.class);
        when(session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION)).thenReturn(assertion);
        AttributePrincipal principal = mock(AttributePrincipal.class);
        when(principal.getProxyTicketFor(STS_ADDRESS)).thenReturn(MOCK_TICKET);
        when(principal.getProxyTicketFor(not(eq(STS_ADDRESS)))).thenThrow(new RuntimeException("Tried to create ticket for incorrect service."));
        when(assertion.getPrincipal()).thenReturn(principal);
    }
    return servletRequest;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) Assertion(org.jasig.cas.client.validation.Assertion) AttributePrincipal(org.jasig.cas.client.authentication.AttributePrincipal)

Example 22 with Assertion

use of org.jasig.cas.client.validation.Assertion in project ddf by codice.

the class CasHandler method getNormalizedToken.

@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, FilterChain chain, boolean resolve) throws ServletException {
    // Default to NO_ACTION and set the source as this handler
    HandlerResult handlerResult = new HandlerResult(HandlerResult.Status.NO_ACTION, null);
    handlerResult.setSource(realm + "-" + SOURCE);
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String path = httpRequest.getServletPath();
    LOGGER.debug("Doing CAS authentication and authorization for path {}", path);
    // if the request contains the principal, return it
    Assertion assertion = getAssertion(httpRequest);
    try {
        if (resolve && assertion == null) {
            proxyFilter.doFilter(request, response, new ProxyFilterChain(null));
        }
    } catch (IOException e) {
        throw new ServletException(e);
    }
    if (assertion != null) {
        LOGGER.debug("Found previous CAS attribute, using that same session.");
        CASAuthenticationToken token = getAuthenticationToken(assertion);
        if (token != null) {
            handlerResult.setToken(token);
            handlerResult.setStatus(HandlerResult.Status.COMPLETED);
            //update cache with new information
            LOGGER.debug("Adding new CAS assertion for session {}", httpRequest.getSession(false).getId());
            httpRequest.getSession(false).setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, assertion);
            LOGGER.debug("Successfully set authentication token, returning result with token.");
        } else {
            LOGGER.debug("Could not create authentication token, returning NO_ACTION result.");
        }
    } else {
        if (resolve) {
            LOGGER.debug("Calling cas authentication and validation filters to perform redirects.");
            handlerResult.setStatus(HandlerResult.Status.REDIRECTED);
        } else {
            LOGGER.debug("No cas authentication information found and resolve is not enabled, returning NO_ACTION.");
        }
    }
    return handlerResult;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Assertion(org.jasig.cas.client.validation.Assertion) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) IOException(java.io.IOException) ProxyFilterChain(org.codice.ddf.security.handler.cas.filter.ProxyFilterChain)

Aggregations

Assertion (org.jasig.cas.client.validation.Assertion)22 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)12 Test (org.junit.Test)10 AttributePrincipal (org.jasig.cas.client.authentication.AttributePrincipal)3 Cas30ServiceTicketValidator (org.jasig.cas.client.validation.Cas30ServiceTicketValidator)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 TicketValidationException (org.jasig.cas.client.validation.TicketValidationException)2 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)2 CasAuthenticationToken (org.springframework.security.cas.authentication.CasAuthenticationToken)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 User (org.springframework.security.core.userdetails.User)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 IOException (java.io.IOException)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 ServletException (javax.servlet.ServletException)1 HttpSession (javax.servlet.http.HttpSession)1