當前位置: 首頁>>代碼示例>>Java>>正文


Java CsrfToken.getToken方法代碼示例

本文整理匯總了Java中org.springframework.security.web.csrf.CsrfToken.getToken方法的典型用法代碼示例。如果您正苦於以下問題:Java CsrfToken.getToken方法的具體用法?Java CsrfToken.getToken怎麽用?Java CsrfToken.getToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.security.web.csrf.CsrfToken的用法示例。


在下文中一共展示了CsrfToken.getToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    // Spring put the CSRF token in session attribute "_csrf"
    CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf");

    // Send the cookie only if the token has changed
    String actualToken = request.getHeader("X-CSRF-TOKEN");
    if (actualToken == null || !actualToken.equals(csrfToken.getToken())) {
        // Session cookie that will be used by AngularJS
        String pCookieName = "CSRF-TOKEN";
        Cookie cookie = new Cookie(pCookieName, csrfToken.getToken());
        cookie.setMaxAge(-1);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        response.addCookie(cookie);
    }
    filterChain.doFilter(request, response);
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:19,代碼來源:CsrfCookieGeneratorFilter.java

示例2: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@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,代碼行數:17,代碼來源:CsrfHeaderFilter.java

示例3: csrfHeaderFilter

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的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

示例4: csrfHeaderFilter

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的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:anonymint,項目名稱:harris-de-swarm,代碼行數:23,代碼來源:UiApplication.java

示例5: csrfHeaderFilter

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的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: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(
        HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {
    if (ignoredMatcher.matches(request)) {
        filterChain.doFilter(request, response);
        return;
    }

    final CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());

    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, ANGULAR_CSRF_DEFAULT_COOKIE_NAME);

        if (cookie == null || csrf.getToken() != null && !csrf.getToken().equals(cookie.getValue())) {
            cookie = new Cookie(ANGULAR_CSRF_DEFAULT_COOKIE_NAME, csrf.getToken());
            cookie.setMaxAge(-1);
            cookie.setPath(getCookiePath(request));
            cookie.setSecure(request.isSecure());
            response.addCookie(cookie);
        }
    }

    filterChain.doFilter(request, response);
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:26,代碼來源:CsrfCookieGeneratorFilter.java

示例7: csrfHeaderFilter

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的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

示例8: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@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:denis-rodionov,項目名稱:cityoffice,代碼行數:18,代碼來源:CsrfHeaderFilter.java

示例9: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(final HttpServletRequest request,
                                final HttpServletResponse response,
                                final FilterChain filterChain)
        throws ServletException, IOException {

    final CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());

    if (csrf != null) {
        final String token = csrf.getToken();
        final Cookie existingCookie = WebUtils.getCookie(request, COOKIE_NAME);

        if (existingCookie == null || !token.equals(existingCookie.getValue())) {
            // `path`   = while it doesn't provide any added security, set to context path to be consistent with `JSESSIONID` cookie
            // `secure` = cookie to only be transmitted over secure protocol as https
            // `maxAge` = expire the cookie after 8 hours
            final Cookie cookie = new Cookie(COOKIE_NAME, token);
            cookie.setPath(request.getContextPath());
            cookie.setSecure(true);
            cookie.setMaxAge(60 * 60 * 8);
            response.addCookie(cookie);
        }
    }

    filterChain.doFilter(request, response);
}
 
開發者ID:choonchernlim,項目名稱:spring-security-adfs-saml2,代碼行數:27,代碼來源:CsrfHeaderFilter.java

示例10: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    
	
	// Spring put the CSRF token in session attribute "_csrf"
    CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf");

    // Send the cookie only if the token has changed
    String actualToken = request.getHeader("X-CSRF-TOKEN");
    if (actualToken == null || !actualToken.equals(csrfToken.getToken())) {
        // Session cookie that will be used by AngularJS
        String pCookieName = "CSRF-TOKEN";
        Cookie cookie = new Cookie(pCookieName, csrfToken.getToken());
        cookie.setMaxAge(-1);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        response.addCookie(cookie);
    }
    
	response.addHeader("Access-Control-Allow-Origin", "*");
	response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
	response.setHeader("Access-Control-Max-Age", "86400"); // 24 Hours
	response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, x-auth-token");
    
    filterChain.doFilter(request, response);
}
 
開發者ID:arhs-cube-gameofcode,項目名稱:gameofcode,代碼行數:27,代碼來源:CsrfCookieGeneratorFilter.java

示例11: csrfHeaderFilter

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的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

示例12: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@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:giaunv,項目名稱:sso-oauth2-angularjs-spring-java,代碼行數:18,代碼來源:CsrfHeaderFilter.java

示例13: csrfHeaderFilter

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的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

示例14: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@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:dick-the-deployer,項目名稱:dick,代碼行數:18,代碼來源:BasicSecurityAutoConfiguration.java

示例15: doFilterInternal

import org.springframework.security.web.csrf.CsrfToken; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    // Spring put the CSRF token in session attribute "_csrf"
    CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf");
    log.trace(csrfToken.getToken());
    // Send the cookie only if the token has changed
    String actualToken = request.getHeader("X-CSRF-TOKEN");
    if (actualToken == null || !actualToken.equals(csrfToken.getToken())) {
        // Session cookie that will be used by AngularJS
        String pCookieName = "CSRF-TOKEN";
        Cookie cookie = new Cookie(pCookieName, csrfToken.getToken());
        cookie.setMaxAge(-1);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        response.addCookie(cookie);
    }
    response.addHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "86400"); // 24 Hours
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, api-key, Accept, x-auth-token, X-CSRF-TOKEN");
    
    
    
    filterChain.doFilter(request, response);
}
 
開發者ID:TransparencyInternationalEU,項目名稱:lobbycal,代碼行數:26,代碼來源:CsrfCookieGeneratorFilter.java


注:本文中的org.springframework.security.web.csrf.CsrfToken.getToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。