@Override protected MultiValueMap<String, HttpCookie> initCookies() { MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>(); for (String name : this.exchange.getRequestCookies().keySet()) { Cookie cookie = this.exchange.getRequestCookies().get(name); HttpCookie httpCookie = new HttpCookie(name, cookie.getValue()); cookies.add(name, httpCookie); } return cookies; }
@Override public String readAttribute(final HttpServerExchange exchange) { Cookie cookie = exchange.getRequestCookies().get(cookieName); if (cookie == null) { return null; } return cookie.getValue(); }
private String getSession(HttpServerExchange exchange) { for(String header : sessionCookieNames) { Cookie cookie = exchange.getRequestCookies().get(header); if(cookie != null) { return cookie.getValue(); } } return null; }
protected Host findStickyHost(HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getRequestCookies(); for (String cookieName : sessionCookieNames) { Cookie sk = cookies.get(cookieName); if (sk != null) { int index = sk.getValue().indexOf('.'); if (index == -1) { continue; } String route = sk.getValue().substring(index + 1); index = route.indexOf('.'); if (index != -1) { route = route.substring(0, index); } return routes.get(route); } } return null; }
@Override protected MultiValueMap<String, HttpCookie> initCookies() { MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>(); for (String name : this.exchange.getRequestCookies().keySet()) { Cookie cookie = this.exchange.getRequestCookies().get(name); HttpCookie httpCookie = new HttpCookie(name, cookie.getValue()); cookies.add(name, httpCookie); } return cookies; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { Cookie sessionId = exchange.getRequestCookies().get(sessionCookieName); if (sessionId != null) { int part = sessionId.getValue().indexOf('.'); if (part != -1) { sessionId.setValue(sessionId.getValue().substring(0, part)); } } exchange.addResponseWrapper(wrapper); next.handleRequest(exchange); }
@Override public String findSessionId(final HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getRequestCookies(); if (cookies != null) { Cookie sessionId = cookies.get(cookieName); if (sessionId != null) { UndertowLogger.SESSION_LOGGER.tracef("Found session cookie session id %s on %s", sessionId, exchange); return sessionId.getValue(); } } return null; }
@Override public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getResponseCookiesInternal(); if (cookies != null) { Cookie sessionId = cookies.get(sessionCookieName); if (sessionId != null) { StringBuilder sb = new StringBuilder(sessionId.getValue()); sb.append('.'); sb.append(jvmRoute); sessionId.setValue(sb.toString()); } } return factory.create(); } }
/** * put cookies info to cookieMap * @param cookiesMap Map of cookies */ private void dumpCookies(Map<String, Cookie> cookiesMap, String maskKey) { cookiesMap.forEach((key, cookie) -> { if(!config.getRequestFilteredCookies().contains(cookie.getName())) { List<Map<String, String>> cookieInfoList = new ArrayList<>(); //mask cookieValue String cookieValue = config.isMaskEnabled() ? Mask.maskRegex(cookie.getValue(), maskKey, cookie.getName()) : cookie.getValue(); cookieInfoList.add(new HashMap<String, String>(){{put(DumpConstants.COOKIE_VALUE, cookieValue);}}); cookieInfoList.add(new HashMap<String, String>(){{put(DumpConstants.COOKIE_DOMAIN, cookie.getDomain());}}); cookieInfoList.add(new HashMap<String, String>(){{put(DumpConstants.COOKIE_PATH, cookie.getPath());}}); cookieInfoList.add(new HashMap<String, String>(){{put(DumpConstants.COOKIE_EXPIRES, cookie.getExpires() == null ? "" : cookie.getExpires().toString());}}); this.cookieMap.put(key, cookieInfoList); } }); }
private static Cookie cookie(final io.undertow.server.handlers.Cookie c) { Cookie.Definition cookie = new Cookie.Definition(c.getName(), c.getValue()); Optional.ofNullable(c.getComment()).ifPresent(cookie::comment); Optional.ofNullable(c.getDomain()).ifPresent(cookie::domain); Optional.ofNullable(c.getPath()).ifPresent(cookie::path); return cookie.toCookie(); }
/** * Sets a response cookie * * @param cookie The cookie */ public HttpServerExchange setResponseCookie(final Cookie cookie) { if(getConnection().getUndertowOptions().get(UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION, UndertowOptions.DEFAULT_ENABLE_RFC6265_COOKIE_VALIDATION)) { if (cookie.getValue() != null && !cookie.getValue().isEmpty()) { Rfc6265CookieSupport.validateCookieValue(cookie.getValue()); } if (cookie.getPath() != null && !cookie.getPath().isEmpty()) { Rfc6265CookieSupport.validatePath(cookie.getPath()); } if (cookie.getDomain() != null && !cookie.getDomain().isEmpty()) { Rfc6265CookieSupport.validateDomain(cookie.getDomain()); } } if (responseCookies == null) { responseCookies = new TreeMap<>(); //hashmap is slow to allocate in JDK7 } responseCookies.put(cookie.getName(), cookie); return this; }
if (cookies != null) { for (Cookie cookie : cookies.values()) { sb.append(" cookie=" + cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain() + "; path=" + cookie.getPath() + "\n");
boolean cancelIdRunning = Boolean.parseBoolean(parts[5]); Cookie cookie = exchange.getRequestCookies().get(EjbHttpService.JSESSIONID); final String sessionAffinity = cookie != null ? cookie.getValue() : null; final InvocationIdentifier identifier; if (invocationId != null && sessionAffinity != null) {
private HttpHandler setupRoutes(HttpHandler handler) { final SimpleSessionIdentifierCodec codec = new SimpleSessionIdentifierCodec(new SimpleRoutingSupport(), this.host.getValue().getServer().getRoute()); return exchange -> { exchange.addResponseCommitListener(ex -> { Cookie cookie = ex.getResponseCookies().get(JSESSIONID); if(cookie != null ) { cookie.setValue(codec.encode(cookie.getValue())); } }); handler.handleRequest(exchange); }; }
if (balancer.isStickySession()) { if (cookies.containsKey(balancer.getStickySessionCookie())) { final String session = cookies.get(balancer.getStickySessionCookie()).getValue(); final String jvmRoute = getJVMRoute(session); if (jvmRoute != null) {
Cookie cookie = exchange.getRequestCookies().get(cookieName); if (cookie != null) { final String ssoId = cookie.getValue(); log.tracef("Found SSO cookie %s", ssoId); try (SingleSignOn sso = this.singleSignOnManager.findSingleSignOn(ssoId)) {
String value = cookie.getValue(); String path = cookie.getPath(); String domain = cookie.getDomain();