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


Java Cookie.setMaxAge方法代码示例

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


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

示例1: build

import io.undertow.server.handlers.Cookie; //导入方法依赖的package包/类
public Cookie build() {
    Cookie cookie = new CookieImpl(this.cookieName)
            .setValue(this.cookieValue)
            .setDiscard(this.cookieDiscard)
            .setSecure(this.cookieSecure)
            .setHttpOnly(this.cookieHttpOnly)
            .setPath(this.cookiePath)
            .setExpires((this.cookieExpires == null) ?
                    Date.from(LocalDateTime.now().plusDays(1).atZone(ZoneId.systemDefault()).toInstant()) :
                    Date.from(this.cookieExpires.atZone(ZoneId.systemDefault()).toInstant()));

    if (this.cookieDomain != null) {
        cookie.setDomain(this.cookieDomain);
    }

    if (this.cookieMaxAge != null) {
        cookie.setMaxAge(this.cookieMaxAge);
    }

    return cookie;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:22,代码来源:CookieBuilder.java

示例2: setSessionId

import io.undertow.server.handlers.Cookie; //导入方法依赖的package包/类
@Override
public void setSessionId(final HttpServerExchange exchange, final String sessionId) {
    Cookie cookie = new CookieImpl(cookieName, sessionId)
            .setPath(path)
            .setDomain(domain)
            .setDiscard(discard)
            .setSecure(secure)
            .setHttpOnly(httpOnly)
            .setComment(comment);
    if (maxAge > 0) {
        cookie.setMaxAge(maxAge);
    }
    exchange.setResponseCookie(cookie);
    exchange.getRequestCookies().put(cookieName, cookie);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:SessionCookieConfig.java

示例3: setAuthenticationCookie

import io.undertow.server.handlers.Cookie; //导入方法依赖的package包/类
/**
 * Sets the authentication cookie to the current HttpServerExchange
 *
 * @param exchange The Undertow HttpServerExchange
 */
protected void setAuthenticationCookie(HttpServerExchange exchange) {
    Authentication authentication = this.attachment.getAuthentication();
    
    if (authentication != null && authentication.hasAuthenticatedUser()) {
        Cookie cookie;
        final String cookieName = this.config.getAuthenticationCookieName();
        if (authentication.isLogout()) {
            cookie = exchange.getRequestCookies().get(cookieName);
            cookie.setSecure(this.config.isAuthenticationCookieSecure());
            cookie.setHttpOnly(true);
            cookie.setPath("/");
            cookie.setMaxAge(0);
            cookie.setDiscard(true);
        } else {
            Map<String, Object> claims = new HashMap<>();
            claims.put(ClaimKey.VERSION.toString(), this.config.getAuthenticationCookieVersion());
            claims.put(ClaimKey.TWO_FACTOR.toString(), authentication.isTwoFactor());
            
            final LocalDateTime expires = authentication.isRememberMe() ? LocalDateTime.now().plusHours(this.config.getAuthenticationRememberExpires()) : authentication.getExpires();
            String jwt = Jwts.builder()
                    .setClaims(claims)
                    .setSubject(authentication.getAuthenticatedUser())
                    .setExpiration(DateUtils.localDateTimeToDate(expires))
                    .signWith(SignatureAlgorithm.HS512, this.config.getApplicationSecret())
                    .compact();
            
            if (this.config.isAuthenticationCookieEncrypt()) {
                jwt = this.attachment.getCrypto().encrypt(jwt);
            }

            cookie = CookieBuilder.create()
                    .name(cookieName)
                    .value(jwt)
                    .secure(this.config.isAuthenticationCookieSecure())
                    .httpOnly(true)
                    .expires(expires)
                    .build();
        }

        exchange.setResponseCookie(cookie);
    }
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:48,代码来源:OutboundCookiesHandler.java


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