當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。