This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push: new d79045f check all applicable session cookies when trying to find a matching global session id new 9c2c27d This closes #1223 d79045f is described below commit d79045f0e166a0ac0024ce45b6a486843224453d Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> AuthorDate: Mon Aug 16 12:54:23 2021 +0100 check all applicable session cookies when trying to find a matching global session id as by default the module only returns one non-matching requested session --- .../rest/util/MultiSessionAttributeAdapter.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java index fc02b05..f950786 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java @@ -20,6 +20,7 @@ package org.apache.brooklyn.rest.util; import com.google.common.collect.ImmutableSet; import com.google.gson.JsonObject; +import javax.servlet.http.Cookie; import org.apache.brooklyn.api.mgmt.ManagementContext; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; @@ -249,6 +250,8 @@ public class MultiSessionAttributeAdapter { if (preferredHandler != null ) { String extendedId= optionalLocalSession!=null ? optionalLocalSession.getId() : optionalRequest!=null ? optionalRequest.getRequestedSessionId() : null; + + // first use the requestedSessionId assigned by the request's session handler if (Strings.isNonBlank(extendedId)) { SessionIdManager idManager = preferredHandler.getSessionIdManager(); String id = idManager.getId(extendedId); @@ -256,6 +259,32 @@ public class MultiSessionAttributeAdapter { if (preferredSession != null && !((Session) preferredSession).getExtendedId().equals(extendedId)) ((Session) preferredSession).setIdChanged(true); } + + // now try all requested session id's, because the request's session handler is not aware of global sessions, see if any are still valid + if (preferredSession==null && optionalRequest instanceof Request) { + SessionHandler sh = ((Request) optionalRequest).getSessionHandler(); + // look at all cookies on request + if (sh.isUsingCookies()) { + Cookie[] cookies = optionalRequest.getCookies(); + if (cookies != null && cookies.length > 0) { + final String sessionCookie = sh.getSessionCookieName(sh.getSessionCookieConfig()); + for (Cookie cookie : cookies) { + if (sessionCookie.equalsIgnoreCase(cookie.getName())) { + SessionIdManager idManager = preferredHandler.getSessionIdManager(); + String requestedId = cookie.getValue(); + + String globalSessionId = idManager.getId(requestedId); + preferredSession = getSessionSafely(preferredHandler, globalSessionId); + if (preferredSession != null) { + ((Request) optionalRequest).setRequestedSessionId(requestedId); + ((Session) preferredSession).setIdChanged(true); + break; + } + } + } + } + } + } } if (log.isTraceEnabled()) { @@ -285,7 +314,7 @@ public class MultiSessionAttributeAdapter { // shouldn't come here; at minimum it should have returned the local session's handler log.warn("Unexpected failure to find a handler for "+info(optionalRequest, optionalLocalSession)); } - } else { + } else if (optionalLocalSession!=null) { log.warn("Unsupported session impl in "+info(optionalRequest, optionalLocalSession)); } return optionalLocalSession;