incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1521895 - in /sling/whiteboard/bdelacretaz: bdelacretaz-oak-server/ bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/ it-repository/ it-repository/src/test/java/org/apache/sling/jcr/repository/it/ oak-launchpad/src/main/bun...
Date Wed, 11 Sep 2013 15:07:19 GMT
Author: bdelacretaz
Date: Wed Sep 11 15:07:18 2013
New Revision: 1521895

URL: http://svn.apache.org/r1521895
Log:
SLING-2788 - testing with local release of Oak 0.8-r1520083, work in progress

Added:
    sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
  (with props)
Modified:
    sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/pom.xml
    sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/OakSlingRepository.java
    sling/whiteboard/bdelacretaz/it-repository/pom.xml
    sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java
    sling/whiteboard/bdelacretaz/oak-launchpad/src/main/bundles/list.xml

Modified: sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/pom.xml?rev=1521895&r1=1521894&r2=1521895&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/pom.xml Wed Sep 11 15:07:18 2013
@@ -38,7 +38,7 @@
 
     <properties>
         <sling.java.version>6</sling.java.version>
-        <oak.version>0.9-SNAPSHOT</oak.version>
+        <oak.version>0.8-r1520083</oak.version>
     </properties>
 
     <build>
@@ -57,8 +57,10 @@
                           org.apache.jackrabbit.test;resolution:=optional,
                           com.mongodb;resolution:=optional,
                           org.apache.jackrabbit.oak.security.user;resolution:=optional,
+                          org.apache.jackrabbit.oak.spi.security.authentication,
                           *
                         </Import-Package>
+                        <Embed-Dependency>oak-jcr</Embed-Dependency>
                         <Bundle-Activator>
                             org.apache.sling.oak.server.Activator
                         </Bundle-Activator>

Added: sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java?rev=1521895&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
(added)
+++ sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
Wed Sep 11 15:07:18 2013
@@ -0,0 +1,49 @@
+/*
+ * 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 SF 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.sling.oak.server;
+
+import javax.jcr.Credentials;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
+
+class JcrRepositoryHacks extends RepositoryImpl {
+	JcrRepositoryHacks(ContentRepository contentRepository, Whiteboard whiteboard, SecurityProvider
securityProvider) {
+		super(contentRepository, whiteboard, securityProvider);
+	}
+	
+    @Override
+    public Session login(final Credentials credentials, final String workspace)
+            throws RepositoryException {
+    	// TODO: shouldn't be needed - set context class loader to
+    	// avoid class not found exceptions on login modules
+        final Thread thread = Thread.currentThread();
+        final ClassLoader loader = thread.getContextClassLoader();
+        try {
+            thread.setContextClassLoader(Oak.class.getClassLoader());
+            return super.login(credentials, workspace);
+        } finally {
+            thread.setContextClassLoader(loader);
+        }
+    }
+}
\ No newline at end of file

Propchange: sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/OakSlingRepository.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/OakSlingRepository.java?rev=1521895&r1=1521894&r2=1521895&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/OakSlingRepository.java
(original)
+++ sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/OakSlingRepository.java
Wed Sep 11 15:07:18 2013
@@ -17,13 +17,24 @@
  */
 package org.apache.sling.oak.server;
 
+import static java.util.Collections.singleton;
+
+import java.security.Principal;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
+import javax.security.auth.Subject;
+import javax.security.auth.login.Configuration;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -31,12 +42,26 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.Oak;
-import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.api.AuthInfo;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
 import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
-import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl;
+import org.apache.jackrabbit.oak.spi.security.authentication.ConfigurationUtil;
+import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
+import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.spi.security.user.action.AccessControlAction;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.whiteboard.OsgiWhiteboard;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
+import org.apache.jackrabbit.oak.spi.xml.ImportBehavior;
+import org.apache.jackrabbit.oak.spi.xml.ProtectedItemImporter;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.base.AbstractNamespaceMappingRepository;
 import org.osgi.service.component.ComponentContext;
@@ -50,21 +75,28 @@ import org.osgi.service.component.Compon
 public class OakSlingRepository extends AbstractNamespaceMappingRepository
         implements SlingRepository {
 
-    private Repository oakRepository;
+    private RepositoryImpl jcrRepository;
+    private SecurityProvider securityProvider;
     
     @Reference
     private NodeStore nodeStore;
     
     @Activate
     protected void activate(ComponentContext ctx) {
-        final SecurityProvider sp = new OpenSecurityProvider();
-        
-        oakRepository = new Jcr(new Oak(nodeStore))
-        .with(sp)
+        // FIXME GRANITE-2315
+        Configuration.setConfiguration(ConfigurationUtil.getJackrabbit2Configuration(ConfigurationParameters.EMPTY));
+
+        final Whiteboard whiteboard = new OsgiWhiteboard(ctx.getBundleContext());
+        securityProvider = new SecurityProviderImpl(buildSecurityConfig());
+        final Oak oak = new Oak(nodeStore)
+        .with(securityProvider)
         .with(new LuceneIndexEditorProvider())
         .with(new LuceneIndexProvider())
         .withAsyncIndexing()
-        .createRepository();
+        .with(whiteboard);
+        
+        final ContentRepository contentRepository = oak.createContentRepository();  
+        jcrRepository = new JcrRepositoryHacks(contentRepository, whiteboard, securityProvider);
         
         setup(ctx.getBundleContext());
     }
@@ -76,46 +108,89 @@ public class OakSlingRepository extends 
     
     @Override
     public String getDescriptor(String key) {
-        return oakRepository.getDescriptor(key);
+        return jcrRepository.getDescriptor(key);
     }
 
     @Override
     public String[] getDescriptorKeys() {
-        return oakRepository.getDescriptorKeys();
+        return jcrRepository.getDescriptorKeys();
     }
 
     @Override
     public Session login() throws LoginException, RepositoryException {
-        return oakRepository.login();
+        return getNamespaceAwareSession(jcrRepository.login());
     }
 
     @Override
     public Session login(Credentials creds, String workspace) throws LoginException,
             NoSuchWorkspaceException, RepositoryException {
-        return oakRepository.login(creds, workspace);
+        return getNamespaceAwareSession(jcrRepository.login(creds, workspace));
     }
 
     @Override
     public Session login(Credentials creds) throws LoginException,
             RepositoryException {
-        return oakRepository.login(creds);
+        return getNamespaceAwareSession(jcrRepository.login(creds));
     }
 
     @Override
     public Session login(String workspace) throws LoginException,
             NoSuchWorkspaceException, RepositoryException {
-        return oakRepository.login(workspace);
+        return getNamespaceAwareSession(jcrRepository.login(workspace));
     }
 
     @Override
     public String getDefaultWorkspace() {
-        return null;
+        return "oak.sling";
     }
 
     @Override
     public Session loginAdministrative(String workspace) throws RepositoryException {
-        // TODO use configurable credentials
-        final SimpleCredentials creds = new SimpleCredentials("admin", "admin".toCharArray());
-        return login(creds, workspace);
+        final String adminId = securityProvider.getConfiguration(UserConfiguration.class)
+        		.getParameters().getConfigValue(UserConstants.PARAM_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID);
+        
+        // TODO: use principal provider to retrieve admin principal
+        Set<? extends Principal> principals = singleton(new AdminPrincipal() {
+            @Override
+            public String getName() {
+                return adminId;
+            }
+        });
+        AuthInfo authInfo = new AuthInfoImpl(adminId, Collections.<String, Object>emptyMap(),
principals);
+        Subject subject = new Subject(true, principals, singleton(authInfo), Collections.<Object>emptySet());
+        Session adminSession;
+        try {
+            adminSession = Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>()
{
+                @Override
+                public Session run() throws Exception {
+                    Map<String,Object> attrs = new HashMap<String, Object>();
+                    attrs.put(RepositoryImpl.REFRESH_INTERVAL,0);
+                    //TODO OAK-803: Backwards compatibility of long-lived sessions
+                    //Remove dependency on implementation specific API
+                    return getNamespaceAwareSession((jcrRepository).login(null, null,attrs));
+                }
+            }, null);
+        } catch (PrivilegedActionException e) {
+            throw new RepositoryException("failed to retrieve admin session.", e);
+        }
+
+        return adminSession;
+    }
+    
+    // TODO: use proper osgi configuration (once that works in oak)
+    private static ConfigurationParameters buildSecurityConfig() {
+        Map<String, Object> userConfig = new HashMap<String, Object>();
+        userConfig.put(UserConstants.PARAM_GROUP_PATH, "/home/groups");
+        userConfig.put(UserConstants.PARAM_USER_PATH, "/home/users");
+        userConfig.put(UserConstants.PARAM_DEFAULT_DEPTH, 1);
+        userConfig.put(AccessControlAction.USER_PRIVILEGE_NAMES, PrivilegeConstants.JCR_ALL);
+        userConfig.put(AccessControlAction.GROUP_PRIVILEGE_NAMES, PrivilegeConstants.JCR_READ);
+        userConfig.put(ProtectedItemImporter.PARAM_IMPORT_BEHAVIOR, ImportBehavior.NAME_BESTEFFORT);
+
+        Map<String, Object> config = new HashMap<String, Object>();
+        config.put(
+                UserConfiguration.NAME,
+                new ConfigurationParameters(userConfig));
+        return new ConfigurationParameters(config);
     }
 }
\ No newline at end of file

Modified: sling/whiteboard/bdelacretaz/it-repository/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/it-repository/pom.xml?rev=1521895&r1=1521894&r2=1521895&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/it-repository/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/it-repository/pom.xml Wed Sep 11 15:07:18 2013
@@ -27,7 +27,7 @@
         <url.version>1.5.2</url.version>
         <org.ops4j.pax.logging.DefaultServiceLog.level>INFO</org.ops4j.pax.logging.DefaultServiceLog.level>
         <org.ops4j.pax.url.mvn.settings></org.ops4j.pax.url.mvn.settings>
-        <oak.version>0.9-SNAPSHOT</oak.version>
+        <oak.version>0.8-r1520083</oak.version>
     </properties>
 
     <build>

Modified: sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java?rev=1521895&r1=1521894&r2=1521895&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java
(original)
+++ sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java
Wed Sep 11 15:07:18 2013
@@ -61,7 +61,6 @@ public abstract class SlingRepositoryITB
         s.logout();
     }
 
-    @Ignore("Fails in OakRepositoryIT due to the use of OpenSecurityProvider")
     @Test(expected=RepositoryException.class)
     public void testWrongLogin() throws RepositoryException {
         final Credentials creds = new SimpleCredentials("badName", "badPAssword".toCharArray());

Modified: sling/whiteboard/bdelacretaz/oak-launchpad/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/oak-launchpad/src/main/bundles/list.xml?rev=1521895&r1=1521894&r2=1521895&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/oak-launchpad/src/main/bundles/list.xml (original)
+++ sling/whiteboard/bdelacretaz/oak-launchpad/src/main/bundles/list.xml Wed Sep 11 15:07:18
2013
@@ -502,37 +502,37 @@
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-core</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-jcr</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-commons</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-mk</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-mk-api</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-mk-remote</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         <bundle>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-lucene</artifactId>
-            <version>0.9-SNAPSHOT</version>
+            <version>0.8-r1520083</version>
         </bundle>
         
         <!-- Jackrabbit bundles that Oak 0.8 needs -->
@@ -563,4 +563,4 @@
             <version>1.0.0</version>
         </bundle>
     </startLevel>
-</bundles>
\ No newline at end of file
+</bundles>



Mime
View raw message