public void dissolve() { if (!shouldWriteLocaleCookie()) { return; } String cookieName = config.localeCookieName(); Locale locale = context.locale(); if (null == locale) { locale = this.locale; } String localeStr = locale.toString(); H.Session session = context.session(); if (null != session) { if (reset) { session.remove(KEY); } else { session.put(KEY, localeStr); } } H.Cookie cookie = new H.Cookie(cookieName, localeStr); cookie.domain(config.cookieDomain()); cookie.path("/"); // in case we have resolved locale from cookie and we shouldn't write cookie anymore, we need to clear it cookie.maxAge(reset ? -1 : COOKIE_TTL); if (reset) { cookie.expires(DateTime.now().minusDays(1).toDate()); } context.resp().addCookie(cookie); }
@Override public void addCookie(H.Cookie cookie) { realResponse.addCookie(cookie); cookies.put(cookie.name(), cookie); }
public void dissolve() { if (!shouldWriteLocaleCookie()) { return; } String cookieName = config.localeCookieName(); Locale locale = context.locale(); if (null == locale) { locale = this.locale; } String localeStr = locale.toString(); H.Session session = context.session(); if (null != session) { if (reset) { session.remove(KEY); } else { session.put(KEY, localeStr); } } H.Cookie cookie = new H.Cookie(cookieName, localeStr); cookie.domain(config.cookieDomain()); cookie.path("/"); // in case we have resolved locale from cookie and we shouldn't write cookie anymore, we need to clear it cookie.maxAge(reset ? -1 : COOKIE_TTL); if (reset) { cookie.expires(DateTime.now().minusDays(1).toDate()); } context.resp().addCookie(cookie); }
public void setCookieAndRenderArgs(ActionContext context) { if (!enabled) { return; } String token = retrieveCsrfToken(context); if (S.blank(token)) { // this branch is for safe methods H.Session session = context.session(); token = csrfProtector.retrieveToken(session, cookieName, app); } if (S.blank(token) || justLoggedIn(context)) { H.Session session = context.session(); csrfProtector.clearExistingToken(session, cookieName); token = app.encrypt(csrfProtector.generateToken(session, app)); H.Cookie cookie = new H.Cookie(cookieName, token); cookie.secure(context.config().sessionSecure()); cookie.domain(cookieDomain); cookie.path("/"); cookie.httpOnly(false); context.resp().addCookie(cookie); csrfProtector.outputToken(token, cookieName, cookieDomain, context); } context.renderArg(paramName, token); }
public void setCookieAndRenderArgs(ActionContext context) { if (!enabled) { return; } String token = retrieveCsrfToken(context); if (S.blank(token)) { // this branch is for safe methods H.Session session = context.session(); token = csrfProtector.retrieveToken(session, cookieName, app); } if (S.blank(token) || justLoggedIn(context)) { H.Session session = context.session(); csrfProtector.clearExistingToken(session, cookieName); token = app.encrypt(csrfProtector.generateToken(session, app)); H.Cookie cookie = new H.Cookie(cookieName, token); cookie.secure(context.config().sessionSecure()); cookie.domain(cookieDomain); cookie.path("/"); cookie.httpOnly(false); context.resp().addCookie(cookie); csrfProtector.outputToken(token, cookieName, cookieDomain, context); } context.renderArg(paramName, token); }
@Override public String getDomain() { return hc.domain(); }
@Override public String getPath() { return hc.path(); }
@Override public String getValue() { return hc.value(); }
@Override public boolean isDiscard() { return hc.maxAge() < 0; }
@Override public void serializeSession(H.Cookie sessionCookie, ActionContext context) { context.resp().header(sessionHeaderName(), sessionCookie.value()); }
@Override public Date getExpires() { return hc.expires(); }
@Override public String getName() { return hc.name(); }
@Override public void serializeFlash(H.Cookie flashCookie, ActionContext context) { context.resp().header(flashHeaderName(), flashCookie.value()); }
@Override public boolean isHttpOnly() { return hc.httpOnly(); }
@Override public Integer getMaxAge() { return hc.maxAge(); }
private String readState(String cookieName, H.Request request) { H.Cookie cookie = request.cookie(cookieName); return null == cookie ? null : cookie.value(); }
@Override public boolean isSecure() { return hc.secure(); }
public static H.Cookie undertow2osgl(Cookie uc) { H.Cookie c = new H.Cookie(uc.getName(), uc.getValue()); c.domain(uc.getDomain()).httpOnly(uc.isHttpOnly()) .path(uc.getPath()).secure(uc.isSecure()) .version(uc.getVersion()).comment(uc.getComment()); Integer maxAge = uc.getMaxAge(); if (null != maxAge) { c.maxAge(maxAge); } Date exp = uc.getExpires(); if (null != exp) { c.expires(exp); } return c; }
@Override public String getDomain() { return hc.domain(); }
@Override public Cookie setDomain(String domain) { hc.domain(domain); return this; }