jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1401754 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/spi/security/principal/ test/java/org/apache/jackrabbit/oak/spi/security/principal/
Date Wed, 24 Oct 2012 16:13:25 GMT
Author: angela
Date: Wed Oct 24 16:13:24 2012
New Revision: 1401754

URL: http://svn.apache.org/viewvc?rev=1401754&view=rev
Log:
OAK-90 : Implement Principal Management (WIP)

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipalTest.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/AnonymousPrincipal.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipal.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipal.java?rev=1401754&r1=1401753&r2=1401754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipal.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipal.java
Wed Oct 24 16:13:24 2012
@@ -81,8 +81,9 @@ public class EveryonePrincipal implement
     public boolean equals(Object obj) {
         if (obj == this) {
             return true;
-        } else if (obj instanceof Principal) {
-            return NAME.equals(((Principal) obj).getName());
+        } else if (obj instanceof JackrabbitPrincipal) {
+            JackrabbitPrincipal other = (JackrabbitPrincipal) obj;
+            return NAME.equals(other.getName());
         }
         return false;
     }

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipalTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipalTest.java?rev=1401754&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipalTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/EveryonePrincipalTest.java
Wed Oct 24 16:13:24 2012
@@ -0,0 +1,124 @@
+/*
+ * 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.oak.spi.security.principal;
+
+import java.security.Principal;
+import java.util.Enumeration;
+
+import org.apache.jackrabbit.api.security.principal.JackrabbitPrincipal;
+import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class EveryonePrincipalTest extends AbstractSecurityTest {
+
+    private final Principal everyone = EveryonePrincipal.getInstance();
+
+    @Test
+    public void testGetName() {
+        assertEquals(EveryonePrincipal.NAME, everyone.getName());
+    }
+
+    @Test
+    public void testEquals() {
+        assertEquals(everyone, EveryonePrincipal.getInstance());
+    }
+
+    @Test
+    public void testSame() {
+        assertSame(everyone, EveryonePrincipal.getInstance());
+    }
+
+    @Test
+    public void testHashCode() {
+        assertTrue(everyone.hashCode() == EveryonePrincipal.getInstance().hashCode());
+    }
+
+    @Test
+    public void testNotEqualsOtherPrincipalWithSameName() {
+        Principal someotherEveryone = new Principal() {
+            public String getName() {
+                return EveryonePrincipal.NAME;
+            }
+        };
+        assertFalse(everyone.equals(someotherEveryone));
+    }
+
+    @Test
+    public void testEqualsOtherJackrabbitPrincipal() {
+        Principal someotherEveryone = new OtherEveryone();
+
+        assertEquals(everyone, someotherEveryone);
+    }
+
+    @Test
+    public void testEqualsOtherJackrabbitGroup() {
+        Principal someotherEveryone = new OtherEveryoneGroup();
+
+        assertEquals(everyone, someotherEveryone);
+    }
+
+    //--------------------------------------------------------------------------
+
+    private class OtherEveryone implements JackrabbitPrincipal {
+        public String getName() {
+            return EveryonePrincipal.NAME;
+        }
+        @Override
+        public boolean equals(Object o) {
+            if (o instanceof JackrabbitPrincipal) {
+                return getName().equals(((JackrabbitPrincipal) o).getName());
+            }
+            return false;
+        }
+        @Override
+        public int hashCode() {
+            return getName().hashCode();
+        }
+    }
+
+    private class OtherEveryoneGroup extends OtherEveryone implements java.security.acl.Group
{
+
+        @Override
+        public boolean addMember(Principal principal) {
+            // TODO
+            return false;
+        }
+
+        @Override
+        public boolean removeMember(Principal principal) {
+            // TODO
+            return false;
+        }
+
+        @Override
+        public boolean isMember(Principal principal) {
+            // TODO
+            return false;
+        }
+
+        @Override
+        public Enumeration<? extends Principal> members() {
+            // TODO
+            return null;
+        }
+    }
+}



Mime
View raw message