当前位置: 首页>>代码示例>>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;未经允许,请勿转载。