use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class SAMLAssertionHandlerTest method testGetNormalizedTokenFromSession.
@Test
public void testGetNormalizedTokenFromSession() throws Exception {
SAMLAssertionHandler handler = new SAMLAssertionHandler();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
when(request.getCookies()).thenReturn(null);
HttpSession session = mock(HttpSession.class);
when(request.getSession(false)).thenReturn(session);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("foo");
SecurityTokenHolder tokenHolder = mock(SecurityTokenHolder.class);
when(session.getAttribute(SecurityConstants.SAML_ASSERTION)).thenReturn(tokenHolder);
SecurityToken securityToken = mock(SecurityToken.class);
when(tokenHolder.getSecurityToken("foo")).thenReturn(securityToken);
when(securityToken.getToken()).thenReturn(readDocument("/saml.xml").getDocumentElement());
HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
assertNotNull(result);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class SAMLAssertionHandlerTest method testGetNormalizedTokenSuccessWithCookie.
/**
* This test ensures the proper functionality of SAMLAssertionHandler's
* method, getNormalizedToken(), when given a valid HttpServletRequest.
* Uses legacy SAML cookie
*/
@Test
public void testGetNormalizedTokenSuccessWithCookie() throws Exception {
SAMLAssertionHandler handler = new SAMLAssertionHandler();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
Element assertion = readDocument("/saml.xml").getDocumentElement();
String assertionId = assertion.getAttributeNodeNS(null, "ID").getNodeValue();
SecurityToken samlToken = new SecurityToken(assertionId, assertion, null);
SamlAssertionWrapper wrappedAssertion = new SamlAssertionWrapper(samlToken.getToken());
String saml = wrappedAssertion.assertionToString();
Cookie cookie = new Cookie(SecurityConstants.SAML_COOKIE_NAME, RestSecurity.deflateAndBase64Encode(saml));
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
assertNotNull(result);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class SAMLAssertionHandlerTest method testGetNormalizedTokenFailureWithHeader.
/**
* This test ensures the proper functionality of SAMLAssertionHandler's
* method, getNormalizedToken(), when given an invalid HttpServletRequest.
*/
@Test
public void testGetNormalizedTokenFailureWithHeader() {
SAMLAssertionHandler handler = new SAMLAssertionHandler();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
doReturn(null).when(request).getHeader(SecurityConstants.SAML_HEADER_NAME);
HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
assertNotNull(result);
assertEquals(HandlerResult.Status.NO_ACTION, result.getStatus());
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class IdpHandlerTest method testGetNormalizedTokenNoRedirect.
@Test
public void testGetNormalizedTokenNoRedirect() throws Exception {
when(httpRequest.getHeader("User-Agent")).thenReturn(BROWSER_USER_AGENT);
when(httpResponse.getWriter()).thenReturn(mock(PrintWriter.class));
idpMetadata.setMetadata(metadata.replace("HTTP-Redirect", "HTTP-POST"));
HandlerResult handlerResult = idpHandler.getNormalizedToken(httpRequest, httpResponse, null, false);
assertThat("Expected a non null handlerRequest", handlerResult, is(notNullValue(HandlerResult.class)));
assertThat(handlerResult.getStatus(), equalTo(HandlerResult.Status.REDIRECTED));
}
use of org.codice.ddf.security.handler.api.HandlerResult in project ddf by codice.
the class IdpHandlerTest method testHandleError.
@Test
public void testHandleError() throws Exception {
when(httpRequest.getHeader("User-Agent")).thenReturn(BROWSER_USER_AGENT);
HandlerResult handlerResult = idpHandler.handleError(httpRequest, httpResponse, null);
assertThat("Expected a non null handlerRequest", handlerResult, is(notNullValue(HandlerResult.class)));
assertThat(handlerResult.getStatus(), equalTo(HandlerResult.Status.NO_ACTION));
}
Aggregations