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


Java Cookie.setHttpOnly方法代码示例

本文整理汇总了Java中javax.servlet.http.Cookie.setHttpOnly方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.setHttpOnly方法的具体用法?Java Cookie.setHttpOnly怎么用?Java Cookie.setHttpOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.Cookie的用法示例。


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

示例1: doFilterInternal

import javax.servlet.http.Cookie; //导入方法依赖的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: createCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private Cookie createCookie(
        String sessionCookieName,
        String value) {
    Cookie cookie = new Cookie(sessionCookieName, value);
    cookie.setPath(getServletContext().getContextPath() + "/");
    if (applicationCookieDomain != null && !applicationCookieDomain.isEmpty()) {
        cookie.setDomain(applicationCookieDomain);
    }
    if (sessionTransferredOverHttpsOnly != null) {
        cookie.setSecure(sessionTransferredOverHttpsOnly);
    }
    if (sessionHttpOnly != null) {
        cookie.setHttpOnly(sessionHttpOnly);
    }
    return cookie;
}
 
开发者ID:onepiecex,项目名称:session-share,代码行数:17,代码来源:SessionImpl.java

示例3: addCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Adds the cookie, taking into account {@link RememberMeCredential#REQUEST_PARAMETER_REMEMBER_ME}
 * in the request.
 *
 * @param request the request
 * @param response the response
 * @param cookieValue the cookie value
 */
public void addCookie(final HttpServletRequest request, final HttpServletResponse response, final String cookieValue) {
    final String theCookieValue = this.casCookieValueManager.buildCookieValue(cookieValue, request);

    if (!StringUtils.hasText(request.getParameter(RememberMeCredential.REQUEST_PARAMETER_REMEMBER_ME))) {
        super.addCookie(response, theCookieValue);
    } else {
        final Cookie cookie = createCookie(theCookieValue);
        cookie.setMaxAge(this.rememberMeMaxAge);
        if (isCookieSecure()) {
            cookie.setSecure(true);
        }
        if (isCookieHttpOnly()) {
            final Method setHttpOnlyMethod = ReflectionUtils.findMethod(Cookie.class, "setHttpOnly", boolean.class);
            if(setHttpOnlyMethod != null) {
                cookie.setHttpOnly(true);
            } else {
                logger.debug("Cookie cannot be marked as HttpOnly; container is not using servlet 3.0.");
            }
        }
        response.addCookie(cookie);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:31,代码来源:CookieRetrievingCookieGenerator.java

示例4: removeCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private void removeCookie(J2EContext context) {
	Cookie cookie = new Cookie(ticketGrantingTicketCookieGenerator.getCookieName(), null); // Not necessary, but saves bandwidth.
	cookie.setPath(ticketGrantingTicketCookieGenerator.getCookiePath());
	cookie.setHttpOnly(true);
	cookie.setSecure(true);
	cookie.setMaxAge(0);
	context.getResponse().addCookie(cookie);
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:9,代码来源:OAuth20AuthorizeEndpointController.java

示例5: addCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Add a cookie with the given value to the response,
 * using the cookie descriptor settings of this generator.
 * <p>Delegates to {@link #createCookie} for cookie creation.
 * @param response the HTTP response to add the cookie to
 * @param cookieValue the value of the cookie to add
 * @see #setCookieName
 * @see #setCookieDomain
 * @see #setCookiePath
 * @see #setCookieMaxAge
 */
public void addCookie(HttpServletResponse response, String cookieValue) {
	Assert.notNull(response, "HttpServletResponse must not be null");
	Cookie cookie = createCookie(cookieValue);
	Integer maxAge = getCookieMaxAge();
	if (maxAge != null) {
		cookie.setMaxAge(maxAge);
	}
	if (isCookieSecure()) {
		cookie.setSecure(true);
	}
	if (isCookieHttpOnly()) {
		cookie.setHttpOnly(true);
	}
	response.addCookie(cookie);
	if (logger.isDebugEnabled()) {
		logger.debug("Added cookie with name [" + getCookieName() + "] and value [" + cookieValue + "]");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:CookieGenerator.java

示例6: onAuthenticationSuccess

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
		Authentication authentication ) throws IOException, ServletException {
	clearAuthenticationAttributes(request);
	User user = (User)authentication.getPrincipal();

	String jws = tokenHelper.generateToken( user.getUsername() );

       // Create token auth Cookie
       Cookie authCookie = new Cookie( TOKEN_COOKIE, ( jws ) );

	authCookie.setHttpOnly( true );

	authCookie.setMaxAge( EXPIRES_IN );

	authCookie.setPath( "/" );
	// Add cookie to response
	response.addCookie( authCookie );

	// JWT is also in the response
	UserTokenState userTokenState = new UserTokenState(jws, EXPIRES_IN);
	String jwtResponse = objectMapper.writeValueAsString( userTokenState );
	response.setContentType("application/json");
	response.getWriter().write( jwtResponse );

}
 
开发者ID:bfwg,项目名称:angular-spring-starter,代码行数:27,代码来源:AuthenticationSuccessHandler.java

示例7: safeCookie4

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void safeCookie4() {
    boolean safe = true;
    Cookie cookie = new Cookie("test1","1234");
    cookie.setHttpOnly(false);
    cookie.setSecure(safe);
    cookie.setHttpOnly(false);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:8,代码来源:InsecureCookieSamples.java

示例8: clear

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static void clear(HttpServletResponse httpServletResponse, String name) {
    Cookie cookie = new Cookie(name, null);
    cookie.setPath("/");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(0);
    cookie.setDomain("localhost");
    httpServletResponse.addCookie(cookie);
}
 
开发者ID:hellokoding,项目名称:single-sign-on-out-auth-jwt-cookie-redis-springboot-freemarker,代码行数:9,代码来源:CookieUtil.java

示例9: index

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@RequestMapping("/")
public String index( Model model, HttpServletResponse response) {
	
	Cookie cookie = new Cookie("jwtk", "011001110202423424214234");
	cookie.setHttpOnly(true);
	response.addCookie(cookie);
	
	List<JwtkMessage> msg = jwtkMessageRepository.findAllByOrderByDateDesc();
	model.addAttribute("msg", msg);
	
	return INDEX_PAGE;
}
 
开发者ID:yrzx404,项目名称:interview-question-code,代码行数:13,代码来源:IndexContoller.java

示例10: setRawCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Sets a cookie.
 * @param name the name
 * @param value the value
 * @param req HTTP request
 * @param res HTTP response
 * @param httpOnly HTTP only flag
 * @param maxAge max age
 */
public static void setRawCookie(String name, String value, HttpServletRequest req,
		HttpServletResponse res, boolean httpOnly, int maxAge) {
	if (StringUtils.isBlank(name) || value == null || req == null || res == null) {
		return;
	}
	Cookie cookie = new Cookie(name, value);
	cookie.setHttpOnly(httpOnly);
	cookie.setMaxAge(maxAge < 0 ? Config.SESSION_TIMEOUT_SEC : maxAge);
	cookie.setPath("/");
	cookie.setSecure(req.isSecure());
	res.addCookie(cookie);
}
 
开发者ID:Erudika,项目名称:scoold,代码行数:22,代码来源:HttpUtils.java

示例11: unsafeCookie4

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void unsafeCookie4() {
    boolean unsafe = false;
    Cookie newCookie = new Cookie("test1","1234");
    newCookie.setHttpOnly(unsafe);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:6,代码来源:HttpOnlyCookieSamples.java

示例12: safeCookie2

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void safeCookie2() {
    Cookie cookie = new Cookie("test1","1234");
    cookie.setHttpOnly(CONST_TRUE);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:5,代码来源:HttpOnlyCookieSamples.java

示例13: unsafeCookie2

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void unsafeCookie2() {
    Cookie newCookie = new Cookie("test1","1234");
    newCookie.setHttpOnly(CONST_FALSE);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:5,代码来源:HttpOnlyCookieSamples.java

示例14: unsafeCookie1

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
void unsafeCookie1() {
    Cookie newCookie = new Cookie("test1","1234");
    newCookie.setHttpOnly(false);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:5,代码来源:HttpOnlyCookieSamples.java

示例15: put

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static void put(HttpServletResponse response, String key, String value) {
	Cookie cookie = new Cookie(key, value);
	cookie.setPath("/");
	cookie.setHttpOnly(true);
	response.addCookie(cookie);
}
 
开发者ID:yushijinhun,项目名称:akir,代码行数:7,代码来源:OneTimeCookie.java


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