use of org.codice.ddf.platform.filter.SecurityFilter in project ddf by codice.
the class JettyAuthenticatorTest method testInitializeSecurityFilter.
@Test
public void testInitializeSecurityFilter() throws IOException, ServerAuthException, AuthenticationException {
// given
final HttpSession httpSession = mock(HttpSession.class);
final Request servletRequest = mock(Request.class);
final ServletContext servletContext = mock(ServletContext.class);
final Dictionary dictionary = new Hashtable();
final String filterNameValue = "my-test-filter";
dictionary.put("osgi.http.whiteboard.filter.name", filterNameValue);
final String param1Key = "param1Key";
final String param1Value = "param1Value";
dictionary.put("init." + param1Key, param1Value);
final String param2Key = "param2Key";
final String param2Value = "param2Value";
dictionary.put("init." + param2Key, param2Value);
final SecurityFilter securityFilter = registerSecurityFilter(dictionary);
// when
jettyAuthenticator.validateRequest(servletRequest, mock(ServletResponse.class), false);
// then
verify(securityFilter).init();
}
use of org.codice.ddf.platform.filter.SecurityFilter in project ddf by codice.
the class JettyAuthenticatorTest method testDoFilterAfterInitDelegateServletFilterWithNullFilterConfig.
/**
* The {@link javax.servlet.Filter#init(FilterConfig)} javadoc does not specify that the {@link
* FilterConfig} argument may not be null. This test confirms that there are no errors when
* initializing the {@link SecurityFilter}s and filtering if this situation occurs.
*/
@Test
public void testDoFilterAfterInitDelegateServletFilterWithNullFilterConfig() throws IOException, ServerAuthException, AuthenticationException {
// given
jettyAuthenticator.setConfiguration(null);
final SecurityFilter securityFilter = registerSecurityFilter(new Hashtable());
final ServletRequest servletRequest = mock(ServletRequest.class);
final ServletResponse servletResponse = mock(ServletResponse.class);
// when
jettyAuthenticator.validateRequest(servletRequest, servletResponse, false);
// then
final InOrder inOrder = Mockito.inOrder(securityFilter);
inOrder.verify(securityFilter).init();
inOrder.verify(securityFilter).doFilter(eq(servletRequest), eq(servletResponse), any(SecurityFilterChain.class));
}
use of org.codice.ddf.platform.filter.SecurityFilter in project ddf by codice.
the class JettyAuthenticatorTest method testRemoveSecurityFilter.
@Test
public void testRemoveSecurityFilter() {
// given
final SecurityFilter securityFilter = mock(SecurityFilter.class);
final MockServiceReference securityFilterServiceReference = new MockServiceReference();
securityFilterServiceReference.setProperties(new Hashtable());
when(bundleContext.getService(securityFilterServiceReference)).thenReturn(securityFilter);
registeredSecurityFilterServiceReferences.add(securityFilterServiceReference);
// when
jettyAuthenticator.removeSecurityFilter(securityFilterServiceReference);
// then
verify(securityFilter).destroy();
}
use of org.codice.ddf.platform.filter.SecurityFilter in project ddf by codice.
the class JettyAuthenticatorTest method testDoFilterWithSecurityFilter.
@Test
public void testDoFilterWithSecurityFilter() throws IOException, ServerAuthException, AuthenticationException {
// given
final SecurityFilter securityFilter = registerSecurityFilter(new Hashtable());
final ServletRequest servletRequest = mock(ServletRequest.class);
final ServletResponse servletResponse = mock(ServletResponse.class);
// when
jettyAuthenticator.validateRequest(servletRequest, servletResponse, false);
// then
final InOrder inOrder = Mockito.inOrder(securityFilter);
inOrder.verify(securityFilter).doFilter(eq(servletRequest), eq(servletResponse), any(SecurityFilterChain.class));
}
use of org.codice.ddf.platform.filter.SecurityFilter in project ddf by codice.
the class JettyAuthenticatorTest method registerSecurityFilter.
private SecurityFilter registerSecurityFilter(Dictionary serviceProperties) throws IOException, AuthenticationException {
final SecurityFilter securityFilter = mock(SecurityFilter.class);
Mockito.doAnswer(invocation -> {
Object[] args = invocation.getArguments();
((SecurityFilterChain) args[2]).doFilter(((ServletRequest) args[0]), ((ServletResponse) args[1]));
return null;
}).when(securityFilter).doFilter(any(ServletRequest.class), any(ServletResponse.class), any(SecurityFilterChain.class));
final MockServiceReference securityFilterServiceReference = new MockServiceReference();
securityFilterServiceReference.setProperties(serviceProperties);
when(bundleContext.getService(securityFilterServiceReference)).thenReturn(securityFilter);
registeredSecurityFilterServiceReferences.add(securityFilterServiceReference);
return securityFilter;
}
Aggregations