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


Java WebUtils.getCookie方法代碼示例

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


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

示例1: csrfHeaderFilter

import org.springframework.web.util.WebUtils; //導入方法依賴的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.util.WebUtils; //導入方法依賴的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: parseLocaleCookieIfNecessary

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = (!"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null);
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            (locale != null ? locale: determineDefaultLocale(request)));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:36,代碼來源:AngularCookieLocaleResolver.java

示例4: parseLocaleCookieIfNecessary

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = !"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null;
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            locale != null ? locale: determineDefaultLocale(request));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            timeZone != null ? timeZone : determineDefaultTimeZone(request));
    }
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:36,代碼來源:AngularCookieLocaleResolver.java

示例5: findSession

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
/**
 * 查詢創建的cookie
 * @param request
 * @return
 */
@RequestMapping(value = "/find", method = RequestMethod.GET)
@ResponseBody
public PrevalentMessage findSession(HttpServletRequest request) {

    Cookie cookie = WebUtils.getCookie(request, "token");

    return new PrevalentMessage(cookie.getValue());
}
 
開發者ID:lordking,項目名稱:spring-rest-sample,代碼行數:14,代碼來源:CrossDomainSessionController.java

示例6: csrfHeaderFilter

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

示例7: csrfHeaderFilter

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

示例8: csrfHeaderFilter

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

示例9: resolveThemeName

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
@Override
public String resolveThemeName(HttpServletRequest request) {
	// Check request for preparsed or preset theme.
	String themeName = (String) request.getAttribute(THEME_REQUEST_ATTRIBUTE_NAME);
	if (themeName != null) {
		return themeName;
	}

	// Retrieve cookie value from request.
	Cookie cookie = WebUtils.getCookie(request, getCookieName());
	if (cookie != null) {
		String value = cookie.getValue();
		if (StringUtils.hasText(value)) {
			themeName = value;
		}
	}

	// Fall back to default theme.
	if (themeName == null) {
		themeName = getDefaultThemeName();
	}
	request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName);
	return themeName;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:CookieThemeResolver.java

示例10: doFilterInternal

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

示例11: doFilterInternal

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

示例12: loadToken

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
@Override
public CsrfTokenBean loadToken(HttpServletRequest request) {
	Cookie cookie = WebUtils.getCookie(request, this.cookieName);
	if (cookie == null) {
		return null;
	}
	String token = cookie.getValue();
	if (!StringUtils.hasLength(token)) {
		return null;
	}
	return new CsrfTokenBean(this.headerName, this.parameterName, token);
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:13,代碼來源:CookieCsrfTokenRepository.java

示例13: callback

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
/**
 * 跨域查詢創建的cookie
 * @param request
 * @return
 */
@RequestMapping(value ="/get", produces =MediaType.APPLICATION_JSON_VALUE )
@ResponseBody
public PrevalentMessage callback(HttpServletRequest request) {

    Cookie cookie = WebUtils.getCookie(request, "token");

    return new PrevalentMessage(cookie.getValue());
}
 
開發者ID:lordking,項目名稱:spring-rest-sample,代碼行數:14,代碼來源:CrossDomainSessionController.java

示例14: parseLocaleCookieIfNecessary

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, QUOTE, "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = !"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null;
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            locale != null ? locale : determineDefaultLocale(request));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            timeZone != null ? timeZone : determineDefaultTimeZone(request));
    }
}
 
開發者ID:jhipster,項目名稱:jhipster,代碼行數:36,代碼來源:AngularCookieLocaleResolver.java

示例15: parseLocaleCookieIfNecessary

import org.springframework.web.util.WebUtils; //導入方法依賴的package包/類
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = (!"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null);
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            (locale != null ? locale : determineDefaultLocale(request)));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
}
 
開發者ID:k8s-for-greeks,項目名稱:gpmr,代碼行數:36,代碼來源:AngularCookieLocaleResolver.java


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