@Override public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException { exchange.setResponseCookie(new CookieImpl(cookieName, newValue)); }
if (c == ';') { if (cookie == null) { cookie = new CookieImpl(key, headerValue.substring(current, i)); } else { handleValue(cookie, key, headerValue.substring(current, i)); if (c == '"') { if (cookie == null) { cookie = new CookieImpl(key, headerValue.substring(current, i)); } else { handleValue(cookie, key, headerValue.substring(current, i)); if (current != headerValue.length()) { if(cookie == null) { cookie = new CookieImpl(key, headerValue.substring(current, headerValue.length())); } else { handleValue(cookie, key, headerValue.substring(current, headerValue.length()));
@Override public void start(StartContext context) throws StartException { pathHandler.clearPaths(); SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator(); pathHandler.addPrefixPath(AFFINITY_PATH, exchange -> { String resolved = exchange.getResolvedPath(); int index = resolved.lastIndexOf(AFFINITY_PATH); if(index > 0) { resolved = resolved.substring(0, index); } exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", generator.createSessionId()).setPath(resolved)); }); }
Cookie c = new CookieImpl(entry.getKey(), entry.getValue()); String domain = additional.get(DOMAIN); if (domain != null) {
private void clearSsoCookie(HttpServerExchange exchange) { exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName).setMaxAge(0).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); }
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new CookieImpl(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.exchange.getResponseCookies().putIfAbsent(name, 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 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 protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new CookieImpl(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.exchange.getResponseCookies().putIfAbsent(name, cookie); } } }
@Override public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException { exchange.setResponseCookie(new CookieImpl(cookieName, newValue)); }
/** * Attach a session cookie, identified by {@code sessionId}, into the current request. * * @param exchange * @param sessionId */ @Override public void attachSessionId(HttpServerExchange exchange, String sessionId ) { final Cookie cookie = new CookieImpl( this.cookieName, sessionId ).setPath( "/" ).setHttpOnly( true ); exchange.setResponseCookie( cookie ); }
@Override public void resetCookie(String name, String path) { CookieImpl cookie = new CookieImpl(name, ""); cookie.setMaxAge(0); cookie.setPath(path); exchange.setResponseCookie(cookie); }
@Override public void start(StartContext context) throws StartException { pathHandler.clearPaths(); SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator(); pathHandler.addPrefixPath(AFFINITY_PATH, exchange -> { String resolved = exchange.getResolvedPath(); int index = resolved.lastIndexOf(AFFINITY_PATH); if(index > 0) { resolved = resolved.substring(0, index); } exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", generator.createSessionId()).setPath(resolved)); }); }
@Override public void expiresSessionId(HttpServerExchange exchange) { final String sessionId = retrieveSessionIdFrom(exchange); final Cookie cookie = new CookieImpl( this.cookieName, sessionId ) .setPath( "/" ).setHttpOnly( true ).setExpires( Date.from( Instant.EPOCH ) ); 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 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 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); }