jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1416517 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/ oak-...
Date Mon, 03 Dec 2012 13:50:56 GMT
Author: angela
Date: Mon Dec  3 13:50:53 2012
New Revision: 1416517

URL: http://svn.apache.org/viewvc?rev=1416517&view=rev
Log:
OAK-50 : Implement User Management (WIP)

Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/JcrAuthorizableProperties.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefinitionProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserConfigurationImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
    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/spi/security/user/UserConfiguration.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/OakAuthorizablePropertyTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserValidatorTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefinitionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefinitionProvider.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefinitionProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefinitionProvider.java
Mon Dec  3 13:50:53 2012
@@ -24,6 +24,9 @@ import javax.jcr.nodetype.NodeDefinition
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+
 /**
  * DefinitionProvider... TODO
  */
@@ -58,8 +61,14 @@ public interface DefinitionProvider {
     PropertyDefinition getDefinition(Node parent, Property targetProperty) throws RepositoryException;
 
     @Nonnull
+    PropertyDefinition getDefinition(Tree parent, PropertyState propertyState) throws RepositoryException;
+
+    @Nonnull
     PropertyDefinition getDefinition(Node parent, String propertyName, boolean isMultiple,
int type, boolean exactTypeMatch) throws RepositoryException;
 
     @Nonnull
+    PropertyDefinition getDefinition(Tree parent, String propertyName, boolean isMultiple,
int type, boolean exactTypeMatch) throws RepositoryException;
+
+    @Nonnull
     PropertyDefinition getDefinition(Iterable<NodeType> nodeTypes, String propertyName,
boolean isMultiple, int type, boolean exactTypeMatch) throws RepositoryException;
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Mon Dec  3 13:50:53 2012
@@ -477,11 +477,25 @@ public abstract class ReadOnlyNodeTypeMa
         throw new RepositoryException("No matching property definition found for " + targetProperty.getName());
     }
 
+    @Nonnull
+    @Override
+    public PropertyDefinition getDefinition(Tree parent, PropertyState propertyState) throws
RepositoryException {
+        return getDefinition(parent, propertyState.getName(), propertyState.isArray(), propertyState.getType().tag(),
true);
+    }
+
+    @Nonnull
     @Override
     public PropertyDefinition getDefinition(Node parent, String propertyName, boolean isMultiple,
int type, boolean exactTypeMatch) throws RepositoryException {
         return getPropertyDefinition(getEffectiveNodeTypes(parent), propertyName, isMultiple,
type, exactTypeMatch);
     }
 
+    @Nonnull
+    @Override
+    public PropertyDefinition getDefinition(Tree parent, String propertyName, boolean isMultiple,
int type, boolean exactTypeMatch) throws RepositoryException {
+        return getPropertyDefinition(getEffectiveNodeTypes(parent), propertyName, isMultiple,
type, exactTypeMatch);
+    }
+
+    @Nonnull
     @Override
     public PropertyDefinition getDefinition(Iterable<NodeType> nodeTypes, String propertyName,
boolean isMultiple,
             int type, boolean exactTypeMatch) throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableImpl.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableImpl.java
Mon Dec  3 13:50:53 2012
@@ -138,12 +138,7 @@ abstract class AuthorizableImpl implemen
 
     @Override
     public String getPath() throws RepositoryException {
-        Node n = getNode();
-        if (n != null) {
-            return n.getPath();
-        } else {
-            return userManager.getNamePathMapper().getJcrPath(getTree().getPath());
-        }
+        return userManager.getNamePathMapper().getJcrPath(getTree().getPath());
     }
 
     //-------------------------------------------------------------< Object >---
@@ -151,17 +146,11 @@ abstract class AuthorizableImpl implemen
     public int hashCode() {
         if (hashCode == 0) {
             // FIXME: add proper hash-code generation taking repo/workspace/tree-identifier
into account
-//            try {
-//                Node node = getNode();
-                StringBuilder sb = new StringBuilder();
-                sb.append(isGroup() ? "group:" : "user:");
-                //sb.append(node.getSession().getWorkspace().getName());
-                sb.append(':');
-                sb.append(id);
-                hashCode = sb.toString().hashCode();
-//            } catch (RepositoryException e) {
-//                log.warn("Error while calculating hash code.",e.getMessage());
-//            }
+            StringBuilder sb = new StringBuilder();
+            sb.append(isGroup() ? "group:" : "user:");
+            sb.append(':');
+            sb.append(id);
+            hashCode = sb.toString().hashCode();
         }
         return hashCode;
     }
@@ -229,18 +218,6 @@ abstract class AuthorizableImpl implemen
     }
 
     /**
-     * @return The node associated with this authorizable instance.
-     * @throws javax.jcr.RepositoryException
-     */
-    @CheckForNull
-    private Node getNode() throws RepositoryException {
-        if (node == null) {
-            node = userManager.getAuthorizableNode(id);
-        }
-        return node;
-    }
-
-    /**
      * Retrieve authorizable properties for property related operations.
      *
      * @return

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
Mon Dec  3 13:50:53 2012
@@ -21,23 +21,31 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import javax.annotation.Nonnull;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.util.LocationUtil;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
-import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
+import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.util.LocationUtil;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
 /**
  * Oak level implementation of the internal {@code AuthorizableProperties} that
  * is used in those cases where no {@code Session} is associated with the
@@ -51,11 +59,19 @@ class OakAuthorizableProperties implemen
     private final UserProvider userProvider;
     private final String id;
     private final NamePathMapper namePathMapper;
+    private final ReadOnlyNodeTypeManager nodeTypeManager;
 
-    OakAuthorizableProperties(UserProvider userProvider, String id, NamePathMapper namePathMapper)
{
+    OakAuthorizableProperties(final Root root, UserProvider userProvider,
+                              String id, NamePathMapper namePathMapper) {
         this.userProvider = userProvider;
         this.id = id;
         this.namePathMapper = namePathMapper;
+        this.nodeTypeManager = new ReadOnlyNodeTypeManager() {
+            @Override
+            protected Tree getTypes() {
+                return root.getTree(NODE_TYPES_PATH);
+            }
+        };
     }
 
     //---------------------------------------------< AuthorizableProperties >---
@@ -64,12 +80,14 @@ class OakAuthorizableProperties implemen
         checkRelativePath(relPath);
 
         Tree tree = getTree();
-        Tree n = getLocation(tree, relPath).getTree();
-        if (n != null && Text.isDescendantOrEqual(tree.getPath(), n.getPath())) {
+        TreeLocation location = getLocation(tree, relPath);
+        Tree parent = location.getTree();
+        if (parent != null && Text.isDescendantOrEqual(tree.getPath(), parent.getPath()))
{
             List<String> l = new ArrayList<String>();
-            for (PropertyState property : n.getProperties()) {
-                if (isAuthorizableProperty(tree, property)) {
-                    l.add(property.getName());
+            for (PropertyState property : parent.getProperties()) {
+                String propName = property.getName();
+                if (isAuthorizableProperty(tree, location.getChild(propName), false)) {
+                    l.add(propName);
                 }
             }
             return l.iterator();
@@ -119,26 +137,28 @@ class OakAuthorizableProperties implemen
      */
     @Override
     public void setProperty(String relPath, Value value) throws RepositoryException {
-        checkRelativePath(relPath);
-
-        String name = Text.getName(relPath);
-        if (!isAuthorizableProperty(name)) {
-            throw new RepositoryException("Attempt to set an protected property " + name);
-        }
+        if (value == null) {
+            removeProperty(relPath);
+        } else {
+            checkRelativePath(relPath);
 
-        String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath,
1);
-        Tree n = getOrCreateTargetTree(intermediate);
-        // check if the property has already been created as multi valued
-        // property before -> in this case remove in order to avoid
-        // ValueFormatException.
-        if (n.hasProperty(name)) {
-            PropertyState p = n.getProperty(name);
-            if (p.isArray()) {
-                n.removeProperty(name);
+            String name = Text.getName(relPath);
+            String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath,
1);
+            Tree parent = getOrCreateTargetTree(intermediate);
+            checkProtectedProperty(parent, name, false, value.getType());
+
+            // check if the property has already been created as multi valued
+            // property before -> in this case remove in order to avoid
+            // ValueFormatException.
+            if (parent.hasProperty(name)) {
+                PropertyState p = parent.getProperty(name);
+                if (p.isArray()) {
+                    parent.removeProperty(name);
+                }
             }
+            PropertyState propertyState = PropertyStates.createProperty(name, value);
+            parent.setProperty(propertyState);
         }
-        PropertyState propertyState = PropertyStates.createProperty(name, value);
-        n.setProperty(propertyState);
     }
 
     /**
@@ -146,26 +166,29 @@ class OakAuthorizableProperties implemen
      */
     @Override
     public void setProperty(String relPath, Value[] values) throws RepositoryException {
-        checkRelativePath(relPath);
-
-        String name = Text.getName(relPath);
-        if (!isAuthorizableProperty(name)) {
-            throw new RepositoryException("Attempt to set an protected property " + name);
-        }
+        if (values == null) {
+            removeProperty(relPath);
+        } else {
+            checkRelativePath(relPath);
 
-        String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath,
1);
-        Tree n = getOrCreateTargetTree(intermediate);
-        // check if the property has already been created as single valued
-        // property before -> in this case remove in order to avoid
-        // ValueFormatException.
-        if (n.hasProperty(name)) {
-            PropertyState p = n.getProperty(name);
-            if (!p.isArray()) {
-                n.removeProperty(name);
+            String name = Text.getName(relPath);
+            String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath,
1);
+            Tree parent = getOrCreateTargetTree(intermediate);
+            int targetType = (values.length == 0) ? PropertyType.UNDEFINED : values[0].getType();
+            checkProtectedProperty(parent, name, true, targetType);
+
+            // check if the property has already been created as single valued
+            // property before -> in this case remove in order to avoid
+            // ValueFormatException.
+            if (parent.hasProperty(name)) {
+                PropertyState p = parent.getProperty(name);
+                if (!p.isArray()) {
+                    parent.removeProperty(name);
+                }
             }
+            PropertyState propertyState = PropertyStates.createProperty(name, Arrays.asList(values));
+            parent.setProperty(propertyState);
         }
-        PropertyState propertyState = PropertyStates.createProperty(name, Arrays.asList(values));
-        n.setProperty(propertyState);
     }
 
     /**
@@ -183,6 +206,8 @@ class OakAuthorizableProperties implemen
                 Tree parent = propertyLocation.getParent().getTree();
                 parent.removeProperty(property.getName());
                 return true;
+            } else {
+                throw new ConstraintViolationException("Property " + relPath + " isn't a
modifiable authorizable property");
             }
         }
         // no such property or wasn't a property of this authorizable.
@@ -208,24 +233,40 @@ class OakAuthorizableProperties implemen
      * @return {@code true} if the given property is defined
      * by the rep:authorizable node type or one of it's sub-node types;
      * {@code false} otherwise.
+     * @throws RepositoryException If an error occurs.
      */
-    private boolean isAuthorizableProperty(Tree authorizableTree, TreeLocation propertyLocation,
boolean verifyAncestor) {
-        if (verifyAncestor && !Text.isDescendant(authorizableTree.getPath(), propertyLocation.getPath()))
{
-                log.debug("Attempt to access property outside of authorizable scope.");
+    private boolean isAuthorizableProperty(Tree authorizableTree, TreeLocation propertyLocation,
boolean verifyAncestor) throws RepositoryException {
+        String authorizablePath = authorizableTree.getPath();
+        String propPath = propertyLocation.getPath();
+        if (verifyAncestor && !Text.isDescendant(authorizablePath, propPath)) {
+            log.debug("Attempt to access property outside of authorizable scope.");
+            return false;
+        }
+
+        Tree parent = propertyLocation.getParent().getTree();
+        PropertyState property = propertyLocation.getProperty();
+        if (property != null) {
+            PropertyDefinition def = nodeTypeManager.getDefinition(parent, property);
+            if (def.isProtected()) {
                 return false;
+            } else if (authorizablePath.equals(parent.getPath())) {
+                NodeType declaringNt = def.getDeclaringNodeType();
+                return declaringNt.isNodeType(UserConstants.NT_REP_AUTHORIZABLE);
+            } else {
+                // another non-protected property somewhere in the subtree of this
+                // authorizable node -> is a property that can be set using #setProperty.
+                return true;
             }
-        return isAuthorizableProperty(authorizableTree, propertyLocation.getProperty());
-    }
-
-    private boolean isAuthorizableProperty(Tree authorizableTree, PropertyState property)
{
-        // FIXME: add proper check for protection and declaring nt of the
-        // FIXME: property using nt functionality provided by nt-plugins
-        return property != null && isAuthorizableProperty(property.getName());
+        }
+        // property does not exist.
+        return false;
     }
 
-    private boolean isAuthorizableProperty(String propertyName) {
-        String prefix = Text.getNamespacePrefix(propertyName);
-        return !NamespaceConstants.RESERVED_PREFIXES.contains(prefix);
+    private void checkProtectedProperty(Tree parent, String propertyName, boolean isArray,
int type) throws RepositoryException {
+        PropertyDefinition def = nodeTypeManager.getDefinition(parent, propertyName, isArray,
type, false);
+        if (def.isProtected()) {
+            throw new ConstraintViolationException("Attempt to set an protected property
" + propertyName);
+        }
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserConfigurationImpl.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserConfigurationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserConfigurationImpl.java
Mon Dec  3 13:50:53 2012
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.securi
 import java.util.Collections;
 import java.util.List;
 import javax.annotation.Nonnull;
-import javax.jcr.Session;
 
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.Root;
@@ -91,13 +90,7 @@ public class UserConfigurationImpl exten
 
     @Nonnull
     @Override
-    public UserManager getUserManager(Root root, NamePathMapper namePathMapper, Session session)
{
-        return new UserManagerImpl(session, root, namePathMapper, securityProvider);
-    }
-
-    @Nonnull
-    @Override
     public UserManager getUserManager(Root root, NamePathMapper namePathMapper) {
-        return new UserManagerImpl(null, root, namePathMapper, securityProvider);
+        return new UserManagerImpl(root, namePathMapper, securityProvider);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Mon Dec  3 13:50:53 2012
@@ -193,12 +193,12 @@ public class UserImporter implements Pro
             if (uMgr instanceof UserManagerImpl) {
                 UserManagerImpl impl = (UserManagerImpl) uMgr;
                 if (isWorkspaceImport) {
-                    userManager = new UserManagerImpl(null, root, namePathMapper, impl.getSecurityProvider());
+                    // use a separate user manager that is not associated with
+                    // transient session modifications.
+                    userManager = new UserManagerImpl(root, namePathMapper, impl.getSecurityProvider());
                     return true;
                 } else {
-                    if (session != impl.getSession()) {
-                        log.warn("Session import cannot handle user content: different session
used by UserManager instance.");
-                    } else if (impl.isAutoSave()) {
+                    if (impl.isAutoSave()) {
                         log.warn("Session import cannot handle user content: UserManager
is in autosave mode.");
                     } else {
                         userManager = impl;

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=1416517&r1=1416516&r2=1416517&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
Mon Dec  3 13:50:53 2012
@@ -23,9 +23,7 @@ import java.util.Iterator;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
-import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -60,7 +58,6 @@ public class UserManagerImpl implements 
 
     private static final Logger log = LoggerFactory.getLogger(UserManagerImpl.class);
 
-    private final Session session;
     private final Root root;
     private final NamePathMapper namePathMapper;
     private final SecurityProvider securityProvider;
@@ -72,9 +69,7 @@ public class UserManagerImpl implements 
 
     private UserQueryManager queryManager;
 
-    public UserManagerImpl(Session session, Root root, NamePathMapper namePathMapper,
-                           SecurityProvider securityProvider) {
-        this.session = session;
+    public UserManagerImpl(Root root, NamePathMapper namePathMapper, SecurityProvider securityProvider)
{
         this.root = root;
         this.namePathMapper = namePathMapper;
         this.securityProvider = securityProvider;
@@ -279,20 +274,6 @@ public class UserManagerImpl implements 
 
     //--------------------------------------------------------------------------
     @CheckForNull
-    Node getAuthorizableNode(String id) throws RepositoryException {
-        if (session == null) {
-            return null;
-        }
-
-        Tree tree = userProvider.getAuthorizable(id);
-        if (tree == null) {
-            throw new RepositoryException("Authorizable not associated with an existing tree");
-        }
-        String jcrPath = getNamePathMapper().getJcrPath(tree.getPath());
-        return session.getNode(jcrPath);
-    }
-
-    @CheckForNull
     Tree getAuthorizableTree(String id) {
         Tree tree = userProvider.getAuthorizable(id);
         if (tree == null) {
@@ -311,11 +292,7 @@ public class UserManagerImpl implements 
 
     @Nonnull
     AuthorizableProperties getAuthorizableProperties(String id) throws RepositoryException
{
-        if (session != null) {
-            return new JcrAuthorizableProperties(getAuthorizableNode(id), namePathMapper);
-        } else {
-            return new OakAuthorizableProperties(userProvider, id, namePathMapper);
-        }
+        return new OakAuthorizableProperties(root, userProvider, id, namePathMapper);
     }
 
     @Nonnull
@@ -344,11 +321,6 @@ public class UserManagerImpl implements 
     }
 
     @CheckForNull
-    Session getSession() {
-        return session;
-    }
-
-    @CheckForNull
     private Authorizable getAuthorizable(String id, Tree tree) throws RepositoryException
{
         if (id == null || tree == null) {
             return null;
@@ -401,8 +373,11 @@ public class UserManagerImpl implements 
     }
 
     private void checkIsLive() throws RepositoryException {
-        if (session != null && !session.isLive()) {
-            throw new RepositoryException("UserManager has been closed.");
+        try {
+            // FIXME: checkIsLive is not part of the public root interface... execute the
check using another method.
+            root.getBlobFactory();
+        } catch (IllegalStateException e) {
+            throw new RepositoryException("User manager is no longer alive.");
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserConfiguration.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserConfiguration.java
Mon Dec  3 13:50:53 2012
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.spi.security.user;
 
 import javax.annotation.Nonnull;
-import javax.jcr.Session;
 
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.Root;
@@ -34,8 +33,5 @@ public interface UserConfiguration exten
     AuthorizableActionProvider getAuthorizableActionProvider();
 
     @Nonnull
-    UserManager getUserManager(Root root, NamePathMapper namePathMapper, Session session);
-
-    @Nonnull
     UserManager getUserManager(Root root, NamePathMapper namePathMapper);
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/OakAuthorizablePropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/OakAuthorizablePropertyTest.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/OakAuthorizablePropertyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/OakAuthorizablePropertyTest.java
Mon Dec  3 13:50:53 2012
@@ -64,7 +64,7 @@ public class OakAuthorizablePropertyTest
         super.before();
 
         root = admin.getLatestRoot();
-        userMgr = new UserManagerImpl(null, root, NamePathMapper.DEFAULT, getSecurityProvider());
+        userMgr = new UserManagerImpl(root, NamePathMapper.DEFAULT, getSecurityProvider());
 
         user = userMgr.createUser("testuser", "pw");
         group = userMgr.createGroup("testgroup");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
Mon Dec  3 13:50:53 2012
@@ -58,7 +58,7 @@ public class UserManagerImplTest extends
         super.before();
 
         root = admin.getLatestRoot();
-        userMgr = new UserManagerImpl(null, root, NamePathMapper.DEFAULT, getSecurityProvider());
+        userMgr = new UserManagerImpl(root, NamePathMapper.DEFAULT, getSecurityProvider());
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserValidatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserValidatorTest.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserValidatorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserValidatorTest.java
Mon Dec  3 13:50:53 2012
@@ -51,7 +51,7 @@ public class UserValidatorTest extends A
         super.before();
 
         root = admin.getLatestRoot();
-        userMgr = new UserManagerImpl(null, root, NamePathMapper.DEFAULT, getSecurityProvider());
+        userMgr = new UserManagerImpl(root, NamePathMapper.DEFAULT, getSecurityProvider());
         user = userMgr.createUser("test", "pw");
         root.commit();
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Mon Dec  3 13:50:53 2012
@@ -85,8 +85,7 @@ public class SessionDelegate {
     SessionDelegate(
             Repository repository, ScheduledExecutorService executor,
             ContentSession contentSession, SecurityProvider securityProvider,
-            boolean autoRefresh)
-            throws RepositoryException {
+            boolean autoRefresh) {
 
         this.repository = checkNotNull(repository);
         this.executor = executor;
@@ -503,7 +502,7 @@ public class SessionDelegate {
     UserManager getUserManager() throws UnsupportedRepositoryOperationException {
         if (userManager == null) {
             if (securityProvider != null) {
-                userManager = securityProvider.getUserConfiguration().getUserManager(root,
getNamePathMapper(), session);
+                userManager = securityProvider.getUserConfiguration().getUserManager(root,
getNamePathMapper());
             } else {
                 throw new UnsupportedRepositoryOperationException("User management not supported.");
             }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java?rev=1416517&r1=1416516&r2=1416517&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
Mon Dec  3 13:50:53 2012
@@ -345,6 +345,54 @@ public class AuthorizablePropertyTest ex
     }
 
     @Test
+    public void testSetNullPropertyRemoves() throws RepositoryException, NotExecutableException
{
+        Value v = superuser.getValueFactory().createValue("testValue");
+        try {
+            user.setProperty("testProperty", v);
+            user.setProperty("testMvProperty", new Value[] {v});
+            superuser.save();
+        } catch (RepositoryException e) {
+            throw new NotExecutableException("Cannot test 'Authorizable.setProperty'.");
+        }
+
+        user.setProperty("testProperty", (Value) null);
+        assertFalse(user.hasProperty("testProperty"));
+
+        user.setProperty("testMvProperty", (Value[]) null);
+        assertFalse(user.hasProperty("testMvProperty"));
+    }
+
+    @Test
+    public void testSingleValueToMultiValue() throws RepositoryException, NotExecutableException
{
+        Value v = superuser.getValueFactory().createValue("testValue");
+        try {
+            user.setProperty("testProperty", v);
+            superuser.save();
+        } catch (RepositoryException e) {
+            throw new NotExecutableException("Cannot test 'Authorizable.setProperty'.");
+        }
+
+        user.setProperty("testProperty", new Value[] {v});
+        Property p = superuser.getProperty(user.getPath() + "/testProperty");
+        assertTrue(p.isMultiple());
+    }
+
+    @Test
+    public void testMultiValueToSingleValue() throws RepositoryException, NotExecutableException
{
+        Value v = superuser.getValueFactory().createValue("testValue");
+        try {
+            user.setProperty("testProperty", new Value[] {v});
+            superuser.save();
+        } catch (RepositoryException e) {
+            throw new NotExecutableException("Cannot test 'Authorizable.setProperty'.");
+        }
+
+        user.setProperty("testProperty", v);
+        Property p = superuser.getProperty(user.getPath() + "/testProperty");
+        assertFalse(p.isMultiple());
+    }
+
+    @Test
     public void testRemoveNotExistingProperty() throws RepositoryException, NotExecutableException
{
         String hint = "Fullname";
         String propName = hint;



Mime
View raw message