You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/06/05 12:56:45 UTC
svn commit: r1600595 - in
/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi:
AbstractRepositoryFactoryTest.groovy TokenAuthenticationTest.groovy
Author: chetanm
Date: Thu Jun 5 10:56:45 2014
New Revision: 1600595
URL: http://svn.apache.org/r1600595
Log:
OAK-1522 - Provide PojoSR based RepositoryFactory implementation
Adding a testcase for TokenAuthentication with PreAuth
Added:
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy
Modified:
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.groovy
Modified: jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.groovy?rev=1600595&r1=1600594&r2=1600595&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.groovy (original)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.groovy Thu Jun 5 10:56:45 2014
@@ -99,6 +99,10 @@ abstract class AbstractRepositoryFactory
return getRepository().login(new SimpleCredentials("admin", "admin".toCharArray()));
}
+ protected String createConfigValue(String ... configFiles){
+ return configFiles.collect {getResource(it).absolutePath}.join(',')
+ }
+
private static String getBaseDir() {
// 'basedir' is set by Maven Surefire. It always points to the current subproject,
// even in reactor builds.
Added: jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy?rev=1600595&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy (added)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/TokenAuthenticationTest.groovy Thu Jun 5 10:56:45 2014
@@ -0,0 +1,117 @@
+/*
+ * 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.run.osgi
+
+import com.google.common.collect.Sets
+import groovy.util.logging.Slf4j
+import org.apache.felix.jaas.LoginModuleFactory
+import org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule
+import org.apache.jackrabbit.oak.spi.security.authentication.PreAuthenticatedLogin
+import org.junit.Before
+import org.junit.Ignore
+import org.junit.Test
+
+import javax.jcr.Credentials
+import javax.jcr.Session
+import javax.jcr.SimpleCredentials
+import javax.security.auth.login.LoginException
+import javax.security.auth.spi.LoginModule
+
+import static org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.REPOSITORY_CONFIG_FILE
+
+
+class TokenAuthenticationTest extends AbstractRepositoryFactoryTest{
+
+ @Before
+ void setupRepo(){
+ config[REPOSITORY_CONFIG_FILE] = createConfigValue("oak-base-config.json", "oak-tar-config.json")
+ }
+
+ @Ignore
+ @Test
+ public void tokenCreationWithPreAuth() throws Exception{
+ repository = repositoryFactory.getRepository(config)
+ registry.registerService(LoginModuleFactory.class.name, new PreAuthLoginModuleFactory(), [
+ 'jaas.controlFlag' : 'sufficient',
+ 'jaas.realmName' : 'jackrabbit.oak',
+ 'jaas.ranking' : '250',
+
+ ] as Hashtable)
+
+ MyCredential myCred = new MyCredential("admin")
+ Session session = repository.login(myCred)
+// assert session.getAttribute(".token")
+ assert myCred.credentials.getAttribute(".token")
+ }
+
+ private static class PreAuthLoginModuleFactory implements LoginModuleFactory {
+ @Override
+ LoginModule createLoginModule() {
+ return new PreAuthLoginModule()
+ }
+ }
+
+ @Slf4j
+ private static class PreAuthLoginModule extends AbstractLoginModule {
+
+ @Override
+ protected Set<Class> getSupportedCredentials() {
+ return Sets.newHashSet(MyCredential.class)
+ }
+
+ @Override
+ boolean login() throws LoginException {
+ Credentials credentials = getCredentials();
+ if (credentials instanceof MyCredential) {
+ String userId = ((MyCredential) credentials).userID;
+ if (userId == null) {
+ log.debug("Could not extract userId/credentials");
+ } else {
+ SimpleCredentials sc = new SimpleCredentials(userId, new char[0])
+ sc.setAttribute(".token","")
+ // we just set the login name and rely on the following login modules to populate the subject
+ sharedState.put(SHARED_KEY_PRE_AUTH_LOGIN, new PreAuthenticatedLogin(userId));
+ sharedState.put(SHARED_KEY_CREDENTIALS, sc);
+ sharedState.put(SHARED_KEY_LOGIN_NAME, userId);
+ log.debug("login succeeded with trusted user: {}", userId);
+
+ ((MyCredential) credentials).credentials = sc
+ }
+ }
+ return false;
+ }
+
+ @Override
+ boolean commit() throws LoginException {
+ return false
+ }
+ }
+
+ private static class MyCredential implements Credentials {
+ final String userID
+ def SimpleCredentials credentials
+
+ MyCredential(String userID) {
+ this.userID = userID
+ }
+
+
+ }
+}