use of javax.servlet.FilterConfig in project simba-os by cegeka.
the class SystemConfigurationTest method configurationThroughFilterConfig.
@Test
public void configurationThroughFilterConfig() {
final ServletContext servletContextMock = setupServletContextMock(Collections.<String, String>emptyMap());
final FilterConfig filterConfigMock = setupFilterConfigMock(servletContextMock, Collections.singletonMap(SYS_PROP_SIMBA_INTERNAL_SERVICE_URL, SERVICE_URL_FILTERCONFIG_VALUE));
assertEquals(SERVICE_URL_FILTERCONFIG_VALUE, SystemConfiguration.getSimbaServiceURL(filterConfigMock));
}
use of javax.servlet.FilterConfig 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.FilterConfig 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.FilterConfig 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.FilterConfig in project ddf by codice.
the class AuthorizationFilterTest method testNoSubject.
@Test
public void testNoSubject() {
FilterConfig filterConfig = mock(FilterConfig.class);
ContextPolicyManager contextPolicyManager = new TestPolicyManager();
contextPolicyManager.setContextPolicy(PATH, getMockContextPolicy());
AuthorizationFilter loginFilter = new AuthorizationFilter(contextPolicyManager);
try {
loginFilter.init(filterConfig);
} catch (ServletException e) {
fail(e.getMessage());
}
HttpServletRequest servletRequest = getMockServletRequest();
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = (request, response) -> fail("Should not have called doFilter without a valid Subject");
try {
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
} catch (IOException | ServletException e) {
fail(e.getMessage());
}
}
Aggregations