use of javax.servlet.FilterChain in project ddf by codice.
the class SAMLAssertionHandlerTest method testGetNormalizedTokenSuccessWithHeader.
/**
* This test ensures the proper functionality of SAMLAssertionHandler's
* method, getNormalizedToken(), when given a valid HttpServletRequest.
*/
@Test
public void testGetNormalizedTokenSuccessWithHeader() 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();
doReturn("SAML " + RestSecurity.deflateAndBase64Encode(saml)).when(request).getHeader(SecurityConstants.SAML_HEADER_NAME);
HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
assertNotNull(result);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
use of javax.servlet.FilterChain 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 javax.servlet.FilterChain 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 javax.servlet.FilterChain 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 javax.servlet.FilterChain in project ddf by codice.
the class BasicAuthenticationHandlerTest method testGetNormalizedTokenNoResolveNoAction.
/**
* This test case handles the scenario in which the credentials are not to
* be obtained (i.e. resolve flag is not set) and the UsernameTokenType
* could not be created with the HTTP request.
*/
@Test
public void testGetNormalizedTokenNoResolveNoAction() {
BasicAuthenticationHandler handler = new BasicAuthenticationHandler();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
HandlerResult result = handler.getNormalizedToken(request, response, chain, false);
assertNotNull(result);
assertEquals(HandlerResult.Status.NO_ACTION, result.getStatus());
}
Aggregations