Search in sources :

Example 1 with SecurityFilterChain

use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.

the class PKIHandlerTest method testErrorHandling.

/**
 * Tests Error Handling
 */
@Test
public void testErrorHandling() throws Exception {
    PKIHandler handler = getPKIHandlerWithMockedCrl(true);
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    SecurityFilterChain filterChain = mock(SecurityFilterChain.class);
    HandlerResult result = handler.handleError(httpRequest, httpResponse, filterChain);
    assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityFilterChain(org.codice.ddf.platform.filter.SecurityFilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 2 with SecurityFilterChain

use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.

the class PKIHandlerTest method testGetNormalizedTokenSuccessNoCrlPki.

/**
 * This test ensures the proper functionality of PKIHandler's method, getNormalizedToken(), when
 * given a valid HTTPServletRequest.
 */
@Test
public void testGetNormalizedTokenSuccessNoCrlPki() throws Exception {
    PKIHandler handler = getPKIHandlerWithMockedCrl(true);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SecurityFilterChain chain = mock(SecurityFilterChain.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;
    result = handler.getNormalizedToken(request, response, chain, true);
    assertThat(result, is(notNullValue()));
    assertThat(result.getStatus(), equalTo(HandlerResult.Status.COMPLETED));
    verify(handler.crlChecker).passesCrlCheck(getTestCerts());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityFilterChain(org.codice.ddf.platform.filter.SecurityFilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 3 with SecurityFilterChain

use of org.codice.ddf.platform.filter.SecurityFilterChain 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
 */
@Test
public void testNoActionWhenHttpResponseIsNull() throws Exception {
    PKIHandler handler = getPKIHandlerWithMockedCrl(true);
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    SecurityFilterChain chain = mock(SecurityFilterChain.class);
    when(httpRequest.getAttribute(("javax.servlet.request.X509Certificate"))).thenReturn(getTestCerts());
    HandlerResult result = handler.getNormalizedToken(httpRequest, null, chain, true);
    assertThat(result.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
    verify(handler.crlChecker, never()).passesCrlCheck(getTestCerts());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityFilterChain(org.codice.ddf.platform.filter.SecurityFilterChain) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 4 with SecurityFilterChain

use of org.codice.ddf.platform.filter.SecurityFilterChain 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 Exception {
    PKIHandler handler = getPKIHandlerWithMockedCrl(false);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SecurityFilterChain chain = mock(SecurityFilterChain.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) SecurityFilterChain(org.codice.ddf.platform.filter.SecurityFilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 5 with SecurityFilterChain

use of org.codice.ddf.platform.filter.SecurityFilterChain in project ddf by codice.

the class WebSSOFilterTest method testDoFilterWhiteListed.

@Test
public void testDoFilterWhiteListed() throws IOException, AuthenticationException {
    ContextPolicy testPolicy = mock(ContextPolicy.class);
    ContextPolicyManager policyManager = mock(ContextPolicyManager.class);
    when(policyManager.getContextPolicy(anyString())).thenReturn(testPolicy);
    when(policyManager.isWhiteListed(anyString())).thenReturn(true);
    when(policyManager.getSessionAccess()).thenReturn(false);
    WebSSOFilter filter = new WebSSOFilter();
    // set handlers
    AuthenticationHandler handler1 = mock(AuthenticationHandler.class);
    HandlerResult noActionResult = mock(HandlerResult.class);
    when(noActionResult.getStatus()).thenReturn(Status.NO_ACTION);
    HandlerResult completedResult = mock(HandlerResult.class);
    when(completedResult.getStatus()).thenReturn(Status.COMPLETED);
    when(completedResult.getToken()).thenReturn(null);
    when(handler1.getNormalizedToken(any(ServletRequest.class), any(ServletResponse.class), any(SecurityFilterChain.class), eq(true))).thenReturn(completedResult);
    when(handler1.getNormalizedToken(any(ServletRequest.class), any(ServletResponse.class), any(SecurityFilterChain.class), eq(false))).thenReturn(noActionResult);
    filter.setHandlerList(Collections.singletonList(handler1));
    filter.setContextPolicyManager(policyManager);
    SecurityFilterChain filterChain = mock(SecurityFilterChain.class);
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn(MOCK_CONTEXT);
    HttpServletResponse response = mock(HttpServletResponse.class);
    filter.doFilter(request, response, filterChain);
    verify(request, times(1)).setAttribute(ContextPolicy.NO_AUTH_POLICY, true);
    verify(filterChain).doFilter(request, response);
    verify(handler1, never()).getNormalizedToken(any(HttpServletRequest.class), any(HttpServletResponse.class), any(SecurityFilterChain.class), anyBoolean());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) SecurityFilterChain(org.codice.ddf.platform.filter.SecurityFilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthenticationHandler(org.codice.ddf.security.handler.api.AuthenticationHandler) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) Test(org.junit.Test)

Aggregations

SecurityFilterChain (org.codice.ddf.platform.filter.SecurityFilterChain)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 Test (org.junit.Test)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 HandlerResult (org.codice.ddf.security.handler.api.HandlerResult)15 ContextPolicyManager (org.codice.ddf.security.policy.context.ContextPolicyManager)11 ContextPolicy (org.codice.ddf.security.policy.context.ContextPolicy)9 ServletRequest (javax.servlet.ServletRequest)6 ServletResponse (javax.servlet.ServletResponse)6 AuthenticationException (org.codice.ddf.platform.filter.AuthenticationException)6 SecurityLogger (ddf.security.audit.SecurityLogger)5 AuthenticationHandler (org.codice.ddf.security.handler.api.AuthenticationHandler)5 SecurityConstants (ddf.security.SecurityConstants)4 Subject (ddf.security.Subject)4 CollectionPermission (ddf.security.permission.CollectionPermission)4 CollectionPermissionImpl (ddf.security.permission.impl.CollectionPermissionImpl)4 KeyValuePermissionImpl (ddf.security.permission.impl.KeyValuePermissionImpl)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4