本文整理汇总了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;
}
示例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);
}
示例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);
}
}