jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1440631 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/ main/java/org/apache/jackrabbit/oak/security/authentication/ test/java/org/apache/jackrabbit/oak/ test/java/org/apache/jackrabbit/oak/security/a...
Date Wed, 30 Jan 2013 20:03:15 GMT
Author: angela
Date: Wed Jan 30 20:03:15 2013
New Revision: 1440631

URL: http://svn.apache.org/viewvc?rev=1440631&view=rev
Log:
OAK-91 : Implement Authentication Support  (remove oakconfiguration and add implementation
specific utility including test)

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ConfigurationUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/OakConfiguration.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/AuthenticationConfigurationImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/DefaultLoginModuleTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/AuthenticationConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/AuthenticationConfigurationImpl.java?rev=1440631&r1=1440630&r2=1440631&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/AuthenticationConfigurationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/AuthenticationConfigurationImpl.java
Wed Jan 30 20:03:15 2013
@@ -20,7 +20,6 @@ import javax.annotation.Nonnull;
 import javax.security.auth.login.Configuration;
 
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.security.OakConfiguration;
 import org.apache.jackrabbit.oak.security.authentication.token.TokenProviderImpl;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
@@ -69,7 +68,9 @@ public class AuthenticationConfiguration
             log.info("Failed to retrieve login configuration: using default. " + e);
         }
         if (loginConfig == null) {
-            loginConfig = new OakConfiguration(options); // TODO: define configuration structure
+            // TODO: define configuration structure
+            // TODO: review if having a default is desirable or if login should fail without
valid login configuration.
+            loginConfig = ConfigurationUtil.getDefaultConfiguration(options);
         }
         return new LoginContextProviderImpl(appName, loginConfig, nodeStore, indexProvider,
securityProvider);
     }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ConfigurationUtil.java?rev=1440631&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ConfigurationUtil.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ConfigurationUtil.java
Wed Jan 30 20:03:15 2013
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.authentication;
+
+import java.util.Collections;
+import java.util.Map;
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
+import org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule;
+import org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule;
+
+/**
+ * ConfigurationUtil... TODO
+ */
+public final class ConfigurationUtil {
+
+    private ConfigurationUtil() {
+    }
+
+    public static Configuration getDefaultConfiguration(final ConfigurationParameters loginConfiguration)
{
+        return new Configuration() {
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String applicationName)
{
+                Map<String, ?> options = loginConfiguration.getConfigValue(applicationName,
Collections.<String, Object>emptyMap());
+                return new AppConfigurationEntry[]{new DefaultEntry(options)};
+            }
+        };
+    }
+
+    public static Configuration getJackrabbit2Configuration(final ConfigurationParameters
loginConfiguration) {
+        return new Configuration() {
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String applicationName)
{
+                Map<String, ?> options = loginConfiguration.getConfigValue(applicationName,
Collections.<String, Object>emptyMap());
+                return new AppConfigurationEntry[]{new GuestEntry(options), new TokenEntry(options),
new DefaultEntry(options)};
+            }
+        };
+    }
+
+    private static final class DefaultEntry extends AppConfigurationEntry {
+        private DefaultEntry(Map<String, ?> options) {
+            super(LoginModuleImpl.class.getName(), LoginModuleControlFlag.REQUIRED, options);
+        }
+    }
+
+    private static final class GuestEntry extends AppConfigurationEntry {
+
+        private GuestEntry(Map<String, ?> options) {
+            super(GuestLoginModule.class.getName(), LoginModuleControlFlag.OPTIONAL, options);
+        }
+    }
+
+    private static final class TokenEntry extends AppConfigurationEntry {
+
+        private TokenEntry(Map<String, ?> options) {
+            super(TokenLoginModule.class.getName(), LoginModuleControlFlag.SUFFICIENT, options);
+        }
+    }
+
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java?rev=1440631&r1=1440630&r2=1440631&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
Wed Jan 30 20:03:15 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak;
 
+import javax.annotation.Nullable;
 import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.SimpleCredentials;
@@ -28,10 +29,12 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
-import org.apache.jackrabbit.oak.security.OakConfiguration;
 import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
+import org.apache.jackrabbit.oak.security.authentication.ConfigurationUtil;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
 import org.junit.After;
 import org.junit.Before;
 
@@ -52,6 +55,9 @@ public abstract class AbstractSecurityTe
     public void before() throws Exception {
         contentRepository = new Oak()
                 .with(new InitialContent())
+                        // FIXME: specify index provider (waiting for OAK-396 and OAK-343)
+//                .with(new Property2IndexHookProvider())
+//                .with(new Property2IndexProvider())
                 .with(getSecurityProvider())
                 .createContentRepository();
 
@@ -75,17 +81,17 @@ public abstract class AbstractSecurityTe
     }
 
     protected Configuration getConfiguration() {
-        return new OakConfiguration();
+        return ConfigurationUtil.getDefaultConfiguration(ConfigurationParameters.EMPTY);
     }
 
-    protected ContentSession login(Credentials credentials)
+    protected ContentSession login(@Nullable Credentials credentials)
             throws LoginException, NoSuchWorkspaceException {
         return contentRepository.login(credentials, null);
     }
 
     protected Credentials getAdminCredentials() {
-        // TODO retrieve from config
-        return new SimpleCredentials("admin", "admin".toCharArray());
+        String adminId = UserUtility.getAdminId(getUserConfiguration().getConfigurationParameters());
+        return new SimpleCredentials(adminId, adminId.toCharArray());
     }
 
 

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=1440631&r1=1440630&r2=1440631&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
Wed Jan 30 20:03:15 2013
@@ -16,10 +16,8 @@
  */
 package org.apache.jackrabbit.oak.security.authentication;
 
-import java.util.Collections;
 import javax.jcr.GuestCredentials;
 import javax.jcr.SimpleCredentials;
-import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginException;
 
@@ -29,7 +27,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.oak.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
@@ -47,17 +45,7 @@ public class DefaultLoginModuleTest exte
 
     @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());
-
-                return new AppConfigurationEntry[] {defaultEntry};
-            }
-        };
+        return ConfigurationUtil.getDefaultConfiguration(ConfigurationParameters.EMPTY);
     }
 
     @Test

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java?rev=1440631&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java
Wed Jan 30 20:03:15 2013
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.authentication;
+
+import javax.security.auth.login.Configuration;
+
+import org.apache.jackrabbit.oak.api.AuthInfo;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * JackrabbitTest... TODO
+ */
+public class Jackrabbit2ConfigurationTest extends TokenDefaultLoginModuleTest {
+
+    @Override
+    protected Configuration getConfiguration() {
+        return ConfigurationUtil.getJackrabbit2Configuration(ConfigurationParameters.EMPTY);
+    }
+
+    @Test
+    public void testNullLogin() throws Exception {
+        ContentSession cs = login(null);
+        try {
+            AuthInfo authInfo = cs.getAuthInfo();
+            String anonymousID = UserUtility.getAnonymousId(getUserConfiguration().getConfigurationParameters());
+            assertEquals(anonymousID, authInfo.getUserID());
+        } finally {
+            cs.close();
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message