syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/2] syncope git commit: Workaround for WICKET-6588
Date Wed, 19 Sep 2018 10:21:58 GMT
Repository: syncope
Updated Branches:
  refs/heads/2_1_X 5bdfc7d63 -> 4c324a80f
  refs/heads/master aebb4460f -> d5b371fa1


Workaround for WICKET-6588


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4c324a80
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4c324a80
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4c324a80

Branch: refs/heads/2_1_X
Commit: 4c324a80f9c1bbdfdce7a8b68e0663c94907ea5e
Parents: 5bdfc7d
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Wed Sep 19 12:21:33 2018 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Wed Sep 19 12:21:33 2018 +0200

----------------------------------------------------------------------
 .../topology/TopologyWebSocketBehavior.java     | 40 ++++++++++++++++++--
 1 file changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/4c324a80/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyWebSocketBehavior.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyWebSocketBehavior.java
b/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyWebSocketBehavior.java
index 1134a00..7ad0f08 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyWebSocketBehavior.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyWebSocketBehavior.java
@@ -27,17 +27,23 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import javax.servlet.SessionTrackingMode;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.rest.ConnectorRestClient;
 import org.apache.syncope.client.console.rest.ResourceRestClient;
 import org.apache.syncope.common.lib.to.ConnInstanceTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
 import org.apache.wicket.Application;
+import org.apache.wicket.Component;
 import org.apache.wicket.Session;
 import org.apache.wicket.ThreadContext;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.ws.api.WebSocketBehavior;
 import org.apache.wicket.protocol.ws.api.WebSocketRequestHandler;
 import org.apache.wicket.protocol.ws.api.message.TextMessage;
+import org.apache.wicket.util.cookies.CookieUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,20 +56,46 @@ public class TopologyWebSocketBehavior extends WebSocketBehavior {
     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
     private final Map<String, String> resources =
-            Collections.<String, String>synchronizedMap(new HashMap<String, String>());
+            Collections.<String, String>synchronizedMap(new HashMap<>());
 
-    private final Set<String> runningResCheck = Collections.synchronizedSet(new HashSet<String>());
+    private final Set<String> runningResCheck = Collections.synchronizedSet(new HashSet<>());
 
     private final Map<String, String> connectors =
-            Collections.<String, String>synchronizedMap(new HashMap<String, String>());
+            Collections.<String, String>synchronizedMap(new HashMap<>());
 
-    private final Set<String> runningConnCheck = Collections.synchronizedSet(new HashSet<String>());
+    private final Set<String> runningConnCheck = Collections.synchronizedSet(new HashSet<>());
 
     private final ConnectorRestClient connectorRestClient = new ConnectorRestClient();
 
     private final ResourceRestClient resourceRestClient = new ResourceRestClient();
 
     @Override
+    protected CharSequence getSessionId(final Component component) {
+        String sessionId = "";
+        WebApplication application = (WebApplication) component.getApplication();
+        Set<SessionTrackingMode> effectiveSessionTrackingModes =
+                application.getServletContext().getEffectiveSessionTrackingModes();
+        Object containerRequest = component.getRequest().getContainerRequest();
+        if (effectiveSessionTrackingModes.size() == 1
+                && SessionTrackingMode.URL.equals(effectiveSessionTrackingModes.iterator().next()))
{
+
+            sessionId = component.getSession().getId();
+        } else if (containerRequest instanceof HttpServletRequest) {
+            CookieUtils cookieUtils = new CookieUtils();
+            String jsessionCookieName = application.getServletContext().getSessionCookieConfig().getName();
+            if (jsessionCookieName == null) {
+                jsessionCookieName = "JSESSIONID";
+            }
+            Cookie jsessionid = cookieUtils.getCookie(jsessionCookieName);
+            HttpServletRequest httpServletRequest = (HttpServletRequest) containerRequest;
+            if (jsessionid == null || httpServletRequest.isRequestedSessionIdValid() == false)
{
+                sessionId = component.getSession().getId();
+            }
+        }
+        return sessionId;
+    }
+
+    @Override
     protected void onMessage(final WebSocketRequestHandler handler, final TextMessage message)
{
         try {
             JsonNode obj = OBJECT_MAPPER.readTree(message.getText());


Mime
View raw message