Search in sources :

Example 16 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method filterRegistrationBeansSkipsRegisteredFilters.

@Test
public void filterRegistrationBeansSkipsRegisteredFilters() throws Exception {
    addWebServerFactoryBean();
    Filter filter = mock(Filter.class);
    FilterRegistrationBean<Filter> initializer = new FilterRegistrationBean<>(filter);
    this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
    this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
    this.context.refresh();
    ServletContext servletContext = getWebServerFactory().getServletContext();
    verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any());
}
Also used : Filter(javax.servlet.Filter) ServletContext(javax.servlet.ServletContext) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.Test)

Example 17 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project spring-boot by spring-projects.

the class JerseyAutoConfiguration method jerseyFilterRegistration.

@Bean
@ConditionalOnMissingBean(name = "jerseyFilterRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "filter")
public FilterRegistrationBean<ServletContainer> jerseyFilterRegistration() {
    FilterRegistrationBean<ServletContainer> registration = new FilterRegistrationBean<>();
    registration.setFilter(new ServletContainer(this.config));
    registration.setUrlPatterns(Arrays.asList(this.path));
    registration.setOrder(this.jersey.getFilter().getOrder());
    registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(this.path));
    addInitParameters(registration);
    registration.setName("jerseyFilter");
    registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
    return registration;
}
Also used : ServletContainer(org.glassfish.jersey.servlet.ServletContainer) DispatcherType(javax.servlet.DispatcherType) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RegistrationBean(org.springframework.boot.web.servlet.RegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 18 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project spring-boot by spring-projects.

the class JerseyAutoConfiguration method requestContextFilter.

@Bean
@ConditionalOnMissingBean
public FilterRegistrationBean<RequestContextFilter> requestContextFilter() {
    FilterRegistrationBean<RequestContextFilter> registration = new FilterRegistrationBean<>();
    registration.setFilter(new RequestContextFilter());
    registration.setOrder(this.jersey.getFilter().getOrder() - 1);
    registration.setName("requestContextFilter");
    return registration;
}
Also used : RequestContextFilter(org.springframework.web.filter.RequestContextFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RegistrationBean(org.springframework.boot.web.servlet.RegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean)

Example 19 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project libresonic by Libresonic.

the class Application method restFilterRegistration.

@Bean
public FilterRegistrationBean restFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(restFilter());
    registration.addUrlPatterns("/rest/*");
    registration.setName("RESTFilter");
    registration.setOrder(3);
    return registration;
}
Also used : FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 20 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project libresonic by Libresonic.

the class Application method metricsFilterRegistration.

@Bean
public FilterRegistrationBean metricsFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(metricsFilter());
    registration.setOrder(7);
    return registration;
}
Also used : FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)23 Bean (org.springframework.context.annotation.Bean)21 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)10 HashMap (java.util.HashMap)4 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 Filter (javax.servlet.Filter)2 HttpWebRequestProperties (org.apereo.cas.configuration.model.core.web.security.HttpWebRequestProperties)2 ClientInfoThreadLocalFilter (org.apereo.inspektr.common.web.ClientInfoThreadLocalFilter)2 Test (org.junit.Test)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)2 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)2 RegistrationBean (org.springframework.boot.web.servlet.RegistrationBean)2 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)1 CsrfFilter (com.erudika.scoold.utils.CsrfFilter)1 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)1 DispatcherType (javax.servlet.DispatcherType)1 ServletContext (javax.servlet.ServletContext)1 AuditProperties (org.apereo.cas.configuration.model.core.audit.AuditProperties)1 ThreadContextMDCServletFilter (org.apereo.cas.logging.web.ThreadContextMDCServletFilter)1