private static void handleValue(CookieImpl cookie, String key, String value) { if (key.equalsIgnoreCase("path")) { cookie.setPath(value); } else if (key.equalsIgnoreCase("domain")) { cookie.setDomain(value); } else if (key.equalsIgnoreCase("max-age")) { cookie.setMaxAge(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("expires")) { cookie.setExpires(DateUtils.parseDate(value)); } else if (key.equalsIgnoreCase("discard")) { cookie.setDiscard(true); } else if (key.equalsIgnoreCase("secure")) { cookie.setSecure(true); } else if (key.equalsIgnoreCase("httpOnly")) { cookie.setHttpOnly(true); } else if (key.equalsIgnoreCase("version")) { cookie.setVersion(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("comment")) { cookie.setComment(value); } else if (key.equalsIgnoreCase("samesite")) { cookie.setSameSite(true); cookie.setSameSiteMode(value); } //otherwise ignore this key-value pair }
private void clearSsoCookie(HttpServerExchange exchange) { exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName).setMaxAge(0).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); }
@Override public void clearSession(final HttpServerExchange exchange, final String sessionId) { Cookie cookie = new CookieImpl(cookieName, sessionId) .setPath(path) .setDomain(domain) .setDiscard(discard) .setSecure(secure) .setHttpOnly(httpOnly) .setMaxAge(0); exchange.setResponseCookie(cookie); UndertowLogger.SESSION_LOGGER.tracef("Clearing session cookie session id %s on %s", sessionId, exchange); }
@Override public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) { SecurityContext sc = exchange.getSecurityContext(); Account account = sc.getAuthenticatedAccount(); if (account != null) { try (SingleSignOn sso = singleSignOnManager.createSingleSignOn(account, sc.getMechanismName())) { Session session = getSession(exchange); registerSessionIfRequired(sso, session); exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName, sso.getId()).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); } } return factory.create(); } }
@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); UndertowLogger.SESSION_LOGGER.tracef("Setting session cookie session id %s on %s", sessionId, exchange); }
private static void handleValue(CookieImpl cookie, String key, String value) { if (key.equalsIgnoreCase("path")) { cookie.setPath(value); } else if (key.equalsIgnoreCase("domain")) { cookie.setDomain(value); } else if (key.equalsIgnoreCase("max-age")) { cookie.setMaxAge(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("expires")) { cookie.setExpires(DateUtils.parseDate(value)); } else if (key.equalsIgnoreCase("discard")) { cookie.setDiscard(true); } else if (key.equalsIgnoreCase("secure")) { cookie.setSecure(true); } else if (key.equalsIgnoreCase("httpOnly")) { cookie.setHttpOnly(true); } else if (key.equalsIgnoreCase("version")) { cookie.setVersion(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("comment")) { cookie.setComment(value); } else if (key.equalsIgnoreCase("samesite")) { cookie.setSameSite(true); cookie.setSameSiteMode(value); } //otherwise ignore this key-value pair }
private static void handleValue(CookieImpl cookie, String key, String value) { if (key.equalsIgnoreCase("path")) { cookie.setPath(value); } else if (key.equalsIgnoreCase("domain")) { cookie.setDomain(value); } else if (key.equalsIgnoreCase("max-age")) { cookie.setMaxAge(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("expires")) { cookie.setExpires(DateUtils.parseDate(value)); } else if (key.equalsIgnoreCase("discard")) { cookie.setDiscard(true); } else if (key.equalsIgnoreCase("secure")) { cookie.setSecure(true); } else if (key.equalsIgnoreCase("httpOnly")) { cookie.setHttpOnly(true); } else if (key.equalsIgnoreCase("version")) { cookie.setVersion(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("comment")) { cookie.setComment(value); } else if (key.equalsIgnoreCase("samesite")) { cookie.setSameSite(true); cookie.setSameSiteMode(value); } //otherwise ignore this key-value pair }
private void clearSsoCookie(HttpServerExchange exchange) { exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName).setMaxAge(0).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); }
private void clearSsoCookie(HttpServerExchange exchange) { exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName).setMaxAge(0).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); }
@Override public void setCookie(String name, String value, String path, String domain, int maxAge, boolean secure, boolean httpOnly) { CookieImpl cookie = new CookieImpl(name, value); cookie.setPath(path); cookie.setDomain(domain); cookie.setMaxAge(maxAge); cookie.setSecure(secure); cookie.setHttpOnly(httpOnly); exchange.setResponseCookie(cookie); }
@Override public void setCookie(String name, String value, String path, String domain, int maxAge, boolean secure, boolean httpOnly) { CookieImpl cookie = new CookieImpl(name, value); cookie.setPath(path); cookie.setDomain(domain); cookie.setMaxAge(maxAge); cookie.setSecure(secure); cookie.setHttpOnly(httpOnly); exchange.setResponseCookie(cookie); }
@Override public void clearSession(final HttpServerExchange exchange, final String sessionId) { Cookie cookie = new CookieImpl(cookieName, sessionId) .setPath(path) .setDomain(domain) .setDiscard(discard) .setSecure(secure) .setHttpOnly(httpOnly) .setMaxAge(0); exchange.setResponseCookie(cookie); UndertowLogger.SESSION_LOGGER.tracef("Clearing session cookie session id %s on %s", sessionId, exchange); }
@Override public void clearSession(final HttpServerExchange exchange, final String sessionId) { Cookie cookie = new CookieImpl(cookieName, sessionId) .setPath(path) .setDomain(domain) .setDiscard(discard) .setSecure(secure) .setHttpOnly(httpOnly) .setMaxAge(0); exchange.setResponseCookie(cookie); UndertowLogger.SESSION_LOGGER.tracef("Clearing session cookie session id %s on %s", sessionId, exchange); }
@Override public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) { SecurityContext sc = exchange.getSecurityContext(); Account account = sc.getAuthenticatedAccount(); if (account != null) { try (SingleSignOn sso = singleSignOnManager.createSingleSignOn(account, sc.getMechanismName())) { Session session = getSession(exchange); registerSessionIfRequired(sso, session); exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName, sso.getId()).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); } } return factory.create(); } }
@Override public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) { SecurityContext sc = exchange.getSecurityContext(); Account account = sc.getAuthenticatedAccount(); if (account != null) { try (SingleSignOn sso = singleSignOnManager.createSingleSignOn(account, sc.getMechanismName())) { Session session = getSession(exchange); registerSessionIfRequired(sso, session); exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName, sso.getId()).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); } } return factory.create(); } }
@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); UndertowLogger.SESSION_LOGGER.tracef("Setting session cookie session id %s on %s", sessionId, exchange); }
@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); UndertowLogger.SESSION_LOGGER.tracef("Setting session cookie session id %s on %s", sessionId, exchange); }
@Override public void addResponseCookie(final Cookie cookie) { final CookieImpl newCookie = new CookieImpl(cookie.getName(), cookie.getValue()); newCookie.setComment(cookie.getComment()); newCookie.setDomain(cookie.getDomain()); newCookie.setPath(cookie.getPath()); newCookie.setMaxAge(cookie.getMaxAge() < 0 ? null : cookie.getMaxAge()); newCookie.setSecure(cookie.isSecure()); newCookie.setHttpOnly(cookie.isHttpOnly()); exchange.setResponseCookie(newCookie); }