Search in sources :

Example 21 with HandlerResult

use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.

the class PKIHandlerTest method testGetNormalizedTokenFailureNoCerts.

/**
     * This test ensures the proper functionality of PKIHandler's method,
     * getNormalizedToken(), when given an invalid HTTPServletRequest.
     */
@Test
public void testGetNormalizedTokenFailureNoCerts() throws ServletException, CertificateException {
    PKIHandler handler = getPKIHandlerWithMockedCrl("signature.properties", false);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain chain = mock(FilterChain.class);
    when(request.getAttribute(("javax.servlet.request.X509Certificate"))).thenReturn(null);
    /**
         * Note that the getNormalizedToken() method for PKI handlers do not
         * use the resolve tag.
         */
    HandlerResult result = null;
    result = handler.getNormalizedToken(request, response, chain, true);
    assertThat(result, is(notNullValue()));
    assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
    verify(handler.crlChecker, never()).passesCrlCheck(getTestCerts());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 22 with HandlerResult

use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.

the class PKIHandlerTest method testGetNormalizedTokenSuccessNoCrlPkiNoResolveNoResponse.

/**
     * This test ensures the proper functionality of PKIHandler's method,
     * getNormalizedToken(), when given a valid HTTPServletRequest and resolve is set to false.
     */
@Test
public void testGetNormalizedTokenSuccessNoCrlPkiNoResolveNoResponse() throws java.security.cert.CertificateException, ServletException {
    PKIHandler handler = getPKIHandlerWithMockedCrl("signature.properties", true);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getAttribute(("javax.servlet.request.X509Certificate"))).thenReturn(getTestCerts());
    /**
         * Note that the getNormalizedToken() method for PKI handlers do not
         * use the resolve tag.
         */
    HandlerResult result = null;
    result = handler.getNormalizedToken(request, null, null, false);
    assertThat(result, is(notNullValue()));
    assertThat(result.getStatus(), equalTo(HandlerResult.Status.COMPLETED));
    verify(handler.crlChecker).passesCrlCheck(getTestCerts());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 23 with HandlerResult

use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.

the class PKIHandlerTest method testNoActionWhenHttpResponseIsNull.

/**
     * Tests that the certificate gets through when CRL checking is enabled but
     * the cert is not listed in the CRL
     *
     * @throws java.security.cert.CertificateException
     * @throws ServletException
     */
@Test
public void testNoActionWhenHttpResponseIsNull() throws java.security.cert.CertificateException, ServletException {
    PKIHandler handler = getPKIHandlerWithMockedCrl("signature.properties", true);
    HttpServletResponse httpResponse = null;
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    FilterChain chain = mock(FilterChain.class);
    HandlerResult result = handler.getNormalizedToken(httpRequest, httpResponse, chain, true);
    assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
    verify(handler.crlChecker, never()).passesCrlCheck(getTestCerts());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 24 with HandlerResult

use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.

the class SAMLAssertionHandler method handleError.

/**
     * If an error occured during the processing of the request, this method will get called. Since
     * SAML handling is typically processed first, then we can assume that there was an error with
     * the presented SAML assertion - either it was invalid, or the reference didn't match a
     * cached assertion, etc. In order not to get stuck in a processing loop, we will return a 401
     * status code.
     *
     * @param servletRequest  http servlet request
     * @param servletResponse http servlet response
     * @param chain           rest of the request chain to be invoked after security handling
     * @return result containing the potential credentials and status
     * @throws ServletException
     */
@Override
public HandlerResult handleError(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException {
    HandlerResult result = new HandlerResult();
    HttpServletRequest httpRequest = servletRequest instanceof HttpServletRequest ? (HttpServletRequest) servletRequest : null;
    HttpServletResponse httpResponse = servletResponse instanceof HttpServletResponse ? (HttpServletResponse) servletResponse : null;
    if (httpRequest == null || httpResponse == null) {
        return result;
    }
    LOGGER.debug("In error handler for saml - setting status code to 401 and returning status REDIRECTED.");
    // we tried to process an invalid or missing SAML assertion
    try {
        httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        httpResponse.flushBuffer();
    } catch (IOException e) {
        LOGGER.debug("Failed to send auth response", e);
    }
    result.setStatus(HandlerResult.Status.REDIRECTED);
    return result;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) IOException(java.io.IOException)

Example 25 with HandlerResult

use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.

the class CasHandler method handleError.

@Override
public HandlerResult handleError(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException {
    HandlerResult handlerResult;
    LOGGER.debug("handleError was called on the CasHandler, cannot do anything.");
    handlerResult = new HandlerResult(HandlerResult.Status.NO_ACTION, null);
    return handlerResult;
}
Also used : HandlerResult(org.codice.ddf.security.handler.api.HandlerResult)

Aggregations

HandlerResult (org.codice.ddf.security.handler.api.HandlerResult)51 HttpServletRequest (javax.servlet.http.HttpServletRequest)33 HttpServletResponse (javax.servlet.http.HttpServletResponse)33 Test (org.junit.Test)33 FilterChain (javax.servlet.FilterChain)24 ServletException (javax.servlet.ServletException)10 IOException (java.io.IOException)8 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)8 ProxyFilterChain (org.codice.ddf.security.handler.cas.filter.ProxyFilterChain)6 Element (org.w3c.dom.Element)6 BaseAuthenticationToken (org.codice.ddf.security.handler.api.BaseAuthenticationToken)5 SAMLAuthenticationToken (org.codice.ddf.security.handler.api.SAMLAuthenticationToken)5 ServletRequest (javax.servlet.ServletRequest)4 ServletResponse (javax.servlet.ServletResponse)4 HttpSession (javax.servlet.http.HttpSession)4 AuthenticationHandler (org.codice.ddf.security.handler.api.AuthenticationHandler)4 Subject (ddf.security.Subject)3 SecurityTokenHolder (ddf.security.common.SecurityTokenHolder)3 SecurityManager (ddf.security.service.SecurityManager)3 FilterConfig (javax.servlet.FilterConfig)3