Java 类org.springframework.web.filter.OncePerRequestFilter 实例源码

项目:trueyes    文件:WebfrontUIApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                FilterChain filterChain) throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:restbucks-member    文件:WebSecurityConfiguration.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                        FilterChain filterChain) throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:putput    文件:WebConfig.java   
@Bean
public OncePerRequestFilter protocolForwardFilter() {
  return new OncePerRequestFilter() {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
      String forwardedProtocolHeader = request.getHeader("X-Forwarded-Proto");
      boolean forwardToHttps = Boolean.parseBoolean(environment.getProperty("forward.to.https", "true"));

      if (forwardToHttps && forwardedProtocolHeader != null && forwardedProtocolHeader.equals("http")) {
        response.sendRedirect(environment.getProperty("secure.base.url", "https://putput.org") + request.getRequestURI());
      } else {
        filterChain.doFilter(request, response);
      }

    }
  };
}
项目:cloud    文件:ResourceServerConfig.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request
                    .getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = new Cookie("XSRF-TOKEN",
                        csrf.getToken());
                cookie.setPath("/");
                response.addCookie(cookie);
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:OpenViSu    文件:SecurityConfiguration.java   
private Filter csrfHeaderFilter()
{
  return new OncePerRequestFilter() {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException
    {
      CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
      if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
          cookie = new Cookie("XSRF-TOKEN", token);
          cookie.setPath("/");
          response.addCookie(cookie);
        }
      }
      filterChain.doFilter(request, response);
    }
  };
}
项目:complete-transaction-management    文件:MainApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:hojeehdiaderua    文件:SecurityConfig.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:eve-oauth2-example    文件:EveOAuth2Example.java   
private Filter csrfHeaderFilter()
{
  return new OncePerRequestFilter()
  {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                    FilterChain filterChain)
      throws ServletException, IOException
    {
      CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
      if(csrf != null)
      {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if(cookie == null || token != null && !token.equals(cookie.getValue()))
        {
          cookie = new Cookie("XSRF-TOKEN", token);
          cookie.setPath("/");
          response.addCookie(cookie);
        }
      }
      filterChain.doFilter(request, response);
    }
  };
}
项目:harris-de-swarm    文件:UiApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:oauth-register-broker    文件:SecurityConfig.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:db-dumper-service    文件:SecurityConfig.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:dick    文件:SsoSecurityAutoConfiguration.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request
                    .getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = new Cookie("XSRF-TOKEN",
                        csrf.getToken());
                cookie.setPath("/");
                response.addCookie(cookie);
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:building-microservices    文件:SsoUiApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {

        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                        throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request
                    .getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null
                        || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }

    };
}
项目:spring-polymer-demo    文件:PolymerDemoSpringSessionConfig.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:spring-polymer-demo    文件:PolymerDemoOAuthConfig.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:spring-multi-module-oauth-sso    文件:AuthClientApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request
                    .getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request,
                        "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:spring-multi-module-oauth-sso    文件:AuthClientApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request
                    .getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request,
                        "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:spring-multi-module-oauth-sso    文件:AuthserverApplication.java   
@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 {
            // We don't want to allow access to a resource with no token so clear
            // the security context in case it is actually an OAuth2Authentication
            if (tokenExtractor.extract(request) == null) {
                SecurityContextHolder.clearContext();
            }
            filterChain.doFilter(request, response);
        }
    }, AbstractPreAuthenticatedProcessingFilter.class);
    http.authorizeRequests().anyRequest().authenticated();
}
项目:gear-service    文件:SecurityConfiguration.java   
/**
 * Method csrfHeaderFilter creates filter for correct csrf security
 * @return OncePerRequestFilter for correct csrf security
 */
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    cookie.setSecure(true);
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:socialDocumentLibrary    文件:WebSecurityContext.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:spring-cloud-cloudfoundry    文件:StickyFilterConfiguration.java   
@Bean
public FilterRegistrationBean<?> stickyCloudFoundryFilter() {
    FilterRegistrationBean<Filter> filter = new FilterRegistrationBean<Filter>();
    filter.setOrder(Ordered.LOWEST_PRECEDENCE);
    filter.setFilter(new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            if (!response.containsHeader("Set-Cookie")) {
                response.addCookie(new Cookie("JSESSIONID", cookie));
            }
            filterChain.doFilter(request, response);
        }
    });
    return filter;
}
项目:LearningAnalyticsProcessor    文件:SecurityConfig.java   
private Filter csrfHeaderFilter() {
  return new OncePerRequestFilter() {      
    @Override
    protected void doFilterInternal(HttpServletRequest request,
        HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {
      CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());

      if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null
            && !token.equals(cookie.getValue())) {
          cookie = new Cookie("XSRF-TOKEN", token);
          cookie.setPath("/");
          response.addCookie(cookie);
        }
      }
      filterChain.doFilter(request, response);
    }
  };
}
项目:JavaSecurity    文件:SsoWithGitHubApplication.java   
private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    cookie.setHttpOnly(true);
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:sagan    文件:SecurityConfig.java   
@Override
protected void configure(HttpSecurity http) throws Exception {
    configureHeaders(http.headers());
    http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint())
            .and().requestMatchers().antMatchers("/admin/**", "/signout").and()
            .addFilterAfter(new OncePerRequestFilter() {

                // TODO this filter needs to be removed once basic auth is removed
                @Override
                protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                                FilterChain filterChain) throws ServletException, IOException {
                    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                    if (authentication == null || !authentication.isAuthenticated()
                            || !(authentication.getPrincipal() instanceof Long)) {
                        throw new BadCredentialsException("Not a github user!");
                    }
                    filterChain.doFilter(request, response);
                }
            }, ExceptionTranslationFilter.class);
    http.logout().logoutRequestMatcher(new AntPathRequestMatcher("/signout"))
            .logoutSuccessUrl("/").and().authorizeRequests().anyRequest()
            .authenticated();
    if (isForceHttps()) {
        http.requiresChannel().anyRequest().requiresSecure();
    }
}
项目:generator-jhipster    文件:_OAuth2Configuration.java   
@Bean
public FilterRegistrationBean saveLoginOriginFilter() {
    Filter filter = new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                        FilterChain filterChain)
            throws ServletException, IOException {
            if (request.getRemoteUser() == null && request.getRequestURI().endsWith("/login")) {
                String referrer = request.getHeader("referer");
                if (!StringUtils.isBlank(referrer) &&
                    request.getSession().getAttribute(SAVED_LOGIN_ORIGIN_URI) == null) {
                    log.debug("Saving login origin URI: {}", referrer);
                    request.getSession().setAttribute(SAVED_LOGIN_ORIGIN_URI, referrer);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
    FilterRegistrationBean bean = new FilterRegistrationBean(filter);
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return bean;
}
项目:openlmis-stockmanagement    文件:ResourceServerSecurityConfiguration.java   
@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 {
      // We don't want to allow access to a resource with no token so clear
      // 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();
}
项目:openlmis-template-service    文件:ResourceServerSecurityConfiguration.java   
@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 {
      // We don't want to allow access to a resource with no token so clear
      // 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(
          "/template",
          "/webjars/**",
          "/template/webjars/**",
          "/template/docs/**"
      ).permitAll()
      .antMatchers("/**").fullyAuthenticated();
}
项目:gwt-bean-validators-example    文件:WebSecurityConfig.java   
private Filter csrfHeaderFilter() {
  return new OncePerRequestFilter() {
    @Override
    protected void doFilterInternal(final HttpServletRequest prequest,
        final HttpServletResponse presponse, final FilterChain pfilterChain)
        throws ServletException, IOException {
      WebSecurityConfig.this.csrfCookieHandler.setCookie(prequest, presponse);
      pfilterChain.doFilter(prequest, presponse);
    }
  };
}
项目:portal-de-servicos    文件:FilterConfig.java   
@Bean
public FilterRegistrationBean securityHeadersFilter(@Value("${pds.piwik.url}") String urlPiwik) {
    return filter(2, new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            filterChain.doFilter(request, response);
            response.setHeader("X-XSS-Protection", "0");
            response.setHeader("X-Content-Type-Options", "nosniff");
            response.setHeader("Content-Security-Policy", "script-src: 'self' 'unsafe-inline' '" + urlPiwik + "' 'barra.brasil.gov.br'; default-src: 'self'");
        }
    });
}
项目:identity-sample-apps    文件:Application.java   
@Bean
public ResourceServerConfigurer resourceServerConfigurerAdapter() {
    return new ResourceServerConfigurerAdapter() {
        @Override
        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
            resources.resourceId("todo");
        }

        @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 {
                    // We don't want to allow access to a resource with no token so clear
                    // 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().anyRequest().authenticated();
        }
    };
}
项目:loc-framework    文件:LocSpringMvcAutoConfiguration.java   
@Bean
@ConditionalOnClass(OncePerRequestFilter.class)
@ConditionalOnProperty(value = "loc.web.springmvc.log.enabled", matchIfMissing = true)
public Filter accessLogFilter(LocSpringMvcLogProperties locSpringMvcProperties) {
  return new LocAccessLogFilter(locSpringMvcProperties);
}
项目:moserp    文件:OAuthConfiguration.java   
/**
 * Spring security offers in-built protection for cross site request forgery
 * (CSRF) by needing a custom token in the header for any requests that are
 * NOT safe i.e. modify the resources from the server e.g. POST, PUT & PATCH
 * etc.<br>
 * <br>
 *
 * This protection is achieved using cookies that send a custom value (would
 * remain same for the session) in the first request and then the front-end
 * would send back the value as a custom header.<br>
 * <br>
 *
 * In this method we create a filter that is applied to the web security as
 * follows:
 * <ol>
 * <li>Spring security provides the CSRF token value as a request attribute;
 * so we extract it from there.</li>
 * <li>If we have the token, Angular wants the cookie name to be
 * "XSRF-TOKEN". So we add the cookie if it's not there and set the path for
 * the cookie to be "/" which is root. In more complicated cases, this might
 * have to be the context root of the api gateway.</li>
 * <li>We forward the request to the next filter in the chain</li>
 * </ol>
 *
 * The request-to-cookie filter that we add needs to be after the
 * <code>csrf()</code> filter so that the request attribute for CsrfToken
 * has been already added before we start to process it.
 *
 * @return
 */
private Filter createCSRFHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                                        HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, CSRF_COOKIE_NAME);
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie(CSRF_COOKIE_NAME, token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}
项目:spring-boot-microservices    文件:OAuthConfiguration.java   
/**
 * Spring security offers in-built protection for cross site request forgery
 * (CSRF) by needing a custom token in the header for any requests that are
 * NOT safe i.e. modify the resources from the server e.g. POST, PUT & PATCH
 * etc.<br>
 * <br>
 * 
 * This protection is achieved using cookies that send a custom value (would
 * remain same for the session) in the first request and then the front-end
 * would send back the value as a custom header.<br>
 * <br>
 * 
 * In this method we create a filter that is applied to the web security as
 * follows:
 * <ol>
 * <li>Spring security provides the CSRF token value as a request attribute;
 * so we extract it from there.</li>
 * <li>If we have the token, Angular wants the cookie name to be
 * "XSRF-TOKEN". So we add the cookie if it's not there and set the path for
 * the cookie to be "/" which is root. In more complicated cases, this might
 * have to be the context root of the api gateway.</li>
 * <li>We forward the request to the next filter in the chain</li>
 * </ol>
 * 
 * The request-to-cookie filter that we add needs to be after the
 * <code>csrf()</code> filter so that the request attribute for CsrfToken
 * has been already added before we start to process it.
 * 
 * @return
 */
private Filter createCSRFHeaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = WebUtils.getCookie(request, CSRF_COOKIE_NAME);
                String token = csrf.getToken();
                if (cookie == null || token != null
                        && !token.equals(cookie.getValue())) {
                    cookie = new Cookie(CSRF_COOKIE_NAME, token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}