jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1403408 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/principal/ test/java/org/apache/jackrabbit/core/security/principal/
Date Mon, 29 Oct 2012 16:36:54 GMT
Author: reschke
Date: Mon Oct 29 16:36:53 2012
New Revision: 1403408

URL: http://svn.apache.org/viewvc?rev=1403408&view=rev
Log:
JCR-3439: let PrincipalManagerImpl.CheckedGroup implement JackrabbitPrincipal (also improve
equals() method)

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java?rev=1403408&r1=1403407&r2=1403408&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
Mon Oct 29 16:36:53 2012
@@ -28,6 +28,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal;
+import org.apache.jackrabbit.api.security.principal.JackrabbitPrincipal;
 import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 
@@ -211,7 +212,7 @@ public class PrincipalManagerImpl implem
      * due to the fact, that the principal provider is not bound to a particular
      * Session object.
      */
-    private class CheckedGroup implements Group {
+    private class CheckedGroup implements Group, JackrabbitPrincipal {
 
         final Group delegatee;
         private final PrincipalProvider provider;
@@ -258,7 +259,7 @@ public class PrincipalManagerImpl implem
 
         @Override
         public boolean equals(Object obj) {
-            return delegatee.equals(obj);
+            return delegatee.equals(obj instanceof CheckedGroup ? ((CheckedGroup) obj).delegatee
: obj);
         }
     }
 

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerTest.java?rev=1403408&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerTest.java
Mon Oct 29 16:36:53 2012
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.core.security.principal;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Properties;
+
+import org.apache.jackrabbit.api.security.principal.JackrabbitPrincipal;
+import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+import sun.security.acl.GroupImpl;
+
+
+/**
+ * <code>PrincipalManagerTest</code>...
+ */
+public class PrincipalManagerTest extends AbstractJCRTest {
+
+    private static final String TESTGROUP_NAME = "org.apache.jackrabbit.core.security.principal.PrincipalManagerTest.testgroup";
+    private static final Group TESTGROUP = new GroupImpl(TESTGROUP_NAME);
+
+    private static class CustomPrincipalProvider extends AbstractPrincipalProvider {
+
+        @Override
+        protected Principal providePrincipal(String principalName) {
+            return TESTGROUP_NAME.equals(principalName) ? TESTGROUP : null;
+        }
+
+        @Override
+        public PrincipalIterator findPrincipals(String simpleFilter) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public PrincipalIterator findPrincipals(String simpleFilter, int searchType) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public PrincipalIterator getPrincipals(int searchType) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public PrincipalIterator getGroupMembership(Principal principal) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public boolean canReadPrincipal(Session session, Principal principalToRead) {
+            return true;
+        }
+    }
+
+    /**
+     * Test if a group which is not item based will be wrapped by a JackrabbitPrincipal implementation.
+     * @throws NotExecutableException
+     * @throws RepositoryException
+     */
+    public void testJackrabbitPrincipal() throws NotExecutableException, RepositoryException
{
+
+        final PrincipalProvider testProvider = new CustomPrincipalProvider();
+        testProvider.init(new Properties());
+        PrincipalManagerImpl principalManager = new PrincipalManagerImpl(superuser, new PrincipalProvider[]
{ testProvider });
+        Principal principalFromManager = principalManager.getPrincipal(TESTGROUP_NAME);
+        assertTrue(principalFromManager instanceof JackrabbitPrincipal);
+    }
+}
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java?rev=1403408&r1=1403407&r2=1403408&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
Mon Oct 29 16:36:53 2012
@@ -37,7 +37,8 @@ public class TestAll extends TestCase {
 
         suite.addTestSuite(AbstractPrincipalProviderTest.class);
         suite.addTestSuite(EveryonePrincipalTest.class);
-        
+        suite.addTestSuite(PrincipalManagerTest.class);
+
         return suite;
     }
 }



Mime
View raw message