Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 531BF10226 for ; Tue, 11 Mar 2014 07:42:08 +0000 (UTC) Received: (qmail 49636 invoked by uid 500); 11 Mar 2014 07:41:35 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 49381 invoked by uid 500); 11 Mar 2014 07:41:30 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 49303 invoked by uid 99); 11 Mar 2014 07:41:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Mar 2014 07:41:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Mar 2014 07:41:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8A5D723889B9; Tue, 11 Mar 2014 07:41:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1576208 - in /jackrabbit/oak/trunk: ./ oak-pojosr/ oak-pojosr/src/ oak-pojosr/src/main/ oak-pojosr/src/main/java/ oak-pojosr/src/main/java/org/ oak-pojosr/src/main/java/org/apache/ oak-pojosr/src/main/java/org/apache/jackrabbit/ oak-pojosr... Date: Tue, 11 Mar 2014 07:41:04 -0000 To: oak-commits@jackrabbit.apache.org From: chetanm@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140311074105.8A5D723889B9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: chetanm Date: Tue Mar 11 07:41:03 2014 New Revision: 1576208 URL: http://svn.apache.org/r1576208 Log: OAK-1522 - Provide PojoSR based RepositoryFactory implementation (wip) Checking in initial implementation. The testcase is currently ignored as some issue with SecurityConfig. Some pending features documented as part of TODOs Added: jackrabbit/oak/trunk/oak-pojosr/ jackrabbit/oak/trunk/oak-pojosr/README.md jackrabbit/oak/trunk/oak-pojosr/pom.xml (with props) jackrabbit/oak/trunk/oak-pojosr/src/ jackrabbit/oak/trunk/oak-pojosr/src/main/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/BundleDescriptorComparator.java (with props) jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactoryTest.java (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-GuestLoginModule.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-LoginModuleImpl.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-TokenLoginModule.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.ConfigurationSpi.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.user.UserConfigurationImpl.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService.config (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logback-test.xml (with props) jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logging.properties (with props) Modified: jackrabbit/oak/trunk/README.md jackrabbit/oak/trunk/pom.xml Modified: jackrabbit/oak/trunk/README.md URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/README.md?rev=1576208&r1=1576207&r2=1576208&view=diff ============================================================================== --- jackrabbit/oak/trunk/README.md (original) +++ jackrabbit/oak/trunk/README.md Tue Mar 11 07:41:03 2014 @@ -65,6 +65,7 @@ The build consists of the following main - oak-http - HTTP binding for Oak - oak-lucene - Lucene-based query index - oak-run - runnable jar packaging + - oak-pojosr - integration with PojoSR - oak-upgrade - tooling for upgrading Jackrabbit repositories to Oak - oak-it - integration tests - oak-it/mk - integration tests for MicroKernel Added: jackrabbit/oak/trunk/oak-pojosr/README.md URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/README.md?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/README.md (added) +++ jackrabbit/oak/trunk/oak-pojosr/README.md Tue Mar 11 07:41:03 2014 @@ -0,0 +1,16 @@ +Oak PojoSR +========== + +This module demonstrates running Oak outside of OSGi environments but using in built OSGi +support for configuring Oak. It makes use of [PojoSR][1] to provide the OSGi framework +support. This would enable usage of Oak in POJO env and would still enable usage of OSGi features +to customize Oak components. + +To make use of this following dependencies are required + +1. PojoSR - Provides the OSGi framework support +2. Apache Felix SCR +3. Apache Felix Config Admin +4. Apache Felix Fileinstall - To provision configuration + +[1]: https://code.google.com/p/pojosr/ \ No newline at end of file Added: jackrabbit/oak/trunk/oak-pojosr/pom.xml URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/pom.xml?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/pom.xml (added) +++ jackrabbit/oak/trunk/oak-pojosr/pom.xml Tue Mar 11 07:41:03 2014 @@ -0,0 +1,149 @@ + + + + + + 4.0.0 + + + org.apache.jackrabbit + oak-parent + 0.19-SNAPSHOT + + + oak-pojosr + Oak PojoSR + + + true + + + + + + + org.apache.rat + apache-rat-plugin + + + README.md + src/test/resources/**/*.config + + + + + + maven-clean-plugin + 2.5 + + + + ${project.basedir} + + derby.log + + + + + + + + + + + + org.apache.jackrabbit + oak-jcr + ${project.version} + + + org.mongodb + mongo-java-driver + + + org.apache.jackrabbit + jackrabbit-data + ${jackrabbit.version} + + + + org.slf4j + log4j-over-slf4j + + + org.slf4j + jcl-over-slf4j + + + org.slf4j + jul-to-slf4j + + + + + org.apache.sling + org.apache.sling.commons.logservice + 1.0.2 + + + ch.qos.logback + logback-classic + + + + + + com.googlecode.pojosr + de.kalpatec.pojosr.framework.bare + 0.2.1 + + + + org.osgi + org.osgi.core + 4.3.0 + + + org.apache.felix + org.apache.felix.scr + 1.8.2 + + + org.apache.felix + org.apache.felix.configadmin + 1.8.0 + + + org.apache.felix + org.apache.felix.fileinstall + 3.2.8 + + + org.apache.felix + org.apache.felix.jaas + 0.0.2 + + + + + junit + junit + test + + + Propchange: jackrabbit/oak/trunk/oak-pojosr/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/BundleDescriptorComparator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/BundleDescriptorComparator.java?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/BundleDescriptorComparator.java (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/BundleDescriptorComparator.java Tue Mar 11 07:41:03 2014 @@ -0,0 +1,73 @@ +/* + * 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 java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; + +import de.kalpatec.pojosr.framework.launch.BundleDescriptor; +import org.osgi.framework.Constants; + +/** + * Comparator to simulate start level support of OSgi framework by ordering the startup + * sequence. This is required to ensure that required configured is provisioned with + * ConfigAdmin before the SCR bundle starts + */ +class BundleDescriptorComparator implements Comparator { + public static final Integer DEFAULT_START_LEVEL = 20; + + private final Map startLevels; + + public BundleDescriptorComparator() { + startLevels = defaultStartLevels(); + } + + public BundleDescriptorComparator(Map startLevels) { + this.startLevels = startLevels; + } + + private Map defaultStartLevels() { + Map defaultLevels = new HashMap(); + + defaultLevels.put("org.apache.sling.commons.logservice", 1); + + defaultLevels.put("org.apache.felix.configadmin", 2); + defaultLevels.put("org.apache.felix.fileinstall", 2); + + defaultLevels.put("org.apache.felix.scr", 10); + return Collections.unmodifiableMap(defaultLevels); + } + + @Override + public int compare(BundleDescriptor o1, BundleDescriptor o2) { + return getStartLevel(o1).compareTo(getStartLevel(o2)); + } + + private Integer getStartLevel(BundleDescriptor bd) { + String symbolicName = bd.getHeaders().get(Constants.BUNDLE_SYMBOLICNAME); + Integer level = startLevels.get(symbolicName); + if (level == null) { + level = DEFAULT_START_LEVEL; + } + return level; + } +} Propchange: jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/BundleDescriptorComparator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java Tue Mar 11 07:41:03 2014 @@ -0,0 +1,311 @@ +/* + * 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 java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.RepositoryFactory; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.SettableFuture; +import de.kalpatec.pojosr.framework.launch.BundleDescriptor; +import de.kalpatec.pojosr.framework.launch.ClasspathScanner; +import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry; +import de.kalpatec.pojosr.framework.launch.PojoServiceRegistryFactory; +import org.apache.commons.io.FilenameUtils; +import org.apache.jackrabbit.api.JackrabbitRepository; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class OakOSGiRepositoryFactory implements RepositoryFactory { + + private static Logger log = LoggerFactory.getLogger(OakOSGiRepositoryFactory.class); + /** + * Name of the repository home parameter. + */ + public static final String REPOSITORY_HOME + = "org.apache.jackrabbit.repository.home"; + + public static final String REPOSITORY_STARTUP_TIMEOUT + = "org.apache.jackrabbit.repository.startupTimeOut"; + + /** + * Default timeout for repository creation + */ + private static final int DEFAULT_TIMEOUT = (int) TimeUnit.MINUTES.toSeconds(10); + + @SuppressWarnings("unchecked") + public Repository getRepository(Map parameters) throws RepositoryException { + Map config = new HashMap(); + config.putAll(parameters); + + //TODO Add support for passing config as map of PID -> Dictionary + //as part of parameters and hook it up with Felix ConfigAdmin + //Say via custom InMemory PersistenceManager or programatically + //registering it with using ConfigAdmin API + //For later part we would need to implement some sort of Start Level + //support such that + // 1. Some base bundles like ConfigAdmin get start first + // 2. We register the user provided config + // 3. Other bundles get started + + //TODO With OSGi Whiteboard we need to provide support for handling + //execution and JMX support as so far they were provided by Sling bundles + //in OSGi env + + processConfig(config); + + PojoServiceRegistry registry = createServiceRegistry(config); + preProcessRegistry(registry); + startBundles(registry); + postProcessRegistry(registry); + + //Future which would be used to notify when repository is ready + // to be used + SettableFuture repoFuture = SettableFuture.create(); + + //Start the tracker for repository creation + new RepositoryTracker(registry, repoFuture); + + //Now wait for repository to be created with given timeout + //if repository creation takes more time. This is required to handle case + // where OSGi runtime fails to start due to bugs (like cycles) + int timeout = getTimeoutInSeconds(config); + try { + return repoFuture.get(timeout, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RepositoryException("Repository initialization was interrupted"); + } catch (ExecutionException e) { + throw new RepositoryException(e); + } catch (TimeoutException e) { + try { + shutdown(registry); + } catch (BundleException be) { + log.warn("Error occurred while shutting down the service registry (due to " + + "startup timeout) backing the Repository ", be); + } + throw new RepositoryException("Repository could not be started in " + + timeout + " seconds", e); + } + } + + /** + * Enables pre processing of service registry by sub classes. This can be + * used to register services before any bundle gets started + * + * @param registry service registry + */ + protected void preProcessRegistry(PojoServiceRegistry registry) { + + } + + /** + * Enables post processing of service registry e.g. registering new services etc + * by sub classes + * + * @param registry service registry + */ + protected void postProcessRegistry(PojoServiceRegistry registry) { + + } + + /** + * @param descriptors + * @return + */ + protected List processDescriptors(List descriptors) { + //If required sort the bundle descriptors such that configuration admin and file install bundle + //gets started before SCR + Collections.sort(descriptors, new BundleDescriptorComparator()); + return descriptors; + } + + static void shutdown(PojoServiceRegistry registry) throws BundleException { + if (registry != null) { + registry.getBundleContext().getBundle().stop(); + } + } + + private static int getTimeoutInSeconds(Map config) { + Integer timeout = (Integer) config.get(REPOSITORY_STARTUP_TIMEOUT); + if (timeout == null) { + timeout = DEFAULT_TIMEOUT; + } + return timeout; + } + + private static void processConfig(Map config) { + String home = (String) config.get(REPOSITORY_HOME); + checkNotNull(home, "Repository home not defined via [%s]", REPOSITORY_HOME); + + home = FilenameUtils.normalizeNoEndSeparator(home); + + String bundleDir = FilenameUtils.concat(home, "bundles"); + config.put(Constants.FRAMEWORK_STORAGE, bundleDir); + + //FIXME Pojo SR currently reads this from system property instead of Framework Property + System.setProperty(Constants.FRAMEWORK_STORAGE, bundleDir); + + //Directory used by Felix File Install to watch for configs + config.put("felix.fileinstall.dir", FilenameUtils.concat(home, "config")); + + //Set log level for config to INFO LogService.LOG_INFO + config.put("felix.fileinstall.log.level", "3"); + + //This ensures that configuration is registered in main thread + //and not in a different thread + config.put("felix.fileinstall.noInitialDelay", "true"); + + //Directory used by Felix File Install to watch for configs + config.put("repository.home", FilenameUtils.concat(home, "repository")); + + copyConfigToSystemProps(config); + } + + private static void copyConfigToSystemProps(Map config) { + //TODO This is a temporary workaround as the current release version + //of PojoSR reads value from System properties. Trunk version reads from + //initial map. This should be removed when we move to version which has the fix + Iterator itr = config.entrySet().iterator(); + while (itr.hasNext()) { + Map.Entry e = itr.next(); + if (e.getValue() instanceof String) { + System.setProperty((String) e.getKey(), (String) e.getValue()); + } + } + } + + private PojoServiceRegistry createServiceRegistry(Map config) { + try { + ServiceLoader loader = ServiceLoader.load(PojoServiceRegistryFactory.class); + return loader.iterator().next().newPojoServiceRegistry(config); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + + private void startBundles(PojoServiceRegistry registry) { + try { + List descriptors = new ClasspathScanner().scanForBundles(); + descriptors = processDescriptors(descriptors); + registry.startBundles(descriptors); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static class RepositoryTracker extends ServiceTracker { + private final SettableFuture repoFuture; + private final PojoServiceRegistry registry; + private RepositoryProxy proxy; + + public RepositoryTracker(PojoServiceRegistry registry, SettableFuture repoFuture) { + super(registry.getBundleContext(), Repository.class.getName(), null); + this.repoFuture = repoFuture; + this.registry = registry; + this.open(); + } + + @Override + public Object addingService(ServiceReference reference) { + Object service = super.addingService(reference); + if (proxy == null) { + //As its possible that future is accessed before the service + //get registered with tracker. We also capture the initial reference + //and use that for the first access case + repoFuture.set(createProxy((Repository) service)); + } + return service; + } + + @Override + public void removedService(ServiceReference reference, Object service) { + if (proxy != null) { + proxy.clearInitialReference(); + } + } + + public PojoServiceRegistry getRegistry() { + return registry; + } + + private Repository createProxy(Repository service) { + proxy = new RepositoryProxy(this, service); + return (Repository) Proxy.newProxyInstance(getClass().getClassLoader(), + new Class[]{Repository.class, JackrabbitRepository.class}, proxy); + } + } + + /** + * Due to the way SecurityConfiguration is managed in OSGi env its possible + * that repository gets created/shutdown few times. So need to have a proxy + * to access the latest service + */ + private static class RepositoryProxy implements InvocationHandler { + private final RepositoryTracker tracker; + private Repository initialService; + + private RepositoryProxy(RepositoryTracker tracker, Repository initialService) { + this.tracker = tracker; + this.initialService = initialService; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Object obj = tracker.getService(); + if (obj == null) { + obj = initialService; + } + + Preconditions.checkNotNull(obj, "Repository service is not available"); + + if ("shutdown".equals(method.getName())) { + shutdown(tracker.getRegistry()); + } + + return method.invoke(obj, args); + } + + public void clearInitialReference() { + this.initialService = null; + } + } +} Propchange: jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactoryTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactoryTest.java?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactoryTest.java (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactoryTest.java Tue Mar 11 07:41:03 2014 @@ -0,0 +1,164 @@ +/* + * 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 java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import javax.jcr.Node; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.RepositoryFactory; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; + +import de.kalpatec.pojosr.framework.launch.PojoServiceRegistry; +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.api.JackrabbitRepository; +import org.apache.jackrabbit.api.JackrabbitSession; +import org.apache.jackrabbit.api.security.user.User; +import org.apache.jackrabbit.commons.JcrUtils; +import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.namepath.NamePathMapper; +import org.apache.jackrabbit.oak.spi.security.SecurityProvider; +import org.apache.jackrabbit.oak.spi.security.user.action.AbstractAuthorizableAction; +import org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableAction; +import org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.apache.commons.io.FilenameUtils.concat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@Ignore("OAK-1522") +public class OakOSGiRepositoryFactoryTest { + + private String repositoryHome; + private RepositoryFactory repositoryFactory = new CustomOakFactory(); + private Map config = new HashMap(); + private String newPassword; + + @Before + public void setUp() throws IOException { + repositoryHome = concat(getBaseDir(), "target/repository"); + config.put("org.apache.jackrabbit.repository.home", repositoryHome); + + File repoHome = new File(repositoryHome); + if (repoHome.exists()) { + FileUtils.cleanDirectory(new File(repositoryHome)); + } + copyConfig("common"); + } + + @Test + public void testRepositoryTar() throws Exception { + copyConfig("tar"); + + Repository repository = repositoryFactory.getRepository(config); + + //Give time for system to stablize :( + TimeUnit.SECONDS.sleep(1); + + assertNotNull(repository); + System.out.println("Repository started "); + + basicCrudTest(repository); + + //For now SecurityConfig is giving some issue + //so disable that + testCallback(repository); + + shutdown(repository); + } + + private void testCallback(Repository repository) throws RepositoryException { + JackrabbitSession session = (JackrabbitSession) + repository.login(new SimpleCredentials("admin", "admin".toCharArray())); + + String testUserId = "footest"; + + User testUser = (User) session.getUserManager().getAuthorizable(testUserId); + if (testUser == null) { + testUser = session.getUserManager().createUser(testUserId, "password"); + } + + session.save(); + + testUser.changePassword("newPassword"); + session.save(); + + assertEquals("newPassword", newPassword); + } + + private void basicCrudTest(Repository repository) throws RepositoryException { + Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); + Node rootNode = session.getRootNode(); + + Node child = JcrUtils.getOrAddNode(rootNode, "child", "oak:Unstructured"); + child.setProperty("foo3", "bar3"); + session.logout(); + + System.out.println("Basic test passed"); + } + + private void shutdown(Repository repository) { + if (repository instanceof JackrabbitRepository) { + ((JackrabbitRepository) repository).shutdown(); + } + } + + private void copyConfig(String type) throws IOException { + FileUtils.copyDirectory(new File(concat(getBaseDir(), "src/test/resources/config-" + type)), + new File(concat(repositoryHome, "config"))); + } + + private static String getBaseDir() { + return new File(".").getAbsolutePath(); + } + + private class CustomOakFactory extends OakOSGiRepositoryFactory { + + @Override + protected void postProcessRegistry(PojoServiceRegistry registry) { + registry.registerService(AuthorizableActionProvider.class.getName(), new AuthorizableActionProvider() { + @Override + public List getAuthorizableActions(SecurityProvider securityProvider) { + return Collections.singletonList(new TestAction()); + } + }, null); + } + } + + private class TestAction extends AbstractAuthorizableAction { + + @Override + public void onPasswordChange(User user, String newPassword, + Root root, NamePathMapper namePathMapper) throws RepositoryException { + OakOSGiRepositoryFactoryTest.this.newPassword = newPassword; + } + } +} Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactoryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-GuestLoginModule.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-GuestLoginModule.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-GuestLoginModule.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-GuestLoginModule.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,5 @@ +jaas.controlFlag="optional" +jaas.classname="org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule" +jaas.ranking=I"300" +jaas.realmName="" +jaas.options=[""] \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-GuestLoginModule.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-LoginModuleImpl.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-LoginModuleImpl.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-LoginModuleImpl.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-LoginModuleImpl.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,5 @@ +jaas.controlFlag="required" +jaas.classname="org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl" +jaas.ranking=I"100" +jaas.realmName="" +jaas.options=[""] \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-LoginModuleImpl.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-TokenLoginModule.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-TokenLoginModule.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-TokenLoginModule.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-TokenLoginModule.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,5 @@ +jaas.controlFlag="sufficient" +jaas.classname="org.apache.jackrabbit.oak.security.authentication.token.TokenLoginModule" +jaas.ranking=I"200" +jaas.realmName="" +jaas.options=[""] \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.Configuration.factory-TokenLoginModule.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.ConfigurationSpi.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.ConfigurationSpi.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.ConfigurationSpi.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.ConfigurationSpi.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,3 @@ +jaas.defaultRealmName="jackrabbit.oak" +jaas.globalConfigPolicy="proxy" +jaas.configProviderName="FelixJaasProvider" \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.felix.jaas.ConfigurationSpi.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1 @@ +importBehavior="besteffort" \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.user.UserConfigurationImpl.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.user.UserConfigurationImpl.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.user.UserConfigurationImpl.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.user.UserConfigurationImpl.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,4 @@ +groupsPath="/home/groups" +usersPath="/home/users" +defaultDepth="1" +importBehavior="besteffort" \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.security.user.UserConfigurationImpl.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,3 @@ +enabledActions=["org.apache.jackrabbit.oak.spi.security.user.action.AccessControlAction"] +userPrivilegeNames=["jcr:all"] +groupPrivilegeNames=["jcr:read"] \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-common/org.apache.jackrabbit.oak.spi.security.user.action.DefaultAuthorizableActionProvider.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,3 @@ +mongouri="mongodb://localhost:27017" +db="oak" +service.ranking=I"50" \ No newline at end of file Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-mongo/org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService.config URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService.config?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService.config (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService.config Tue Mar 11 07:41:03 2014 @@ -0,0 +1,2 @@ +name="Oak-Tar" +service.ranking=I"100" Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/config-tar/org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService.config ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logback-test.xml URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logback-test.xml?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logback-test.xml (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logback-test.xml Tue Mar 11 07:41:03 2014 @@ -0,0 +1,39 @@ + + + + + + %d{dd.MM.yyyy HH:mm:ss.SSS} *%level* [%thread] %logger %message%n + + + + + target/unit-tests.log + + %d{dd.MM.yyyy HH:mm:ss.SSS} *%level* [%thread] %logger %message%n + + + + + + + + + Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logback-test.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logging.properties URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logging.properties?rev=1576208&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logging.properties (added) +++ jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logging.properties Tue Mar 11 07:41:03 2014 @@ -0,0 +1,16 @@ +# 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. + +handlers = org.slf4j.bridge.SLF4JBridgeHandler Propchange: jackrabbit/oak/trunk/oak-pojosr/src/test/resources/logging.properties ------------------------------------------------------------------------------ svn:eol-style = native Modified: jackrabbit/oak/trunk/pom.xml URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/pom.xml?rev=1576208&r1=1576207&r2=1576208&view=diff ============================================================================== --- jackrabbit/oak/trunk/pom.xml (original) +++ jackrabbit/oak/trunk/pom.xml Tue Mar 11 07:41:03 2014 @@ -54,6 +54,7 @@ oak-auth-ldap oak-run oak-it + oak-pojosr