jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1400188 - in /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security: ./ authentication/ authentication/token/
Date Fri, 19 Oct 2012 17:29:23 GMT
Author: angela
Date: Fri Oct 19 17:29:22 2012
New Revision: 1400188

URL: http://svn.apache.org/viewvc?rev=1400188&view=rev
Log:
 OAK-91 - Implement Authentication Support (WIP)

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/TokenDefaultLoginModuleTest.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/authentication/token/TokenProviderImplTest.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=1400188&r1=1400187&r2=1400188&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 17:29:22 2012
@@ -35,12 +35,9 @@ import org.junit.Before;
  */
 public abstract class AbstractSecurityTest {
 
-    protected final SecurityProvider securityProvider =
-            new SecurityProviderImpl();
-
     private ContentRepository contentRepository;
-
     protected ContentSession admin;
+    protected final SecurityProvider securityProvider = new SecurityProviderImpl();
 
     @Before
     public void before() throws Exception {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenDefaultLoginModuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenDefaultLoginModuleTest.java?rev=1400188&r1=1400187&r2=1400188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenDefaultLoginModuleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/TokenDefaultLoginModuleTest.java
Fri Oct 19 17:29:22 2012
@@ -45,7 +45,21 @@ public class TokenDefaultLoginModuleTest
 
     @Override
     protected Configuration getConfiguration() {
-        return new TokenDefaultConfiguration();
+        return new Configuration() {
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
+                AppConfigurationEntry tokenEntry = new AppConfigurationEntry(
+                        TokenLoginModule.class.getName(),
+                        AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
+                        Collections.<String, Object>emptyMap());
+
+                AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
+                        LoginModuleImpl.class.getName(),
+                        AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+                        Collections.<String, Object>emptyMap());
+                return new AppConfigurationEntry[] {tokenEntry, defaultEntry};
+            }
+        };
     }
 
     @Test
@@ -186,20 +200,4 @@ public class TokenDefaultLoginModuleTest
             cs.close();
         }
     }
-
-    private class TokenDefaultConfiguration extends Configuration {
-
-        @Override
-        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
-            AppConfigurationEntry tokenEntry = new AppConfigurationEntry(
-                    TokenLoginModule.class.getName(),
-                    AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
-                    Collections.<String, Object>emptyMap());
-            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
-                    LoginModuleImpl.class.getName(),
-                    AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
-                    Collections.<String, Object>emptyMap());
-            return new AppConfigurationEntry[] {tokenEntry, 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=1400188&r1=1400187&r2=1400188&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 17:29:22 2012
@@ -42,7 +42,17 @@ public class TokenLoginModuleTest extend
 
     @Override
     protected Configuration getConfiguration() {
-        return new TokenConfiguration();
+        return new Configuration() {
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
+                AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
+                        TokenLoginModule.class.getName(),
+                        AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+                        Collections.<String, Object>emptyMap());
+
+                return new AppConfigurationEntry[] {defaultEntry};
+            }
+        };
     }
 
     @Test
@@ -140,17 +150,4 @@ public class TokenLoginModuleTest extend
         }
 
     }
-
-    private class TokenConfiguration extends Configuration {
-
-        @Override
-        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
-            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(
-                    TokenLoginModule.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/token/TokenProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java?rev=1400188&r1=1400187&r2=1400188&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImplTest.java
Fri Oct 19 17:29:22 2012
@@ -16,18 +16,56 @@
  */
 package org.apache.jackrabbit.oak.security.authentication.token;
 
-import org.apache.jackrabbit.oak.api.ContentRepository;
+import javax.jcr.GuestCredentials;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider;
+import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 /**
  * TokenProviderImplTest...
  */
-public class TokenProviderImplTest {
+public class TokenProviderImplTest extends AbstractSecurityTest {
+
+    private TokenProviderImpl tokenProvider;
+
+    @Before
+    public void before() throws Exception {
+        super.before();
+
+        tokenProvider = new TokenProviderImpl(admin.getLatestRoot(),
+                ConfigurationParameters.EMPTY,
+                securityProvider.getUserConfiguration());
+    }
+
 
     @Test
     public void testDoCreateToken() throws Exception {
-        // TODO
+        assertFalse(tokenProvider.doCreateToken(new GuestCredentials()));
+        assertFalse(tokenProvider.doCreateToken(new TokenCredentials("token")));
+        assertFalse(tokenProvider.doCreateToken(getAdminCredentials()));
+
+        SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
+        assertFalse(tokenProvider.doCreateToken(sc));
+
+        sc.setAttribute("any_attribute", "value");
+        assertFalse(tokenProvider.doCreateToken(sc));
+
+        sc.setAttribute(TokenProvider.TOKEN_ATTRIBUTE + "_key", "value");
+        assertFalse(tokenProvider.doCreateToken(sc));
+
+        sc.setAttribute(TokenProvider.TOKEN_ATTRIBUTE, "existing");
+        assertFalse(tokenProvider.doCreateToken(sc));
+
+        sc.setAttribute(TokenProvider.TOKEN_ATTRIBUTE, "");
+        assertTrue(tokenProvider.doCreateToken(sc));
     }
 
     @Test



Mime
View raw message