Search in sources :

Example 6 with OncePerRequestFilter

use of org.springframework.web.filter.OncePerRequestFilter in project flow by vaadin.

the class Application method publicImagesAliasFilter.

// Test views use relative path to images, that cannot be correctly resolved
// where setting vaadin.urlMapping, because view base path differs from
// web application context path
// The following filter forwards request from
// {vaadin.urlMapping}/public/images
// to /public/images, so they are then served by spring.
@Bean
FilterRegistrationBean<?> publicImagesAliasFilter() {
    FilterRegistrationBean<OncePerRequestFilter> registrationBean = new FilterRegistrationBean<>(new OncePerRequestFilter() {

        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            request.getRequestDispatcher(request.getRequestURI().substring(7)).forward(request, response);
        }
    });
    registrationBean.addUrlPatterns("/vaadin/public/images/*", "/vaadin/public/profiles/*");
    registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return registrationBean;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with OncePerRequestFilter

use of org.springframework.web.filter.OncePerRequestFilter in project openlmis-stockmanagement by OpenLMIS.

the class ResourceServerSecurityConfiguration method configure.

@Override
public void configure(HttpSecurity http) throws Exception {
    http.addFilterAfter(new OncePerRequestFilter() {

        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            // the security context in case it is actually an OAuth2Authentication
            if (tokenExtractor.extract(request) == null) {
                SecurityContextHolder.clearContext();
            }
            filterChain.doFilter(request, response);
        }
    }, AbstractPreAuthenticatedProcessingFilter.class);
    http.csrf().disable();
    http.authorizeRequests().antMatchers("/stockmanagement", "/webjars/**", "/stockmanagement/webjars/**", "/stockmanagement/docs/**").permitAll().antMatchers("/**").fullyAuthenticated();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException)

Aggregations

FilterChain (javax.servlet.FilterChain)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)7 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3 Bean (org.springframework.context.annotation.Bean)3 Cookie (javax.servlet.http.Cookie)2 CsrfToken (org.springframework.security.web.csrf.CsrfToken)2 MockFilterChain (com.thoughtworks.go.http.mocks.MockFilterChain)1 MockHttpServletRequest (com.thoughtworks.go.http.mocks.MockHttpServletRequest)1 MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)1 UsernamePassword (com.thoughtworks.go.server.newsecurity.models.UsernamePassword)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 Filter (javax.servlet.Filter)1 Servlet (javax.servlet.Servlet)1 Test (org.junit.jupiter.api.Test)1 OAuth2ClientAuthenticationProcessingFilter (org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter)1 SecurityFilterChain (org.springframework.security.web.SecurityFilterChain)1