jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1399241 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/
Date Wed, 17 Oct 2012 13:34:14 GMT
Author: angela
Date: Wed Oct 17 13:34:13 2012
New Revision: 1399241

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

Modified:
    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/GroupImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ImpersonationImpl.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/UserImpl.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/security/user/UserProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java

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=1399241&r1=1399240&r2=1399241&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
Wed Oct 17 13:34:13 2012
@@ -33,7 +33,6 @@ import javax.jcr.nodetype.PropertyDefini
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
@@ -45,8 +44,6 @@ import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-
 /**
  * AuthorizableImpl...
  */
@@ -339,22 +336,6 @@ abstract class AuthorizableImpl implemen
     }
 
     /**
-     * @return The principal name of this authorizable.
-     * @throws RepositoryException If no principal name can be retrieved.
-     */
-    @Nonnull
-    String getPrincipalName() throws RepositoryException {
-        Tree tree = getTree();
-        if (tree.hasProperty(REP_PRINCIPAL_NAME)) {
-            return tree.getProperty(REP_PRINCIPAL_NAME).getValue(STRING);
-        } else {
-            String msg = "Authorizable without principal name " + getID();
-            log.warn(msg);
-            throw new RepositoryException(msg);
-        }
-    }
-
-    /**
      * Returns {@code true} if this authorizable represents the 'everyone' group.
      *
      * @return {@code true} if this authorizable represents the group everyone
@@ -362,7 +343,7 @@ abstract class AuthorizableImpl implemen
      * @throws RepositoryException If an error occurs.
      */
     boolean isEveryone() throws RepositoryException {
-        return isGroup() && EveryonePrincipal.NAME.equals(getPrincipalName());
+        return isGroup() && EveryonePrincipal.NAME.equals(getUserProvider().getPrincipalName(getTree()));
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/GroupImpl.java?rev=1399241&r1=1399240&r2=1399241&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/GroupImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/GroupImpl.java
Wed Oct 17 13:34:13 2012
@@ -71,7 +71,8 @@ class GroupImpl extends AuthorizableImpl
      */
     @Override
     public Principal getPrincipal() throws RepositoryException {
-        return new GroupPrincipal(getPrincipalName(), getTree());
+        Tree groupTree = getTree();
+        return new GroupPrincipal(getUserProvider().getPrincipalName(groupTree), groupTree);
     }
 
     //--------------------------------------------------------------< Group >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ImpersonationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ImpersonationImpl.java?rev=1399241&r1=1399240&r2=1399241&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ImpersonationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ImpersonationImpl.java
Wed Oct 17 13:34:13 2012
@@ -20,7 +20,6 @@ import java.security.Principal;
 import java.security.acl.Group;
 import java.util.HashSet;
 import java.util.Set;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.security.auth.Subject;
 
@@ -189,11 +188,11 @@ class ImpersonationImpl implements Imper
     }
 
     private void updateImpersonatorNames(Tree userTree, Set<String> principalNames)
{
-        String[] pNames = principalNames.toArray(new String[principalNames.size()]);
-        if (pNames.length == 0) {
-            pNames = null;
+        if (principalNames == null || principalNames.isEmpty()) {
+            userTree.removeProperty(REP_IMPERSONATORS);
+        } else {
+            userTree.setProperty(REP_IMPERSONATORS, principalNames, Type.STRINGS);
         }
-        userProvider.setProtectedProperty(userTree, REP_IMPERSONATORS, pNames, PropertyType.STRING);
     }
 
     private Tree getUserTree() throws RepositoryException {

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=1399241&r1=1399240&r2=1399241&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
Wed Oct 17 13:34:13 2012
@@ -31,17 +31,12 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.user.UserProvider;
 
 /**
- * UserContextImpl... TODO
+ * UserConfigurationImpl... TODO
  */
 public class UserConfigurationImpl implements UserConfiguration {
 
     private final ConfigurationParameters config;
 
-    // TODO add proper configuration
-    public UserConfigurationImpl() {
-        this(new ConfigurationParameters());
-    }
-
     public UserConfigurationImpl(ConfigurationParameters config) {
         this.config = config;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImpl.java?rev=1399241&r1=1399240&r2=1399241&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImpl.java
Wed Oct 17 13:34:13 2012
@@ -64,9 +64,9 @@ class UserImpl extends AuthorizableImpl 
      */
     @Override
     public Principal getPrincipal() throws RepositoryException {
-        String principalName = getPrincipalName();
-        return new TreeBasedPrincipal(principalName, getTree(), getUserManager().getNamePathMapper());
-
+        Tree userTree = getTree();
+        String principalName = getUserProvider().getPrincipalName(userTree);
+        return new TreeBasedPrincipal(principalName, userTree, getUserManager().getNamePathMapper());
     }
 
     //---------------------------------------------------------------< User >---

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=1399241&r1=1399240&r2=1399241&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
Wed Oct 17 13:34:13 2012
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.securi
 import java.security.Principal;
 import java.util.Iterator;
 import javax.annotation.CheckForNull;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
@@ -356,8 +355,8 @@ public class UserManagerImpl implements 
         }
     }
 
-    private void setPrincipal(Tree userTree, Principal principal) {
-        getUserProvider().setProtectedProperty(userTree, UserConstants.REP_PRINCIPAL_NAME,
principal.getName(), PropertyType.STRING);
+    private void setPrincipal(Tree userTree, Principal principal) throws RepositoryException
{
+        getUserProvider().setPrincipalName(userTree, principal.getName());
     }
 
     private void checkIsLive() throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java?rev=1399241&r1=1399240&r2=1399241&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
Wed Oct 17 13:34:13 2012
@@ -22,7 +22,6 @@ import java.security.Principal;
 import java.text.ParseException;
 import java.util.Collections;
 import java.util.Iterator;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.query.Query;
@@ -35,7 +34,6 @@ import org.apache.jackrabbit.oak.api.Res
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
@@ -280,7 +278,29 @@ class UserProviderImpl extends Authoriza
         } else {
             pwHash = password;
         }
-        setProtectedProperty(userTree, UserConstants.REP_PASSWORD, pwHash, PropertyType.STRING);
+        setProtectedProperty(userTree, UserConstants.REP_PASSWORD, pwHash);
+    }
+
+    @Override
+    public String getPrincipalName(Tree authorizableTree) throws RepositoryException {
+        checkNotNull(authorizableTree);
+
+        String principalName;
+        if (authorizableTree.hasProperty(REP_PRINCIPAL_NAME)) {
+            return authorizableTree.getProperty(REP_PRINCIPAL_NAME).getValue(STRING);
+        } else {
+            String msg = "Authorizable without principal name " + getAuthorizableId(authorizableTree);
+            log.warn(msg);
+            throw new RepositoryException(msg);
+        }
+    }
+
+    @Override
+    public void setPrincipalName(Tree authorizableTree, String principalName) throws RepositoryException
{
+        checkNotNull(authorizableTree);
+        checkNotNull(principalName);
+
+        setProtectedProperty(authorizableTree, UserConstants.REP_PRINCIPAL_NAME, principalName);
     }
 
     @Override
@@ -318,33 +338,10 @@ class UserProviderImpl extends Authoriza
         if (reason == null) {
             if (isDisabled(userTree)) {
                 // enable the user again.
-                setProtectedProperty(userTree, REP_DISABLED, (String) null, PropertyType.STRING);
+                setProtectedProperty(userTree, REP_DISABLED, null);
             } // else: not disabled -> nothing to
         } else {
-            setProtectedProperty(userTree, REP_DISABLED, reason, PropertyType.STRING);
-        }
-    }
-
-    @Override
-    public void setProtectedProperty(Tree authorizableTree, String propertyName, String value,
int propertyType) {
-        checkNotNull(authorizableTree);
-
-        if (value == null) {
-            authorizableTree.removeProperty(propertyName);
-        } else {
-            authorizableTree.setProperty(PropertyStates.createProperty(propertyName, value,
propertyType));
-        }
-    }
-
-    @Override
-    public void setProtectedProperty(Tree authorizableTree, String propertyName, String[]
values, int propertyType) {
-        checkNotNull(authorizableTree);
-
-        if (values == null) {
-            authorizableTree.removeProperty(propertyName);
-        } else {
-            NodeUtil node = new NodeUtil(authorizableTree);
-            node.setValues(propertyName, values, propertyType);
+            setProtectedProperty(userTree, REP_DISABLED, reason);
         }
     }
 
@@ -448,4 +445,12 @@ class UserProviderImpl extends Authoriza
         }
         return sb.toString();
     }
+
+    private void setProtectedProperty(Tree authorizableTree, String propertyName, String
value) {
+        if (value == null) {
+            authorizableTree.removeProperty(propertyName);
+        } else {
+            authorizableTree.setProperty(propertyName, value);
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java?rev=1399241&r1=1399240&r2=1399241&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
Wed Oct 17 13:34:13 2012
@@ -108,6 +108,11 @@ public interface UserProvider {
      */
     void setPassword(Tree userTree, String password, boolean forceHash) throws RepositoryException;
 
+    @CheckForNull
+    String getPrincipalName(Tree authorizableTree) throws RepositoryException;
+
+    void setPrincipalName(Tree authorizableTree, String principalName) throws RepositoryException;
+
     @Nonnull
     Impersonation getImpersonation(Tree userTree, PrincipalProvider principalProvider);
 
@@ -117,9 +122,4 @@ public interface UserProvider {
     String getDisableReason(Tree userTree);
 
     void disable(Tree userTree, String reason) throws RepositoryException;
-
-    void setProtectedProperty(Tree authorizableTree, String propertyName, String value, int
propertyType);
-
-    void setProtectedProperty(Tree v, String propertyName, String[] values, int propertyType);
-
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java?rev=1399241&r1=1399240&r2=1399241&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
Wed Oct 17 13:34:13 2012
@@ -221,6 +221,9 @@ public class UserManagerTest extends Abs
 
     }
 
+    /**
+     * @since oak
+     */
     @Test
     public void testCreateUserWithoutPassword() throws Exception {
         try {



Mime
View raw message