incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1522668 - in /sling/whiteboard/bdelacretaz: bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java
Date Thu, 12 Sep 2013 17:19:18 GMT
Author: bdelacretaz
Date: Thu Sep 12 17:19:17 2013
New Revision: 1522668

URL: http://svn.apache.org/r1522668
Log:
SLING-2788 - set thread context class loader for all login variants, more login tests pass
now

Modified:
    sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
    sling/whiteboard/bdelacretaz/it-repository/src/test/java/org/apache/sling/jcr/repository/it/SlingRepositoryITBase.java

Modified: 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=1522668&r1=1522667&r2=1522668&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
(original)
+++ sling/whiteboard/bdelacretaz/bdelacretaz-oak-server/src/main/java/org/apache/sling/oak/server/JcrRepositoryHacks.java
Thu Sep 12 17:19:17 2013
@@ -17,6 +17,8 @@
  */
 package org.apache.sling.oak.server;
 
+import java.util.Map;
+
 import javax.jcr.Credentials;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -28,22 +30,73 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 
 class JcrRepositoryHacks extends RepositoryImpl {
+    
+    // TODO TCCL switching shouldn't be needed?
+    // LoginModules are not found without this
+    static abstract class LoginHelper {
+        Session TCCLLogin() throws RepositoryException {
+            final Thread thread = Thread.currentThread();
+            final ClassLoader loader = thread.getContextClassLoader();
+            try {
+                thread.setContextClassLoader(Oak.class.getClassLoader());
+                return doLogin();
+            } finally {
+                thread.setContextClassLoader(loader);
+            }
+            
+        }
+        
+        protected abstract Session doLogin() throws RepositoryException;
+    };
+    
 	JcrRepositoryHacks(ContentRepository contentRepository, Whiteboard whiteboard, SecurityProvider
securityProvider) {
 		super(contentRepository, whiteboard, securityProvider);
 	}
 	
     @Override
+    public Session login() throws RepositoryException {
+        return new LoginHelper() {
+            protected Session doLogin() throws RepositoryException {
+                return JcrRepositoryHacks.super.login();
+            }
+        }.TCCLLogin();
+    }
+
+    @Override
+    public Session login(final Credentials creds, final String workspace, final Map<String,
Object> opt)
+            throws RepositoryException {
+        return new LoginHelper() {
+            protected Session doLogin() throws RepositoryException {
+                return JcrRepositoryHacks.super.login(creds, workspace, opt);
+            }
+        }.TCCLLogin();
+    }
+
+    @Override
+    public Session login(final Credentials credentials) throws RepositoryException {
+        return new LoginHelper() {
+            protected Session doLogin() throws RepositoryException {
+                return JcrRepositoryHacks.super.login(credentials);
+            }
+        }.TCCLLogin();
+    }
+
+    @Override
+    public Session login(final String workspace) throws RepositoryException {
+        return new LoginHelper() {
+            protected Session doLogin() throws RepositoryException {
+                return JcrRepositoryHacks.super.login(workspace);
+            }
+        }.TCCLLogin();
+    }
+
+    @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);
-        }
+        return new LoginHelper() {
+            protected Session doLogin() throws RepositoryException {
+                return JcrRepositoryHacks.super.login(credentials, workspace);
+            }
+        }.TCCLLogin();
     }
 }
\ No newline at end of file

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=1522668&r1=1522667&r2=1522668&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
Thu Sep 12 17:19:17 2013
@@ -62,8 +62,7 @@ public abstract class SlingRepositoryITB
     }
 
     @Test
-    @Ignore("Fails on Oak: javax.security.auth.login.LoginException: unable to find LoginModule
class: org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule")
-    public void testAdminLogin() throws RepositoryException {
+    public void testExplicitAdminLogin() throws RepositoryException {
         final Credentials creds = new SimpleCredentials("admin", "admin".toCharArray());
         repository.login(creds).logout();
     }
@@ -71,7 +70,7 @@ public abstract class SlingRepositoryITB
     @Test(expected=RepositoryException.class)
     public void testWrongLogin() throws RepositoryException {
         final Credentials creds = new SimpleCredentials("badName", "badPAssword".toCharArray());
-        repository.login(creds).logout();
+        repository.login(creds);
     }
     
     private void assertCreateRetrieveNode(String nodeType) throws RepositoryException {



Mime
View raw message