当前位置: 首页>>代码示例>>Java>>正文


Java OncePerRequestFilter类代码示例

本文整理汇总了Java中org.springframework.web.filter.OncePerRequestFilter的典型用法代码示例。如果您正苦于以下问题:Java OncePerRequestFilter类的具体用法?Java OncePerRequestFilter怎么用?Java OncePerRequestFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OncePerRequestFilter类属于org.springframework.web.filter包,在下文中一共展示了OncePerRequestFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}
	};
}
 
开发者ID:ksambhav,项目名称:trueyes,代码行数:20,代码来源:WebfrontUIApplication.java

示例2: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
        }
    };
}
 
开发者ID:restbucks,项目名称:restbucks-member,代码行数:20,代码来源:WebSecurityConfiguration.java

示例3: protocolForwardFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
@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);
      }

    }
  };
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:18,代码来源:WebConfig.java

示例4: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}
	};
}
 
开发者ID:JerryNiu,项目名称:cloud,代码行数:19,代码来源:ResourceServerConfig.java

示例5: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
    }
  };
}
 
开发者ID:kreinhard,项目名称:OpenViSu,代码行数:22,代码来源:SecurityConfiguration.java

示例6: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}
	};
}
 
开发者ID:gjk0090,项目名称:complete-transaction-management,代码行数:19,代码来源:MainApplication.java

示例7: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
        }
    };
}
 
开发者ID:ortolanph,项目名称:hojeehdiaderua,代码行数:23,代码来源:SecurityConfig.java

示例8: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
    }
  };
}
 
开发者ID:fetox74,项目名称:eve-oauth2-example,代码行数:26,代码来源:EveOAuth2Example.java

示例9: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
        }
    };
}
 
开发者ID:dick-the-deployer,项目名称:dick,代码行数:19,代码来源:SsoSecurityAutoConfiguration.java

示例10: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}

	};
}
 
开发者ID:livelessons-spring,项目名称:building-microservices,代码行数:25,代码来源:SsoUiApplication.java

示例11: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}
	};
}
 
开发者ID:sdeeg-pivotal,项目名称:spring-polymer-demo,代码行数:22,代码来源:PolymerDemoSpringSessionConfig.java

示例12: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}
	};
}
 
开发者ID:sdeeg-pivotal,项目名称:spring-polymer-demo,代码行数:23,代码来源:PolymerDemoOAuthConfig.java

示例13: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
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);
		}
	};
}
 
开发者ID:mefernandez,项目名称:spring-multi-module-oauth-sso,代码行数:24,代码来源:AuthClientApplication.java

示例14: configure

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
@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();
}
 
开发者ID:mefernandez,项目名称:spring-multi-module-oauth-sso,代码行数:18,代码来源:AuthserverApplication.java

示例15: csrfHeaderFilter

import org.springframework.web.filter.OncePerRequestFilter; //导入依赖的package包/类
/**
 * 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);
        }
    };
}
 
开发者ID:Nandtel,项目名称:gear-service,代码行数:25,代码来源:SecurityConfiguration.java


注:本文中的org.springframework.web.filter.OncePerRequestFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。