use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenInsertFiltersEmptyThenException.
@Test
public void onStartupWhenInsertFiltersEmptyThenException() {
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) {
insertFilters(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 onStartupWhenEnableHttpSessionEventPublisherIsTrueThenAddsHttpSessionEventPublisher.
@Test
public void onStartupWhenEnableHttpSessionEventPublisherIsTrueThenAddsHttpSessionEventPublisher() {
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() {
@Override
protected boolean enableHttpSessionEventPublisher() {
return true;
}
}.onStartup(context);
assertProxyDefaults(proxyCaptor.getValue());
verify(registration).addMappingForUrlPatterns(DEFAULT_DISPATCH, false, "/*");
verify(registration).setAsyncSupported(true);
verify(context).addListener(HttpSessionEventPublisher.class.getName());
}
use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenNullFilterInsertedThenException.
@Test
public void onStartupWhenNullFilterInsertedThenException() {
Filter filter = 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(filter))).willReturn(registration);
assertThatIllegalArgumentException().isThrownBy(() -> new AbstractSecurityWebApplicationInitializer() {
@Override
protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
insertFilters(context, filter, null);
}
}.onStartup(context)).withMessageContaining("filters cannot contain null values");
verify(context, times(2)).addFilter(anyString(), any(Filter.class));
}
use of jakarta.servlet.ServletContext in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializerTests method onStartupWhenDefaultContextThenRegistersSpringSecurityFilterChain.
@Test
public void onStartupWhenDefaultContextThenRegistersSpringSecurityFilterChain() {
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() {
}.onStartup(context);
assertProxyDefaults(proxyCaptor.getValue());
verify(registration).addMappingForUrlPatterns(DEFAULT_DISPATCH, false, "/*");
verify(registration).setAsyncSupported(true);
verifyNoAddListener(context);
}
use of jakarta.servlet.ServletContext in project spring-framework by spring-projects.
the class FreeMarkerMacroTests method setup.
@BeforeEach
public void setup() throws Exception {
ServletContext sc = new MockServletContext();
wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
// final Template expectedTemplate = new Template();
fc = new FreeMarkerConfigurer();
fc.setTemplateLoaderPaths("classpath:/", "file://" + System.getProperty("java.io.tmpdir"));
fc.afterPropertiesSet();
wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc);
wac.refresh();
request = new MockHttpServletRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
response = new MockHttpServletResponse();
}
Aggregations