use of javax.servlet.FilterChain in project ddf by codice.
the class LoginFilterTest method testValidEmptySubject.
@Test
public void testValidEmptySubject() throws IOException, ServletException {
FilterConfig filterConfig = mock(FilterConfig.class);
LoginFilter loginFilter = new LoginFilter();
loginFilter.setSessionFactory(sessionFactory);
loginFilter.init(filterConfig);
HttpServletRequest servletRequest = new TestHttpServletRequest();
servletRequest.setAttribute("ddf.security.token", mock(HandlerResult.class));
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
verify(filterChain, never()).doFilter(servletRequest, servletResponse);
}
use of javax.servlet.FilterChain in project ddf by codice.
the class LoginFilterTest method testExpiredSamlCookie.
@Test(expected = ServletException.class)
public void testExpiredSamlCookie() throws IOException, XMLStreamException, ServletException, ParserConfigurationException, SAXException, SecurityServiceException {
FilterConfig filterConfig = mock(FilterConfig.class);
LoginFilter loginFilter = new LoginFilter();
loginFilter.setSessionFactory(sessionFactory);
ddf.security.service.SecurityManager securityManager = mock(ddf.security.service.SecurityManager.class);
loginFilter.setSecurityManager(securityManager);
loginFilter.setSignaturePropertiesFile("signature.properties");
try {
loginFilter.init(filterConfig);
} catch (ServletException e) {
fail(e.getMessage());
}
HttpServletRequest servletRequest = new TestHttpServletRequest();
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
SecurityToken securityToken = new SecurityToken();
Element thisToken = readDocument("/good_saml.xml").getDocumentElement();
securityToken.setToken(thisToken);
SAMLAuthenticationToken samlToken = new SAMLAuthenticationToken(null, securityToken, "karaf");
HandlerResult result = new HandlerResult(HandlerResult.Status.COMPLETED, samlToken);
servletRequest.setAttribute("ddf.security.token", result);
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
}
use of javax.servlet.FilterChain in project ddf by codice.
the class LoginFilterTest method testBadSubject.
/**
* Test with a bad subject - shouldn't call the filter chain, just returns.
*
* @throws IOException
* @throws ServletException
*/
@Test
public void testBadSubject() throws IOException, ServletException {
FilterConfig filterConfig = mock(FilterConfig.class);
LoginFilter loginFilter = new LoginFilter();
loginFilter.setSessionFactory(sessionFactory);
try {
loginFilter.init(filterConfig);
} catch (ServletException e) {
fail(e.getMessage());
}
HttpServletRequest servletRequest = new TestHttpServletRequest();
servletRequest.setAttribute("ddf.security.securityToken", mock(SecurityToken.class));
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
fail("Should not have continued down the filter chain without a valid Subject");
}
};
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
}
use of javax.servlet.FilterChain in project ddf by codice.
the class GuestHandlerTest method testGetNormalizedToken.
/**
* This test ensures the proper functionality of GuestHandler's method,
* getNormalizedToken().
*/
@Test
public void testGetNormalizedToken() throws WSSecurityException {
GuestHandler handler = new GuestHandler();
PKIAuthenticationTokenFactory tokenFactory = new PKIAuthenticationTokenFactory();
handler.setTokenFactory(tokenFactory);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
/**
* Note that the parameters are insignificant as GuestHandler
* does not use them.
*/
HandlerResult result = handler.getNormalizedToken(request, response, chain, true);
assertNotNull(result);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
assertTrue(result.getToken() instanceof GuestAuthenticationToken);
assertEquals("Guest", result.getToken().getCredentials());
assertEquals(null, result.getToken().getRealm());
assertEquals("null-GuestHandler", result.getSource());
}
use of javax.servlet.FilterChain in project ddf by codice.
the class GuestHandlerTest method testHandleError.
@Test
public void testHandleError() throws ServletException, IOException {
GuestHandler handler = new GuestHandler();
PKIAuthenticationTokenFactory tokenFactory = new PKIAuthenticationTokenFactory();
handler.setTokenFactory(tokenFactory);
StringWriter writer = new StringWriter(1024);
PrintWriter printWriter = new PrintWriter(writer);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getAttribute(anyString())).thenReturn("DDF");
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
FilterChain chain = mock(FilterChain.class);
/**
* Note that the parameters are insignificant as GuestHandler
* does not use them.
*/
HandlerResult result = handler.handleError(request, response, chain);
assertNotNull(result);
assertEquals(HandlerResult.Status.REDIRECTED, result.getStatus());
assertNull(result.getToken());
assertEquals("DDF-GuestHandler", result.getSource());
assertEquals(GuestHandler.INVALID_MESSAGE, writer.toString());
}
Aggregations