use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenAppendFiltersEmptyThenException.
@Test
public void onStartupWhenAppendFiltersEmptyThenException() {
ServletContext context = mock(ServletContext.class);
FilterRegistration.Dynamic registration = mock(FilterRegistration.Dynamic.class);
ArgumentCaptor<DelegatingFilterProxy> proxyCaptor = ArgumentCaptor.forClass(DelegatingFilterProxy.class);
given(context.addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture())).willReturn(registration);
assertThatIllegalArgumentException().isThrownBy(() -> new AbstractSecurityWebApplicationInitializer() {
@Override
protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
appendFilters(context);
}
}.onStartup(context)).withMessage("filters cannot be null or empty");
assertProxyDefaults(proxyCaptor.getValue());
}
use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenInsertFiltersThenInserted.
@Test
public void onStartupWhenInsertFiltersThenInserted() {
Filter filter1 = mock(Filter.class);
Filter filter2 = mock(Filter.class);
ServletContext context = mock(ServletContext.class);
FilterRegistration.Dynamic registration = mock(FilterRegistration.Dynamic.class);
ArgumentCaptor<DelegatingFilterProxy> proxyCaptor = ArgumentCaptor.forClass(DelegatingFilterProxy.class);
given(context.addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture())).willReturn(registration);
given(context.addFilter(anyString(), eq(filter1))).willReturn(registration);
given(context.addFilter(anyString(), eq(filter2))).willReturn(registration);
new AbstractSecurityWebApplicationInitializer() {
@Override
protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
insertFilters(context, filter1, filter2);
}
}.onStartup(context);
assertProxyDefaults(proxyCaptor.getValue());
verify(registration, times(3)).addMappingForUrlPatterns(DEFAULT_DISPATCH, false, "/*");
verify(registration, times(3)).setAsyncSupported(true);
verifyNoAddListener(context);
verify(context).addFilter(anyString(), eq(filter1));
verify(context).addFilter(anyString(), eq(filter2));
}
use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenAppendFiltersThenAppended.
@Test
public void onStartupWhenAppendFiltersThenAppended() {
Filter filter1 = mock(Filter.class);
Filter filter2 = mock(Filter.class);
ServletContext context = mock(ServletContext.class);
FilterRegistration.Dynamic registration = mock(FilterRegistration.Dynamic.class);
ArgumentCaptor<DelegatingFilterProxy> proxyCaptor = ArgumentCaptor.forClass(DelegatingFilterProxy.class);
given(context.addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture())).willReturn(registration);
given(context.addFilter(anyString(), eq(filter1))).willReturn(registration);
given(context.addFilter(anyString(), eq(filter2))).willReturn(registration);
new AbstractSecurityWebApplicationInitializer() {
@Override
protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
appendFilters(context, filter1, filter2);
}
}.onStartup(context);
verify(registration, times(1)).addMappingForUrlPatterns(DEFAULT_DISPATCH, false, "/*");
verify(registration, times(2)).addMappingForUrlPatterns(DEFAULT_DISPATCH, true, "/*");
verify(registration, times(3)).setAsyncSupported(true);
verifyNoAddListener(context);
verify(context, times(3)).addFilter(anyString(), any(Filter.class));
}
use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenSpringSecurityFilterChainAlreadyRegisteredThenException.
@Test
public void onStartupWhenSpringSecurityFilterChainAlreadyRegisteredThenException() {
ServletContext context = mock(ServletContext.class);
assertThatIllegalStateException().isThrownBy(() -> new AbstractSecurityWebApplicationInitializer() {
}.onStartup(context)).withMessage("Duplicate Filter registration for 'springSecurityFilterChain'. " + "Check to ensure the Filter is only configured once.");
}
use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenConfigurationClassThenAddsContextLoaderListener.
@Test
public void onStartupWhenConfigurationClassThenAddsContextLoaderListener() {
ServletContext context = mock(ServletContext.class);
FilterRegistration.Dynamic registration = mock(FilterRegistration.Dynamic.class);
ArgumentCaptor<DelegatingFilterProxy> proxyCaptor = ArgumentCaptor.forClass(DelegatingFilterProxy.class);
given(context.addFilter(eq("springSecurityFilterChain"), proxyCaptor.capture())).willReturn(registration);
new AbstractSecurityWebApplicationInitializer(MyRootConfiguration.class) {
}.onStartup(context);
assertProxyDefaults(proxyCaptor.getValue());
verify(registration).addMappingForUrlPatterns(DEFAULT_DISPATCH, false, "/*");
verify(registration).setAsyncSupported(true);
verify(context).addListener(any(ContextLoaderListener.class));
}
Aggregations