jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1390375 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user: AuthorizableImpl.java AuthorizableIterator.java GroupImpl.java ImpersonationImpl.java UserImpl.java UserManagerImpl.java
Date Wed, 26 Sep 2012 10:23:31 GMT
Author: angela
Date: Wed Sep 26 10:23:30 2012
New Revision: 1390375

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

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java?rev=1390375&r1=1390374&r2=1390375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImpl.java
Wed Sep 26 10:23:30 2012
@@ -37,17 +37,13 @@ import org.apache.jackrabbit.commons.ite
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.oak.spi.security.user.MembershipProvider;
-import org.apache.jackrabbit.oak.spi.security.user.Type;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * AuthorizableImpl... TODO
- *
- * FIXME: get rid of keeping both tree AND node fields. this is workaround for
- *        missing conversion from Node to Tree and vice version in OAK-JCR
+ * AuthorizableImpl...
  */
 abstract class AuthorizableImpl implements Authorizable, UserConstants {
 
@@ -56,14 +52,13 @@ abstract class AuthorizableImpl implemen
      */
     private static final Logger log = LoggerFactory.getLogger(AuthorizableImpl.class);
 
-    private final Tree tree;
+    private final String id;
     private final UserManagerImpl userManager;
-
     private Node node;
     private int hashCode;
 
-    AuthorizableImpl(Tree tree, UserManagerImpl userManager) throws RepositoryException {
-        this.tree = tree;
+    AuthorizableImpl(String id, Tree tree, UserManagerImpl userManager) throws RepositoryException
{
+        this.id = id;
         this.userManager = userManager;
 
         checkValidTree(tree);
@@ -81,7 +76,7 @@ abstract class AuthorizableImpl implemen
      */
     @Override
     public String getID() {
-        return userManager.getUserProvider().getAuthorizableId(tree, (isGroup()) ? Type.GROUP
: Type.USER);
+        return id;
     }
 
     /**
@@ -111,7 +106,7 @@ abstract class AuthorizableImpl implemen
             throw new RepositoryException("The administrator cannot be removed.");
         }
         userManager.onRemove(this);
-        tree.remove();
+        getTree().remove();
     }
 
     /**
@@ -270,7 +265,7 @@ abstract class AuthorizableImpl implemen
             AuthorizableImpl otherAuth = (AuthorizableImpl) obj;
             try {
                 Node node = getNode();
-                return isGroup() == otherAuth.isGroup() && node.isSame(otherAuth.node);
+                return isGroup() == otherAuth.isGroup() && node.isSame(otherAuth.getNode());
             } catch (RepositoryException e) {
                 // should not occur -> return false in this case.
             }
@@ -284,17 +279,18 @@ abstract class AuthorizableImpl implemen
     @Override
     public String toString() {
         String typeStr = (isGroup()) ? "Group '" : "User '";
-        return new StringBuilder().append(typeStr).append(getID()).append('\'').toString();
+        return new StringBuilder().append(typeStr).append(id).append('\'').toString();
     }
 
     //--------------------------------------------------------------------------
     /**
      * @return The node associated with this authorizable instance.
+     * @throws javax.jcr.RepositoryException
      */
     @Nonnull
     Node getNode() throws RepositoryException {
         if (node == null) {
-            String jcrPath = userManager.getNamePathMapper().getJcrPath(tree.getPath());
+            String jcrPath = userManager.getNamePathMapper().getJcrPath(getTree().getPath());
             node = userManager.getSession().getNode(jcrPath);
         }
         return node;
@@ -302,6 +298,10 @@ abstract class AuthorizableImpl implemen
 
     @Nonnull
     Tree getTree() {
+        Tree tree = userManager.getUserProvider().getAuthorizable(id);
+        if (tree == null) {
+            throw new IllegalStateException("Authorizable not associated with an existing
tree");
+        }
         return tree;
     }
 
@@ -323,6 +323,7 @@ abstract class AuthorizableImpl implemen
      */
     @Nonnull
     String getPrincipalName() throws RepositoryException {
+        Tree tree = getTree();
         if (tree.hasProperty(REP_PRINCIPAL_NAME)) {
             return tree.getProperty(REP_PRINCIPAL_NAME).getValue().getString();
         } else {
@@ -435,7 +436,7 @@ abstract class AuthorizableImpl implemen
         }
 
         MembershipProvider mMgr = userManager.getMembershipProvider();
-        Iterator<String> oakPaths = mMgr.getMembership(tree, includeInherited);
+        Iterator<String> oakPaths = mMgr.getMembership(getTree(), includeInherited);
         if (oakPaths.hasNext()) {
             AuthorizableIterator groups = AuthorizableIterator.create(oakPaths, userManager,
UserManager.SEARCH_TYPE_GROUP);
             return new RangeIteratorAdapter(groups, groups.getSize());

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java?rev=1390375&r1=1390374&r2=1390375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
Wed Sep 26 10:23:30 2012
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.jcr.security.user;
 
 import java.util.Iterator;
-import javax.annotation.Nullable;
 import javax.jcr.RangeIterator;
 import javax.jcr.RepositoryException;
 
@@ -103,7 +102,7 @@ class AuthorizableIterator implements It
         }
 
         @Override
-        public Authorizable apply(@Nullable String oakPath) {
+        public Authorizable apply(String oakPath) {
             String jcrPath = userManager.getNamePathMapper().getJcrPath(oakPath);
             try {
                 Authorizable a = userManager.getAuthorizableByPath(jcrPath);
@@ -126,7 +125,7 @@ class AuthorizableIterator implements It
         }
 
         @Override
-        public Authorizable apply(@Nullable Tree authorizableTree) {
+        public Authorizable apply(Tree authorizableTree) {
             try {
                 return userManager.getAuthorizable(authorizableTree);
             } catch (RepositoryException e) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java?rev=1390375&r1=1390374&r2=1390375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImpl.java
Wed Sep 26 10:23:30 2012
@@ -46,8 +46,8 @@ class GroupImpl extends AuthorizableImpl
      */
     private static final Logger log = LoggerFactory.getLogger(GroupImpl.class);
 
-    GroupImpl(Tree tree, UserManagerImpl userManager) throws RepositoryException {
-        super(tree, userManager);
+    GroupImpl(String id, Tree tree, UserManagerImpl userManager) throws RepositoryException
{
+        super(id, tree, userManager);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java?rev=1390375&r1=1390374&r2=1390375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationImpl.java
Wed Sep 26 10:23:30 2012
@@ -190,7 +190,7 @@ class ImpersonationImpl implements Imper
         return princNames;
     }
 
-    private void updateImpersonatorNames(Set<String> principalNames) {
+    private void updateImpersonatorNames(Set<String> principalNames) throws RepositoryException
{
         String[] pNames = principalNames.toArray(new String[principalNames.size()]);
         if (pNames.length == 0) {
             user.setProtectedProperty(REP_PRINCIPAL_NAME, (String) null);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java?rev=1390375&r1=1390374&r2=1390375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserImpl.java
Wed Sep 26 10:23:30 2012
@@ -42,8 +42,8 @@ class UserImpl extends AuthorizableImpl 
      */
     private static final Logger log = LoggerFactory.getLogger(UserImpl.class);
 
-    UserImpl(Tree tree, UserManagerImpl userManager) throws RepositoryException {
-        super(tree, userManager);
+    UserImpl(String id, Tree tree, UserManagerImpl userManager) throws RepositoryException
{
+        super(id, tree, userManager);
     }
 
     void checkValidTree(Tree tree) throws RepositoryException {
@@ -148,7 +148,7 @@ class UserImpl extends AuthorizableImpl 
      * @see org.apache.jackrabbit.api.security.user.User#isDisabled()
      */
     @Override
-    public boolean isDisabled() {
+    public boolean isDisabled() throws RepositoryException {
         return getTree().hasProperty(REP_DISABLED);
     }
 
@@ -156,7 +156,7 @@ class UserImpl extends AuthorizableImpl 
      * @see org.apache.jackrabbit.api.security.user.User#getDisabledReason()
      */
     @Override
-    public String getDisabledReason() {
+    public String getDisabledReason() throws RepositoryException {
         PropertyState disabled = getTree().getProperty(REP_DISABLED);
         if (disabled != null) {
             return disabled.getValue().getString();
@@ -166,11 +166,11 @@ class UserImpl extends AuthorizableImpl 
 
     //--------------------------------------------------------------------------
 
-    void setProtectedProperty(String oakName, String value) {
+    void setProtectedProperty(String oakName, String value) throws RepositoryException {
         getUserManager().getUserProvider().setProtectedProperty(getTree(), oakName, value,
PropertyType.STRING);
     }
 
-    void setProtectedProperty(String oakName, String[] values) {
+    void setProtectedProperty(String oakName, String[] values) throws RepositoryException
{
         getUserManager().getUserProvider().setProtectedProperty(getTree(), oakName, values,
PropertyType.STRING);
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java?rev=1390375&r1=1390374&r2=1390375&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
Wed Sep 26 10:23:30 2012
@@ -80,7 +80,7 @@ public class UserManagerImpl implements 
         Authorizable authorizable = null;
         Tree tree = getUserProvider().getAuthorizable(id);
         if (tree != null) {
-            authorizable = getAuthorizable(tree);
+            authorizable = getAuthorizable(id, tree);
         }
         return authorizable;
     }
@@ -149,7 +149,7 @@ public class UserManagerImpl implements 
         setPrincipal(userTree, principal);
         setPassword(userTree, password, true);
 
-        User user = new UserImpl(userTree, this);
+        User user = new UserImpl(userID, userTree, this);
         onCreate(user, password);
 
         log.debug("User created: " + userID);
@@ -188,7 +188,7 @@ public class UserManagerImpl implements 
         Tree groupTree = getUserProvider().createGroup(groupID, intermediatePath);
         setPrincipal(groupTree, principal);
 
-        Group group = new GroupImpl(groupTree, this);
+        Group group = new GroupImpl(groupID, groupTree, this);
         onCreate(group);
 
         log.debug("Group created: " + groupID);
@@ -340,12 +340,20 @@ public class UserManagerImpl implements 
         if (tree == null) {
             return null;
         }
+        return getAuthorizable(userProvider.getAuthorizableId(tree), tree);
+    }
+
+    @CheckForNull
+    private Authorizable getAuthorizable(String id, Tree tree) throws RepositoryException
{
+        if (id == null || tree == null) {
+            return null;
+        }
         if (userProvider.isAuthorizableType(tree, Type.USER)) {
-            return new UserImpl(tree, this);
+            return new UserImpl(userProvider.getAuthorizableId(tree), tree, this);
         } else if (userProvider.isAuthorizableType(tree, Type.GROUP)) {
-            return new GroupImpl(tree, this);
+            return new GroupImpl(userProvider.getAuthorizableId(tree), tree, this);
         } else {
-            throw new RepositoryException("Not a user or group tree " + tree.getPath() +
".");
+            throw new RepositoryException("Not a user or group tree " + tree.getPath() +
'.');
         }
     }
 



Mime
View raw message