]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/SimpleSessionProvider.java
Update license headers
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jackrabbit / src / main / java / org / argeo / jackrabbit / remote / SimpleSessionProvider.java
index 8e8b1d945ce22f2c7a3883d74cfc0f6673150b57..12315930b61995cca0fc48625da9e845252592b3 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.argeo.jackrabbit.remote;
 
 import java.io.Serializable;
@@ -29,8 +44,8 @@ import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.JcrUtils;
 
 /**
- * To be injected, typically of scope="session". Implements an open session in
- * view patter: a new JCR session is created for each request
+ * Implements an open session in view patter: a new JCR session is created for
+ * each request
  */
 public class SimpleSessionProvider implements SessionProvider, Serializable {
        private static final long serialVersionUID = 2270957712453841368L;
@@ -42,6 +57,8 @@ public class SimpleSessionProvider implements SessionProvider, Serializable {
 
        private Boolean openSessionInView = true;
 
+       private String securityWorkspace = "security";
+
        public Session getSession(HttpServletRequest request, Repository rep,
                        String workspace) throws LoginException, ServletException,
                        RepositoryException {
@@ -49,7 +66,8 @@ public class SimpleSessionProvider implements SessionProvider, Serializable {
                if (openSessionInView) {
                        JackrabbitSession session = (JackrabbitSession) rep
                                        .login(workspace);
-                       writeRemoteRoles(session);
+                       if (session.getWorkspace().getName().equals(securityWorkspace))
+                               writeRemoteRoles(session);
                        return session;
                } else {
                        // since sessions is transient it can't be restored from the session
@@ -61,7 +79,9 @@ public class SimpleSessionProvider implements SessionProvider, Serializable {
                                try {
                                        JackrabbitSession session = (JackrabbitSession) rep.login(
                                                        null, workspace);
-                                       writeRemoteRoles(session);
+                                       if (session.getWorkspace().getName()
+                                                       .equals(securityWorkspace))
+                                               writeRemoteRoles(session);
                                        if (log.isTraceEnabled())
                                                log.trace("User " + session.getUserID()
                                                                + " logged into " + request.getServletPath());
@@ -98,7 +118,8 @@ public class SimpleSessionProvider implements SessionProvider, Serializable {
                                userGroupIds.add(it.next().getID());
 
                // write roles if needed
-               Node userProfile = JcrUtils.getUserProfile(session);
+               Node userProfile = JcrUtils.getUserHome(session).getNode(
+                               ArgeoNames.ARGEO_PROFILE);
                boolean writeRoles = false;
                if (userProfile.hasProperty(ArgeoNames.ARGEO_REMOTE_ROLES)) {
                        Value[] roles = userProfile.getProperty(
@@ -141,7 +162,7 @@ public class SimpleSessionProvider implements SessionProvider, Serializable {
        public void init() {
        }
 
-       public void dispose() {
+       public void destroy() {
                if (sessions != null)
                        for (String workspace : sessions.keySet()) {
                                Session session = sessions.get(workspace);
@@ -152,4 +173,18 @@ public class SimpleSessionProvider implements SessionProvider, Serializable {
                                }
                        }
        }
+
+       /**
+        * If set to true a new session will be created each time (the default),
+        * otherwise a single session is cached by workspace and the object should
+        * be of scope session (not supported)
+        */
+       public void setOpenSessionInView(Boolean openSessionInView) {
+               this.openSessionInView = openSessionInView;
+       }
+
+       public void setSecurityWorkspace(String securityWorkspace) {
+               this.securityWorkspace = securityWorkspace;
+       }
+
 }