jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r948866 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ test/java/org/apache/jackrabbit/core/
Date Thu, 27 May 2010 15:48:01 GMT
Author: jukka
Date: Thu May 27 15:48:00 2010
New Revision: 948866

URL: http://svn.apache.org/viewvc?rev=948866&view=rev
Log:
JCR-2640: Internal repository context

Use the RepositoryContext to track the JackrabbitSecurityManager instance.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/UserPerWorkspaceSecurityManagerTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java?rev=948866&r1=948865&r2=948866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
Thu May 27 15:48:00 2010
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.core.data.D
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.security.JackrabbitSecurityManager;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 
 /**
@@ -78,6 +79,11 @@ public class RepositoryContext {
     private WorkspaceManager workspaceManager;
 
     /**
+     * Security manager of this repository;
+     */
+    private JackrabbitSecurityManager securityManager;
+
+    /**
      * Creates a component context for the given repository.
      *
      * @param repository repository instance
@@ -192,7 +198,7 @@ public class RepositoryContext {
      *
      * @param fileSystem repository file system
      */
-    public void setFileSystem(FileSystem fileSystem) {
+    void setFileSystem(FileSystem fileSystem) {
         assert fileSystem != null;
         this.fileSystem = fileSystem;
     }
@@ -212,7 +218,7 @@ public class RepositoryContext {
      *
      * @param dataStore data store
      */
-    public void setDataStore(DataStore dataStore) {
+    void setDataStore(DataStore dataStore) {
         assert dataStore != null;
         this.dataStore = dataStore;
     }
@@ -232,7 +238,7 @@ public class RepositoryContext {
      *
      * @param clusterNode cluster node
      */
-    public void setClusterNode(ClusterNode clusterNode) {
+    void setClusterNode(ClusterNode clusterNode) {
         assert clusterNode != null;
         this.clusterNode = clusterNode;
     }
@@ -252,9 +258,29 @@ public class RepositoryContext {
      *
      * @param workspaceManager workspace manager
      */
-    public void setWorkspaceManager(WorkspaceManager workspaceManager) {
+    void setWorkspaceManager(WorkspaceManager workspaceManager) {
         assert workspaceManager != null;
         this.workspaceManager = workspaceManager;
     }
 
+    /**
+     * Returns the security manager of this repository.
+     *
+     * @return security manager
+     */
+    public JackrabbitSecurityManager getSecurityManager() {
+        assert securityManager != null;
+        return securityManager;
+    }
+
+    /**
+     * Sets the security manager of this repository.
+     *
+     * @param securityManager security manager
+     */
+    void setSecurityManager(JackrabbitSecurityManager securityManager) {
+        assert securityManager != null;
+        this.securityManager = securityManager;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=948866&r1=948865&r2=948866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Thu May 27 15:48:00 2010
@@ -347,6 +347,9 @@ public class RepositoryImpl extends Abst
             // initialize system search manager
             getSystemSearchManager(repConfig.getDefaultWorkspaceName());
 
+            // Initialise the security manager;
+            context.setSecurityManager(createSecurityManager());
+            
             // after the workspace is initialized we pass a system session to
             // the virtual node type manager
 
@@ -431,36 +434,35 @@ public class RepositoryImpl extends Abst
     }
 
     /**
-     * Returns the {@link org.apache.jackrabbit.core.security.JackrabbitSecurityManager SecurityManager}
+     * Creates the {@link org.apache.jackrabbit.core.security.JackrabbitSecurityManager SecurityManager}
      * of this <code>Repository</code>
      *
      * @return the security manager
      * @throws RepositoryException if an error occurs.
      */
-    protected synchronized JackrabbitSecurityManager getSecurityManager()
+    private synchronized JackrabbitSecurityManager createSecurityManager()
             throws RepositoryException {
+        SecurityManagerConfig smc =
+            getConfig().getSecurityConfig().getSecurityManagerConfig();
+        String workspaceName = getConfig().getDefaultWorkspaceName();
+        if (smc != null && smc.getWorkspaceName() != null) {
+            workspaceName = smc.getWorkspaceName();
+        }
+        SystemSession securitySession = getSystemSession(workspaceName);
+        // mark system session as 'active' for that the system workspace does
+        // not get disposed by workspace-janitor
+        onSessionCreated(securitySession);
+
+        if (smc == null) {
+            log.debug("No configuration entry for SecurityManager. Using org.apache.jackrabbit.core.security.simple.SimpleSecurityManager");
+            securityMgr = new SimpleSecurityManager();
+        } else {
+            securityMgr = smc.newInstance(JackrabbitSecurityManager.class);
+        }
 
-        if (securityMgr == null) {
-            SecurityManagerConfig smc = getConfig().getSecurityConfig().getSecurityManagerConfig();
-            String workspaceName = getConfig().getDefaultWorkspaceName();
-            if (smc != null && smc.getWorkspaceName() != null) {
-                workspaceName = smc.getWorkspaceName();
-            }
-            SystemSession securitySession = getSystemSession(workspaceName);
-            // mark system session as 'active' for that the system workspace does
-            // not get disposed by workspace-janitor
-            onSessionCreated(securitySession);
-
-            if (smc == null) {
-                log.debug("No configuration entry for SecurityManager. Using org.apache.jackrabbit.core.security.simple.SimpleSecurityManager");
-                securityMgr = new SimpleSecurityManager();
-            } else {
-                securityMgr = smc.newInstance(JackrabbitSecurityManager.class);
-            }
+        securityMgr.init(this, securitySession);
+        log.info("SecurityManager = " + securityMgr.getClass());
 
-            securityMgr.init(this, securitySession);
-            log.info("SecurityManager = " + securityMgr.getClass());
-        }
         return securityMgr;
     }
 
@@ -993,7 +995,8 @@ public class RepositoryImpl extends Abst
         } else {
             log.debug("Found preauthenticated Subject, try to extend authentication");
             // login either using JAAS or custom LoginModule
-            AuthContext authCtx = getSecurityManager().getAuthContext(null, subject, workspaceName);
+            AuthContext authCtx = context.getSecurityManager().getAuthContext(
+                    null, subject, workspaceName);
             try {
                 authCtx.login();
                 s = createSession(authCtx, workspaceName);
@@ -1421,7 +1424,8 @@ public class RepositoryImpl extends Abst
                 }
             }
             // not preauthenticated -> try login with credentials
-            AuthContext authCtx = getSecurityManager().getAuthContext(credentials, new Subject(),
workspaceName);
+            AuthContext authCtx = context.getSecurityManager().getAuthContext(
+                    credentials, new Subject(), workspaceName);
             authCtx.login();
 
             // create session, and add SimpleCredentials attributes (JCR-1932)

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=948866&r1=948865&r2=948866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Thu May 27 15:48:00 2010
@@ -301,7 +301,8 @@ public class SessionImpl extends Abstrac
      * @return the userID.
      */
     protected String retrieveUserId(Subject subject, String workspaceName) throws RepositoryException
{
-        return rep.getSecurityManager().getUserID(subject, workspaceName);
+        return repositoryContext.getSecurityManager().getUserID(
+                subject, workspaceName);
     }
 
     /**
@@ -373,7 +374,7 @@ public class SessionImpl extends Abstrac
                 hierarchyManager,
                 this,
                 wspName);
-        return rep.getSecurityManager().getAccessManager(this, ctx);
+        return repositoryContext.getSecurityManager().getAccessManager(this, ctx);
     }
 
     /**
@@ -746,7 +747,8 @@ public class SessionImpl extends Abstrac
      */
     public PrincipalManager getPrincipalManager() throws RepositoryException, AccessDeniedException
{
         if (principalManager == null) {
-            principalManager = rep.getSecurityManager().getPrincipalManager(this);
+            principalManager =
+                repositoryContext.getSecurityManager().getPrincipalManager(this);
         }
         return principalManager;
     }
@@ -756,7 +758,8 @@ public class SessionImpl extends Abstrac
      */
     public UserManager getUserManager() throws AccessDeniedException, RepositoryException
{
         if (userManager == null) {
-            userManager = rep.getSecurityManager().getUserManager(this);
+            userManager =
+                repositoryContext.getSecurityManager().getUserManager(this);
         }
         return userManager;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/UserPerWorkspaceSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/UserPerWorkspaceSecurityManagerTest.java?rev=948866&r1=948865&r2=948866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/UserPerWorkspaceSecurityManagerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/UserPerWorkspaceSecurityManagerTest.java
Thu May 27 15:48:00 2010
@@ -49,7 +49,7 @@ public class UserPerWorkspaceSecurityMan
         super.setUp();
 
         RepositoryImpl repo = (RepositoryImpl) superuser.getRepository();
-        secMgr = repo.getSecurityManager();
+        secMgr = repo.getRepositoryContext().getSecurityManager();
         if (!(secMgr instanceof UserPerWorkspaceSecurityManager)) {
             throw new NotExecutableException();
         }



Mime
View raw message