jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1534573 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/ut...
Date Tue, 22 Oct 2013 09:43:40 GMT
Author: angela
Date: Tue Oct 22 09:43:40 2013
New Revision: 1534573

URL: http://svn.apache.org/r1534573
Log:
OAK-1098 : AuthorizableImpl methods should convert path to Oak path (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/RemappingTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
Tue Oct 22 09:43:40 2013
@@ -288,7 +288,7 @@ public class UserManagerImpl implements 
         if (tree == null || !tree.exists()) {
             return null;
         }
-        return getAuthorizable(userProvider.getAuthorizableId(tree), tree);
+        return getAuthorizable(UserUtil.getAuthorizableId(tree), tree);
     }
 
     @Nonnull
@@ -325,9 +325,9 @@ public class UserManagerImpl implements 
             return null;
         }
         if (UserUtil.isType(tree, AuthorizableType.USER)) {
-            return new UserImpl(userProvider.getAuthorizableId(tree), tree, this);
+            return new UserImpl(UserUtil.getAuthorizableId(tree), tree, this);
         } else if (UserUtil.isType(tree, AuthorizableType.GROUP)) {
-            return new GroupImpl(userProvider.getAuthorizableId(tree), tree, this);
+            return new GroupImpl(UserUtil.getAuthorizableId(tree), tree, this);
         } else {
             throw new RepositoryException("Not a user or group tree " + tree.getPath() +
'.');
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
Tue Oct 22 09:43:40 2013
@@ -28,7 +28,6 @@ import javax.jcr.nodetype.ConstraintViol
 import javax.jcr.query.Query;
 
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.api.Root;
@@ -40,14 +39,12 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName;
 import org.apache.jackrabbit.oak.spi.security.user.AuthorizableType;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.apache.jackrabbit.oak.spi.security.user.util.UserUtil;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
 
 /**
  * User provider implementation and manager for group memberships with the
@@ -228,20 +225,6 @@ class UserProvider extends AuthorizableB
         return null;
     }
 
-    @CheckForNull
-    static String getAuthorizableId(@Nonnull Tree authorizableTree) {
-        checkNotNull(authorizableTree);
-        if (UserUtil.isType(authorizableTree, AuthorizableType.AUTHORIZABLE)) {
-            PropertyState idProp = authorizableTree.getProperty(UserConstants.REP_AUTHORIZABLE_ID);
-            if (idProp != null) {
-                return idProp.getValue(STRING);
-            } else {
-                return Text.unescapeIllegalJcrChars(authorizableTree.getName());
-            }
-        }
-        return null;
-    }
-
     //------------------------------------------------------------< private >---
 
     private Tree createAuthorizableNode(String authorizableId, boolean isGroup, String intermediatePath)
throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
Tue Oct 22 09:43:40 2013
@@ -166,7 +166,7 @@ class UserValidator extends DefaultValid
 
     private boolean isAdminUser(@Nonnull Tree userTree) {
         if (userTree.exists() && isUser(userTree)) {
-            String id = UserProvider.getAuthorizableId(userTree);
+            String id = UserUtil.getAuthorizableId(userTree);
             return UserUtil.getAdminId(provider.getConfig()).equals(id);
         } else {
             return false;
@@ -178,7 +178,7 @@ class UserValidator extends DefaultValid
     }
 
     private static boolean isValidUUID(@Nonnull Tree parent, @Nonnull String uuid) {
-        String id = UserProvider.getAuthorizableId(parent);
+        String id = UserUtil.getAuthorizableId(parent);
         return id != null && uuid.equals(UserProvider.getContentID(id));
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
Tue Oct 22 09:43:40 2013
@@ -71,7 +71,10 @@ class ResultRowToAuthorizable implements
                 type = UserUtil.getType(tree);
             }
             if (tree.exists() && (targetType == null || targetType == type)) {
-                authorizable = userManager.getAuthorizableByPath(tree.getPath());
+                String id = UserUtil.getAuthorizableId(tree);
+                if (id != null) {
+                    authorizable = userManager.getAuthorizable(id);
+                }
             }
         } catch (RepositoryException e) {
             log.debug("Failed to access authorizable " + resultPath);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java
Tue Oct 22 09:43:40 2013
@@ -156,8 +156,9 @@ public class UserQueryManager {
      * @throws javax.jcr.RepositoryException If an error occurs.
      */
     @Nonnull
-    public Iterator<Authorizable> findAuthorizables(String relPath, String value,
-                                                    AuthorizableType authorizableType) throws
RepositoryException {
+    public Iterator<Authorizable> findAuthorizables(@Nonnull String relPath,
+                                                    @Nullable String value,
+                                                    @Nonnull AuthorizableType authorizableType)
throws RepositoryException {
         return findAuthorizables(relPath, value, authorizableType, true);
     }
 
@@ -180,17 +181,21 @@ public class UserQueryManager {
      * @throws javax.jcr.RepositoryException If an error occurs.
      */
     @Nonnull
-    public Iterator<Authorizable> findAuthorizables(String relPath, String value,
-                                                    AuthorizableType authorizableType, boolean
exact) throws RepositoryException {
+    public Iterator<Authorizable> findAuthorizables(@Nonnull String relPath,
+                                                    @Nullable String value,
+                                                    @Nonnull AuthorizableType authorizableType,
+                                                    boolean exact) throws RepositoryException
{
         String statement = buildXPathStatement(relPath, value, authorizableType, exact);
         return findAuthorizables(statement, Long.MAX_VALUE, 0, authorizableType);
     }
 
     //------------------------------------------------------------< private >---
     @Nonnull
-    private String buildXPathStatement(String relPath, String value, AuthorizableType type,
boolean exact) {
+    private String buildXPathStatement(@Nonnull String relPath,
+                                       @Nullable String value,
+                                       @Nonnull AuthorizableType type, boolean exact) {
         StringBuilder stmt = new StringBuilder();
-        String searchRoot = QueryUtil.getSearchRoot(type, config);
+        String searchRoot = namePathMapper.getJcrPath(QueryUtil.getSearchRoot(type, config));
         if (!"/".equals(searchRoot)) {
             stmt.append(searchRoot);
         }
@@ -216,7 +221,7 @@ public class UserQueryManager {
                 }
             }
             path = Strings.emptyToNull(sb.toString());
-            ntName = QueryUtil.getNodeTypeName(type);
+            ntName = namePathMapper.getJcrName(QueryUtil.getNodeTypeName(type));
         }
 
         stmt.append("//");

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtil.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtil.java
Tue Oct 22 09:43:40 2013
@@ -20,6 +20,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.user.AuthorizableType;
@@ -27,6 +28,9 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.apache.jackrabbit.util.Text;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+
 /**
  * Utility methods for user management.
  */
@@ -94,4 +98,18 @@ public final class UserUtil implements U
         }
         return path;
     }
+
+    @CheckForNull
+    public static String getAuthorizableId(@Nonnull Tree authorizableTree) {
+        checkNotNull(authorizableTree);
+        if (UserUtil.isType(authorizableTree, AuthorizableType.AUTHORIZABLE)) {
+            PropertyState idProp = authorizableTree.getProperty(UserConstants.REP_AUTHORIZABLE_ID);
+            if (idProp != null) {
+                return idProp.getValue(STRING);
+            } else {
+                return Text.unescapeIllegalJcrChars(authorizableTree.getName());
+            }
+        }
+        return null;
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserProviderTest.java
Tue Oct 22 09:43:40 2013
@@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.spi.security.user.util.UserUtil;
 import org.apache.jackrabbit.util.Text;
 import org.junit.After;
 import org.junit.Before;
@@ -224,7 +225,7 @@ public class UserProviderTest {
             root.commit();
 
             assertEquals(defaultUserPath + m.get(uid), user.getPath());
-            assertEquals(uid, userProvider.getAuthorizableId(user));
+            assertEquals(uid, UserUtil.getAuthorizableId(user));
 
             Tree ath = userProvider.getAuthorizable(uid);
             assertNotNull("Tree with id " + uid + " must exist.", ath);
@@ -272,11 +273,11 @@ public class UserProviderTest {
 
         String userID = "Amanda";
         Tree user = up.createUser(userID, null);
-        assertEquals(userID, up.getAuthorizableId(user));
+        assertEquals(userID, UserUtil.getAuthorizableId(user));
 
         String groupID = "visitors";
         Tree group = up.createGroup(groupID, null);
-        assertEquals(groupID, up.getAuthorizableId(group));
+        assertEquals(groupID, UserUtil.getAuthorizableId(group));
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Tue Oct 22 09:43:40 2013
@@ -119,6 +119,8 @@
 
       <!-- User Management -->
       org.apache.jackrabbit.oak.jcr.security.user.MemberNodeImportTest                  
            <!-- OAK-414, OAK-482 -->
+      org.apache.jackrabbit.oak.jcr.security.user.RemappingTest#testFindAuthorizable    
            <!-- OAK-1098 -->
+      org.apache.jackrabbit.oak.jcr.security.user.RemappingTest#testFindAuthorizable2   
            <!-- OAK-1098 -->
 
       <!-- Query -->
       org.apache.jackrabbit.test.api.query.ElementTest#testElementTestNameTestSomeNTWithSNS
         <!-- OAK-203 -->

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/RemappingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/RemappingTest.java?rev=1534573&r1=1534572&r2=1534573&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/RemappingTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/RemappingTest.java
Tue Oct 22 09:43:40 2013
@@ -18,12 +18,14 @@ package org.apache.jackrabbit.oak.jcr.se
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
@@ -40,16 +42,15 @@ public class RemappingTest extends Abstr
 
     private List<String> unmappedPaths = ImmutableList.of("uTest:property", "uTest:node/uTest:property2");
     private List<String> mappedPaths = ImmutableList.of("my:property", "my:node/my:property2");
-    private Value value;
-    private Value value2;
+    private Value nameValue;
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
 
         superuser.getWorkspace().getNamespaceRegistry().registerNamespace("uTest", "http://jackrabbit-oak.apache.org");
-        value = superuser.getValueFactory().createValue("uTest:value", PropertyType.NAME);
-        value2 = superuser.getValueFactory().createValue("uTest:value2", PropertyType.NAME);
+        Value value = superuser.getValueFactory().createValue("value");
+        nameValue = superuser.getValueFactory().createValue("uTest:value", PropertyType.NAME);
         for (String relPath : unmappedPaths) {
             user.setProperty(relPath, value);
         }
@@ -93,6 +94,38 @@ public class RemappingTest extends Abstr
 
     @Test
     public void testFindAuthorizable() throws Exception {
+        user.setProperty("prop", superuser.getValueFactory().createValue(true));
+        superuser.save();
+        session.refresh(false);
+
+        Map<String, String> m = ImmutableMap.of("prop", "true", "my:property", "value",
"my:node/my:property2", "value");
+        for (String relPath : m.keySet()) {
+            String value = m.get(relPath);
+            Iterator<Authorizable> result = getUserManager(session).findAuthorizables(relPath,
value);
+            assertTrue(result.hasNext());
+            assertEquals(user.getID(), result.next().getID());
+        }
+    }
+
+    @Test
+    public void testFindAuthorizable2() throws Exception {
+        for (String relPath : unmappedPaths) {
+            user.setProperty(relPath, nameValue);
+        }
+        superuser.save();
+        session.refresh(false);
+
+        Map<String, String> m = ImmutableMap.of("my:property", "my:value", "my:node/my:property2",
"my:value");
+        for (String relPath : m.keySet()) {
+            String value = m.get(relPath);
+            Iterator<Authorizable> result = getUserManager(session).findAuthorizables(relPath,
value);
+            assertTrue(result.hasNext());
+            assertEquals(user.getID(), result.next().getID());
+        }
+    }
+
+    @Test
+    public void testQuery() throws Exception {
         // TODO
     }
 
@@ -143,11 +176,22 @@ public class RemappingTest extends Abstr
 
     @Test
     public void testGetProperty() throws Exception {
+        for (String relPath : unmappedPaths) {
+            user.setProperty(relPath, nameValue);
+            user.setProperty(relPath, new Value[] {nameValue});
+        }
+        superuser.save();
+        session.refresh(false);
+
         for (String relPath : mappedPaths) {
             Value[] values = authorizable.getProperty(relPath);
             assertNotNull(values);
             assertEquals(1, values.length);
-            assertEquals("my:value", values[0].getString());
+            if (PropertyType.STRING == values[0].getType()) {
+                assertEquals("value", values[0].getString());
+            } else {
+                assertEquals("my:value", values[0].getString());
+            }
         }
     }
 
@@ -166,8 +210,8 @@ public class RemappingTest extends Abstr
     @Test
     public void testSetProperty() throws Exception {
         for (String relPath : mappedPaths) {
-            authorizable.setProperty(relPath, value2);
-            authorizable.setProperty(relPath, new Value[] {value2});
+            authorizable.setProperty(relPath, nameValue);
+            authorizable.setProperty(relPath, new Value[] {nameValue});
         }
     }
 
@@ -175,14 +219,14 @@ public class RemappingTest extends Abstr
     public void testSetProperty2() throws Exception {
         for (String relPath : unmappedPaths) {
             try {
-                authorizable.setProperty(relPath, value2);
+                authorizable.setProperty(relPath, nameValue);
                 fail();
             } catch (RepositoryException e) {
                 // success
             }
 
             try {
-                authorizable.setProperty(relPath, new Value[] {value2});
+                authorizable.setProperty(relPath, new Value[] {nameValue});
                 fail();
             } catch (RepositoryException e) {
                 // success



Mime
View raw message