jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1535932 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/user/autosave/ test/java/org/apache/jackrabbit/oak/security/user/autosave/
Date Sat, 26 Oct 2013 06:39:08 GMT
Author: angela
Date: Sat Oct 26 06:39:07 2013
New Revision: 1535932

URL: http://svn.apache.org/r1535932
Log:
OAK-50 : Implement User Management

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapper.java?rev=1535932&r1=1535931&r2=1535932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapper.java
Sat Oct 26 06:39:07 2013
@@ -22,7 +22,6 @@ import com.google.common.base.Function;
 import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
-import org.apache.jackrabbit.api.security.user.User;
 
 class AuthorizableWrapper<T extends Authorizable> implements Function<T, T> {
 
@@ -36,10 +35,8 @@ class AuthorizableWrapper<T extends Auth
     public T apply(T authorizable) {
         if (authorizable == null) {
             return null;
-        } else if (authorizable.isGroup()) {
-            return (T) new GroupImpl((Group) authorizable, mgr);
         } else {
-            return (T) new UserImpl((User) authorizable, mgr);
+            return (T) mgr.wrap(authorizable);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java?rev=1535932&r1=1535931&r2=1535932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
Sat Oct 26 06:39:07 2013
@@ -17,16 +17,21 @@
 package org.apache.jackrabbit.oak.security.user.autosave;
 
 import java.security.Principal;
+import java.util.Iterator;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.AuthorizableExistsException;
 import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.Query;
 import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.security.user.UserManagerImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 
 /**
  * Implementation of the user management that allows to set the autosave flag.
@@ -50,20 +55,87 @@ import org.apache.jackrabbit.oak.spi.sec
  *     }
  * </pre>
  */
-public class AutoSaveEnabledManager extends UserManagerImpl {
+public class AutoSaveEnabledManager implements UserManager {
 
+    private final UserManager dlg;
     private final Root root;
     private boolean autosave = true;
 
-    public AutoSaveEnabledManager(Root root, NamePathMapper namePathMapper, SecurityProvider
securityProvider) {
-        super(root, namePathMapper, securityProvider);
+    public AutoSaveEnabledManager(UserManager dlg, Root root) {
+        this.dlg = dlg;
         this.root = root;
     }
 
     @Override
+    public Authorizable getAuthorizable(String s) throws RepositoryException {
+        return wrap(dlg.getAuthorizable(s));
+    }
+
+    @Override
+    public Authorizable getAuthorizable(Principal principal) throws RepositoryException {
+        return wrap(dlg.getAuthorizable(principal));
+    }
+
+    @Override
+    public Authorizable getAuthorizableByPath(String s) throws UnsupportedRepositoryOperationException,
RepositoryException {
+        return wrap(dlg.getAuthorizableByPath(s));
+    }
+
+    @Override
+    public Iterator<Authorizable> findAuthorizables(String s, String s1) throws RepositoryException
{
+        return AuthorizableWrapper.createIterator(dlg.findAuthorizables(s, s1), this);
+    }
+
+    @Override
+    public Iterator<Authorizable> findAuthorizables(String s, String s1, int i) throws
RepositoryException {
+        return AuthorizableWrapper.createIterator(dlg.findAuthorizables(s, s1, i), this);
+    }
+
+    @Override
+    public Iterator<Authorizable> findAuthorizables(Query query) throws RepositoryException
{
+        return AuthorizableWrapper.createIterator(dlg.findAuthorizables(query), this);
+    }
+
+    @Override
+    public User createUser(String userID, String password) throws AuthorizableExistsException,
RepositoryException {
+        try {
+            return wrap(dlg.createUser(userID, password));
+        } finally {
+            autosave();
+        }
+    }
+
+    @Override
     public User createUser(String userID, String password, Principal principal, @Nullable
String intermediatePath) throws RepositoryException {
         try {
-            return new UserImpl(super.createUser(userID, password, principal, intermediatePath),
this);
+            return wrap(dlg.createUser(userID, password, principal, intermediatePath));
+        } finally {
+            autosave();
+        }
+    }
+
+    @Override
+    public Group createGroup(String groupId) throws AuthorizableExistsException, RepositoryException
{
+        try {
+            return wrap(dlg.createGroup(groupId));
+        } finally {
+            autosave();
+        }
+    }
+
+    @Override
+    public Group createGroup(Principal principal) throws AuthorizableExistsException, RepositoryException
{
+        try {
+            return wrap(dlg.createGroup(principal));
+        } finally {
+            autosave();
+        }
+    }
+
+    @Override
+    public Group createGroup(Principal principal, String groupId) throws AuthorizableExistsException,
RepositoryException {
+        try {
+            return wrap(dlg.createGroup(principal, groupId));
         } finally {
             autosave();
         }
@@ -72,7 +144,7 @@ public class AutoSaveEnabledManager exte
     @Override
     public Group createGroup(String groupID, Principal principal, @Nullable String intermediatePath)
throws RepositoryException {
         try {
-            return new GroupImpl(super.createGroup(groupID, principal, intermediatePath),
this);
+            return wrap(dlg.createGroup(groupID, principal, intermediatePath));
         } finally {
             autosave();
         }
@@ -88,6 +160,8 @@ public class AutoSaveEnabledManager exte
         autosave = enable;
     }
 
+    //--------------------------------------------------------------------------
+
     void autosave() throws RepositoryException {
         if (autosave) {
             try {
@@ -99,4 +173,26 @@ public class AutoSaveEnabledManager exte
             }
         }
     }
+
+    @CheckForNull
+    Authorizable wrap(@Nullable Authorizable authorizable) {
+        if (authorizable == null) {
+            return null;
+        }
+        if (authorizable.isGroup()) {
+            return wrap((Group) authorizable);
+        } else {
+            return wrap((User) authorizable);
+        }
+    }
+
+    @Nonnull
+    User wrap(@Nonnull User user) {
+        return new UserImpl(user, this);
+    }
+
+    @Nonnull
+    Group wrap(@Nonnull Group group) {
+        return new GroupImpl(group, this);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java?rev=1535932&r1=1535931&r2=1535932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java
Sat Oct 26 06:39:07 2013
@@ -26,9 +26,12 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.Impersonation;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -39,7 +42,7 @@ public class AutoSaveEnabledManagerTest 
     @Override
     public void before() throws Exception {
         super.before();
-        mgr = new AutoSaveEnabledManager(root, getNamePathMapper(), getSecurityProvider());
+        mgr = new AutoSaveEnabledManager(getUserManager(root), root);
     }
 
     @Override
@@ -59,6 +62,36 @@ public class AutoSaveEnabledManagerTest 
     }
 
     @Test
+    public void testGetAuthorizable() throws RepositoryException {
+        Authorizable a = mgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
+        assertNotNull(a);
+        assertTrue(a instanceof AuthorizableImpl);
+        assertTrue(a instanceof UserImpl);
+
+        a = mgr.getAuthorizableByPath(a.getPath());
+        assertNotNull(a);
+        assertTrue(a instanceof AuthorizableImpl);
+        assertTrue(a instanceof UserImpl);
+
+        a = mgr.getAuthorizable(a.getPrincipal());
+        assertNotNull(a);
+        assertTrue(a instanceof AuthorizableImpl);
+        assertTrue(a instanceof UserImpl);
+
+        assertNull(mgr.getAuthorizable("unknown"));
+    }
+
+    @Test
+    public void testFindAuthorizable() throws RepositoryException {
+        Iterator<Authorizable> res = mgr.findAuthorizables(UserConstants.REP_AUTHORIZABLE_ID,
UserConstants.DEFAULT_ANONYMOUS_ID);
+        assertTrue(res.hasNext());
+
+        Authorizable a = res.next();
+        assertNotNull(a);
+        assertTrue(a instanceof AuthorizableImpl);
+    }
+
+    @Test
     public void testIsAutoSave() {
         assertTrue(mgr.isAutoSave());
     }



Mime
View raw message