jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1400077 - in /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security: ./ authentication/ principal/ user/
Date Fri, 19 Oct 2012 12:58:32 GMT
Author: jukka
Date: Fri Oct 19 12:58:31 2012
New Revision: 1400077

URL: http://svn.apache.org/viewvc?rev=1400077&view=rev
Log:
OAK-352: Oak builder for simplified repository construction

Combine repository initialization and JAAS configuration in security tests

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java?rev=1400077&r1=1400076&r2=1400077&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/AbstractSecurityTest.java
Fri Oct 19 12:58:31 2012
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import org.junit.After;
 import org.junit.Before;
 
 /**
@@ -39,6 +40,8 @@ public abstract class AbstractSecurityTe
 
     private ContentRepository contentRepository;
 
+    protected ContentSession admin;
+
     @Before
     public void before() throws Exception {
         contentRepository = new Oak()
@@ -48,6 +51,19 @@ public abstract class AbstractSecurityTe
 
         // TODO: OAK-17. workaround for missing test configuration
         Configuration.setConfiguration(new OakConfiguration());
+        admin = login(getAdminCredentials());
+
+        Configuration.setConfiguration(getConfiguration());
+    }
+
+    @After
+    public void after() throws Exception {
+        admin.close();
+        Configuration.setConfiguration(null);
+    }
+
+    protected Configuration getConfiguration() {
+        return new OakConfiguration();
     }
 
     protected ContentSession login(Credentials credentials)

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java?rev=1400077&r1=1400076&r2=1400077&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java
Fri Oct 19 12:58:31 2012
@@ -34,8 +34,6 @@ import org.apache.jackrabbit.oak.securit
 import org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -48,22 +46,19 @@ import static org.junit.Assert.fail;
  */
 public class DefaultLoginModuleTest extends AbstractSecurityTest {
 
-    ContentSession admin;
+    @Override
+    protected Configuration getConfiguration() {
+        return new Configuration() {
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
+                AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
+                        LoginModuleImpl.class.getName(),
+                        AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+                        Collections.<String, Object>emptyMap());
 
-    @Before
-    public void before() throws Exception {
-        super.before();
-
-        admin = login(getAdminCredentials());
-        Configuration.setConfiguration(new DefaultConfiguration());
-    }
-
-    @After
-    public void after() throws Exception {
-        Configuration.setConfiguration(null);
-        if (admin != null) {
-            admin.close();
-        }
+                return new AppConfigurationEntry[] {defaultEntry};
+            }
+        };
     }
 
     @Test
@@ -145,16 +140,4 @@ public class DefaultLoginModuleTest exte
         }
     }
 
-    private class DefaultConfiguration extends Configuration {
-
-        @Override
-        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
-            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
-                    LoginModuleImpl.class.getName(),
-                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
-                    Collections.<String, Object>emptyMap());
-
-            return new AppConfigurationEntry[] {defaultEntry};
-        }
-    }
-}
\ No newline at end of file
+}

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java?rev=1400077&r1=1400076&r2=1400077&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/GuestDefaultLoginModuleTest.java
Fri Oct 19 12:58:31 2012
@@ -27,8 +27,6 @@ import org.apache.jackrabbit.oak.securit
 import org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl;
 import org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -38,15 +36,24 @@ import static org.junit.Assert.assertEqu
  */
 public class GuestDefaultLoginModuleTest extends AbstractSecurityTest {
 
-    @Before
-    public void before() throws Exception {
-        super.before();
-        Configuration.setConfiguration(new GuestDefaultConfiguration());
-    }
-
-    @After
-    public void after() throws Exception {
-        Configuration.setConfiguration(null);
+    @Override
+    protected Configuration getConfiguration() {
+        return new Configuration() {
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
+                AppConfigurationEntry guestEntry = new AppConfigurationEntry(
+                        GuestLoginModule.class.getName(),
+                        AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL,
+                        Collections.<String, Object>emptyMap());
+
+                AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
+                        LoginModuleImpl.class.getName(),
+                        AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+                        Collections.<String, Object>emptyMap());
+
+                return new AppConfigurationEntry[] {guestEntry, defaultEntry};
+            }
+        };
     }
 
     @Test
@@ -72,22 +79,4 @@ public class GuestDefaultLoginModuleTest
             cs.close();
         }
     }
-
-    private class GuestDefaultConfiguration extends Configuration {
-
-        @Override
-        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
-            AppConfigurationEntry guestEntry = new AppConfigurationEntry(
-                    GuestLoginModule.class.getName(),
-                    AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL,
-                    Collections.<String, Object>emptyMap());
-
-            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
-                    LoginModuleImpl.class.getName(),
-                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
-                    Collections.<String, Object>emptyMap());
-
-            return new AppConfigurationEntry[] {guestEntry, defaultEntry};
-        }
-    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java?rev=1400077&r1=1400076&r2=1400077&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenLoginModuleTest.java
Fri Oct 19 12:58:31 2012
@@ -31,8 +31,6 @@ import org.apache.jackrabbit.oak.securit
 import org.apache.jackrabbit.oak.security.authentication.token.TokenProviderImpl;
 import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo;
 import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -43,20 +41,9 @@ import static org.junit.Assert.fail;
  */
 public class TokenLoginModuleTest extends AbstractSecurityTest {
 
-    ContentSession admin;
-
-    @Before
-    public void before() throws Exception {
-        super.before();
-
-        admin = login(getAdminCredentials());
-        Configuration.setConfiguration(new TokenConfiguration());
-    }
-
-    @After
-    public void after() throws Exception {
-        Configuration.setConfiguration(null);
-        admin.close();
+    @Override
+    protected Configuration getConfiguration() {
+        return new TokenConfiguration();
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java?rev=1400077&r1=1400076&r2=1400077&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
Fri Oct 19 12:58:31 2012
@@ -19,13 +19,11 @@ package org.apache.jackrabbit.oak.securi
 import java.security.Principal;
 import java.util.Set;
 
-import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
-import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertFalse;
@@ -37,20 +35,12 @@ import static org.junit.Assert.assertTru
  */
 public class PrincipalProviderImplTest extends AbstractSecurityTest {
 
-    private ContentSession admin;
-    private PrincipalProviderImpl principalProvider;
-
-    @Before
-    public void before() throws Exception {
-        super.before();
-
-        admin = login(getAdminCredentials());
-        Root root = admin.getLatestRoot();
-        principalProvider = new PrincipalProviderImpl(root, securityProvider.getUserConfiguration(),
NamePathMapper.DEFAULT);
-    }
-
     @Test
     public void testGetPrincipals() throws Exception {
+        Root root = admin.getLatestRoot();
+        PrincipalProviderImpl principalProvider =
+                new PrincipalProviderImpl(root, securityProvider.getUserConfiguration(),
NamePathMapper.DEFAULT);
+
         String adminId = admin.getAuthInfo().getUserID();
         Set<? extends Principal> principals = principalProvider.getPrincipals(adminId);
 

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=1400077&r1=1400076&r2=1400077&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
Fri Oct 19 12:58:31 2012
@@ -20,7 +20,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
@@ -29,8 +29,6 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtility;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 import static junit.framework.Assert.assertEquals;
@@ -45,25 +43,14 @@ import static org.junit.Assert.fail;
  */
 public class UserManagerImplTest extends AbstractSecurityTest {
 
-    ContentSession admin;
-    Root root;
-    UserManagerImpl userMgr;
-
-    @Before
-    public void before() throws Exception {
-        super.before();
-        admin = login(getAdminCredentials());
-        root = admin.getLatestRoot();
-        userMgr = (UserManagerImpl) new UserConfigurationImpl(ConfigurationParameters.EMPTY,
securityProvider).getUserManager(root, NamePathMapper.DEFAULT);
-    }
-
-    @After
-    public void after() throws Exception {
-        admin.close();
-    }
+    private final UserConfigurationImpl uc = new UserConfigurationImpl(
+            ConfigurationParameters.EMPTY, securityProvider);
 
     @Test
     public void testSetPassword() throws Exception {
+        Root root = admin.getLatestRoot();
+        UserManagerImpl userMgr = (UserManagerImpl) uc.getUserManager(root, NamePathMapper.DEFAULT);
+
         User user = userMgr.createUser("a", "pw");
         root.commit();
 
@@ -95,6 +82,9 @@ public class UserManagerImplTest extends
 
     @Test
     public void setPasswordNull() throws Exception {
+        Root root = admin.getLatestRoot();
+        UserManagerImpl userMgr = (UserManagerImpl) uc.getUserManager(root, NamePathMapper.DEFAULT);
+
         User user = userMgr.createUser("a", null);
         root.commit();
 
@@ -116,6 +106,9 @@ public class UserManagerImplTest extends
 
     @Test
     public void testGetPasswordHash() throws Exception {
+        Root root = admin.getLatestRoot();
+        UserManager userMgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
+
         User user = userMgr.createUser("a", null);
         root.commit();
 



Mime
View raw message