jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1336237 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/ oak-c...
Date Wed, 09 May 2012 15:11:46 GMT
Author: angela
Date: Wed May  9 15:11:45 2012
New Revision: 1336237

URL: http://svn.apache.org/viewvc?rev=1336237&view=rev
Log:
 OAK-91 - Implement Authentication Support (WIP)
 
 - add initial dummy version of principal provider
 - stop treating null-credentials as anonymous login
    -> fix test cases that use Repository.login()

Other fixes:
- AbstractRepositoryTest didn't logout the session field (bug)
- QomTest left session open.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/PrincipalProviderCallback.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/diff.txt
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/KernelPrincipalProvider.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/CallbackHandlerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/LoginModuleImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Wed May  9 15:11:45 2012
@@ -26,8 +26,10 @@ import org.apache.jackrabbit.oak.kernel.
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.security.authentication.CallbackHandlerImpl;
 import org.apache.jackrabbit.oak.security.authentication.ConfigurationImpl;
+import org.apache.jackrabbit.oak.security.principal.KernelPrincipalProvider;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.commit.EmptyCommitHook;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.slf4j.Logger;
@@ -58,6 +60,7 @@ public class ContentRepositoryImpl imple
     private final NodeStore nodeStore;
 
     private final Configuration authConfig;
+    private final PrincipalProvider principalProvider;
 
     /**
      * Utility constructor that creates a new in-memory repository with default
@@ -81,8 +84,9 @@ public class ContentRepositoryImpl imple
         QueryIndexProvider qip = (indexProvider == null) ? getDefaultIndexProvider(microKernel)
: indexProvider;
         queryEngine = new QueryEngineImpl(nodeStore, microKernel, qip);
 
-        // TODO: use configurable authentication config
+        // TODO: use configurable authentication config and principal provider
         authConfig = new ConfigurationImpl();
+        principalProvider = new KernelPrincipalProvider();
 
         // FIXME: workspace setup must be done elsewhere...
         NodeState root = nodeStore.getRoot();
@@ -112,7 +116,7 @@ public class ContentRepositoryImpl imple
         // TODO: add proper implementation
         // TODO  - authentication against configurable spi-authentication
         // TODO  - validation of workspace name (including access rights for the given 'user')
-        LoginContext loginContext = new LoginContext(APP_NAME, null, new CallbackHandlerImpl(credentials),
authConfig);
+        LoginContext loginContext = new LoginContext(APP_NAME, null, new CallbackHandlerImpl(credentials,
principalProvider), authConfig);
         loginContext.login();
 
         NodeState wspRoot = nodeStore.getRoot().getChildNode(workspaceName);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/CallbackHandlerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/CallbackHandlerImpl.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/CallbackHandlerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/CallbackHandlerImpl.java
Wed May  9 15:11:45 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.security.authentication;
 
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,9 +41,11 @@ public class CallbackHandlerImpl impleme
     private static final Logger log = LoggerFactory.getLogger(CallbackHandlerImpl.class);
 
     private final Credentials credentials;
+    private final PrincipalProvider principalProvider;
 
-    public CallbackHandlerImpl(Credentials credentials) {
+    public CallbackHandlerImpl(Credentials credentials, PrincipalProvider principalProvider)
{
         this.credentials = credentials;
+        this.principalProvider = principalProvider;
     }
 
     //----------------------------------------------------< CallbackHandler >---
@@ -57,6 +60,8 @@ public class CallbackHandlerImpl impleme
                 ((PasswordCallback) callback).setPassword(getPassword());
             } else if (callback instanceof ImpersonationCallback) {
                 ((ImpersonationCallback) callback).setImpersonator(getImpersonationSubject());
+            } else if (callback instanceof PrincipalProviderCallback) {
+                ((PrincipalProviderCallback) callback).setPrincipalProvider(principalProvider);
             } else {
                 throw new UnsupportedCallbackException(callback);
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/LoginModuleImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/LoginModuleImpl.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/LoginModuleImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/LoginModuleImpl.java
Wed May  9 15:11:45 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.security.authentication;
 
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,6 +30,7 @@ import javax.security.auth.callback.Unsu
 import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 import java.io.IOException;
+import java.security.Principal;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -47,6 +49,7 @@ public class LoginModuleImpl implements 
     private CallbackHandler callbackHandler;
 
     private Set<Credentials> credentials;
+    private String principalName;
 
     //--------------------------------------------------------< LoginModule >---
     @Override
@@ -61,18 +64,20 @@ public class LoginModuleImpl implements 
     public boolean login() throws LoginException {
         // TODO
         credentials = retrieveCredentials();
-        if (credentials.isEmpty()) {
-            credentials.add(new GuestCredentials());
+        if (supportsCredentials()) {
+            principalName = retrievePrincipalName();
+            return true;
+        } else {
+            return false;
         }
-        return supportsCredentials(credentials);
-
     }
 
     @Override
     public boolean commit() throws LoginException {
         // TODO
 
-        subject.getPublicCredentials().add(credentials);
+        subject.getPrincipals().addAll(retrievePrincipals(principalName));
+        subject.getPublicCredentials().addAll(credentials);
         return true;
     }
 
@@ -113,7 +118,7 @@ public class LoginModuleImpl implements 
         return credentials;
     }
 
-    private static boolean supportsCredentials(Set<Credentials> credentials) {
+    private boolean supportsCredentials() {
         for (Credentials creds : credentials) {
             if (creds instanceof SimpleCredentials) {
                 return true;
@@ -123,4 +128,39 @@ public class LoginModuleImpl implements 
         }
         return false;
     }
+
+    private String retrievePrincipalName() {
+        for (Credentials creds : credentials) {
+            if (creds instanceof SimpleCredentials) {
+                return ((SimpleCredentials) creds).getUserID();
+            } else if (creds instanceof GuestCredentials) {
+                return "anonymous";
+            }
+        }
+
+        return null;
+    }
+
+    private Set<Principal> retrievePrincipals(String principalName) {
+        Set<Principal> principals = new HashSet<Principal>();
+        try {
+            PrincipalProviderCallback principalCallBack = new PrincipalProviderCallback();
+            callbackHandler.handle(new Callback[] {principalCallBack});
+            PrincipalProvider pp = principalCallBack.getPrincipalProvider();
+            if (pp != null) {
+                Principal p = pp.getPrincipal(principalName);
+                if (p != null) {
+                    principals.add(p);
+                    principals.addAll(pp.getGroupMembership(p));
+                }
+            }
+
+        } catch (IOException e) {
+            log.warn(e.getMessage());
+        } catch (UnsupportedCallbackException e) {
+            log.warn(e.getMessage());
+        }
+
+        return principals;
+    }
 }
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/PrincipalProviderCallback.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/PrincipalProviderCallback.java?rev=1336237&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/PrincipalProviderCallback.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/PrincipalProviderCallback.java
Wed May  9 15:11:45 2012
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.auth.callback.Callback;
+
+/**
+ * PrincipalProviderCallback...
+ */
+public class PrincipalProviderCallback implements Callback {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(PrincipalProviderCallback.class);
+
+    private PrincipalProvider principalProvider;
+
+    public PrincipalProvider getPrincipalProvider() {
+        return principalProvider;
+    }
+
+    public void setPrincipalProvider(PrincipalProvider principalProvider) {
+        this.principalProvider = principalProvider;
+    }
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/diff.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/diff.txt?rev=1336237&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/diff.txt
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/diff.txt
Wed May  9 15:11:45 2012
@@ -0,0 +1,4 @@
+differences regarding jackrabbit 2.x implementation
+================================================================================
+
+- null credential login is no longer treated equivalent to GuestCredentials.
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/KernelPrincipalProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/KernelPrincipalProvider.java?rev=1336237&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/KernelPrincipalProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/KernelPrincipalProvider.java
Wed May  9 15:11:45 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.principal;
+
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * The {@code KernelPrincipalProvider} is a principal provider implementation
+ * that operates on data obtained from {@code MicroKernel} directly.
+ */
+public class KernelPrincipalProvider implements PrincipalProvider {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(KernelPrincipalProvider.class);
+
+
+    @Override
+    public Principal getPrincipal(final String principalName) {
+        // TODO
+        return new Principal() {
+            @Override
+            public String getName() {
+                return principalName;
+            }
+        };
+    }
+
+    @Override
+    public Set<Group> getGroupMembership(Principal principal) {
+        // TODO
+        return Collections.<Group>singleton(EveryonePrincipal.getInstance());
+    }
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
Wed May  9 15:11:45 2012
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.spi.se
 
 import java.security.Principal;
 import java.security.acl.Group;
-import java.util.Iterator;
+import java.util.Set;
 
 /**
  * PrincipalProvider... TODO
@@ -48,5 +48,5 @@ public interface PrincipalProvider {
      * @return an iterator returning all groups the given principal is member of.
      * @see java.security.acl.Group#isMember(java.security.Principal)
      */
-    Iterator<Group> getGroupMembership(Principal principal);
+    Set<Group> getGroupMembership(Principal principal);
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
Wed May  9 15:11:45 2012
@@ -22,12 +22,14 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.junit.Test;
 
+import javax.jcr.GuestCredentials;
+
 public class NamespaceMappingsTest {
 
     @Test
     public void testMappings() throws Exception {
         ContentRepository repository = new ContentRepositoryImpl();
-        ContentSession session = repository.login(null, "default");
+        ContentSession session = repository.login(new GuestCredentials(), "default");
         NamespaceMappings r = new NamespaceMappings(session);
 
         r.registerNamespace("p", "n");

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
Wed May  9 15:11:45 2012
@@ -38,20 +38,20 @@ public abstract class AbstractRepository
     private Session session;
 
     public void logout() throws RepositoryException {
-        Session session = getRepository().login();
+        Session cleanupSession = createAnonymousSession();
         try {
-            Node root = session.getRootNode();
+            Node root = cleanupSession.getRootNode();
             NodeIterator ns = root.getNodes();
             while (ns.hasNext()) {
                 ns.nextNode().remove();
             }
-            session.save();
+            cleanupSession.save();
         }
         finally {
-            session.logout();
+            cleanupSession.logout();
         }
 
-
+        // release session field
         if (session != null) {
             session.logout();
             session = null;
@@ -68,7 +68,7 @@ public abstract class AbstractRepository
 
     protected Session getSession() throws RepositoryException {
         if (session == null) {
-            session = getRepository().login(new GuestCredentials());
+            session = createAnonymousSession();
         }
         return session;
     }
@@ -81,4 +81,8 @@ public abstract class AbstractRepository
         return getSession().getProperty(path);
     }
 
+    protected Session createAnonymousSession() throws RepositoryException {
+        return getRepository().login(new GuestCredentials());
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
Wed May  9 15:11:45 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.jcr;
 import org.junit.After;
 import org.junit.Test;
 
+import javax.jcr.GuestCredentials;
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -37,7 +38,7 @@ public class CRUDTest extends AbstractRe
     @Test
     public void testCRUD() throws RepositoryException {
         Repository repository = getRepository();
-        Session session = repository.login();
+        Session session = createAnonymousSession();
         try {
             // Create
             Node hello = session.getRootNode().addNode("hello");

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java
Wed May  9 15:11:45 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.jcr;
 import org.junit.After;
 import org.junit.Test;
 
+import javax.jcr.GuestCredentials;
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -52,15 +53,15 @@ public class CompatibilityIssuesTest ext
     public void sessionIsolation() throws RepositoryException {
         Repository repository = getRepository();
 
-        Session session0 = repository.login();
+        Session session0 = createAnonymousSession();
         Node testNode = session0.getNode("/").addNode("testNode");
         testNode.setProperty("p1", 1);
         testNode.setProperty("p2", 1);
         session0.save();
         check(getSession());
 
-        Session session1 = repository.login();
-        Session session2 = repository.login();
+        Session session1 = createAnonymousSession();
+        Session session2 = createAnonymousSession();
 
         session1.getNode("/testNode").setProperty("p1", -1);
         check(session1);
@@ -70,7 +71,7 @@ public class CompatibilityIssuesTest ext
         check(session2);      // Throws on JR2, not on JR3
         session2.save();
 
-        Session session3 = repository.login();
+        Session session3 = createAnonymousSession();
         try {
             check(session3);  // Throws on JR3
             fail();

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Wed May  9 15:11:45 2012
@@ -26,6 +26,7 @@ import org.junit.Test;
 import util.NumberStream;
 
 import javax.jcr.Binary;
+import javax.jcr.GuestCredentials;
 import javax.jcr.Item;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
@@ -77,7 +78,7 @@ public class RepositoryTest extends Abst
 
     @Before
     public void setup() throws RepositoryException {
-        Session session = getRepository().login();
+        Session session = createAnonymousSession();
         ValueFactory valueFactory = session.getValueFactory();
         try {
             Node root = session.getRootNode();
@@ -117,7 +118,7 @@ public class RepositoryTest extends Abst
     @Test(expected = NoSuchWorkspaceException.class)
     public void loginInvalidWorkspace() throws RepositoryException {
         Repository repository = getRepository();
-        repository.login("invalid");
+        repository.login(new GuestCredentials(), "invalid");
     }
 
     @Ignore("WIP") // TODO implement workspace management
@@ -138,7 +139,7 @@ public class RepositoryTest extends Abst
     public void createDeleteWorkspace() throws RepositoryException {
         getSession().getWorkspace().createWorkspace("new");
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             String[] workspaces = session2.getWorkspace().getAccessibleWorkspaceNames();
             assertTrue(asList(workspaces).contains("new"));
@@ -151,7 +152,7 @@ public class RepositoryTest extends Abst
             session2.logout();
         }
 
-        Session session4 = getRepository().login();
+        Session session4 = createAnonymousSession();
         try {
             String[] workspaces = session4.getWorkspace().getAccessibleWorkspaceNames();
             assertFalse(asList(workspaces).contains("new"));
@@ -316,7 +317,7 @@ public class RepositoryTest extends Abst
         assertFalse(added.isModified());
         session.save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             assertTrue(session2.nodeExists(newNode));
             added = session2.getNode(newNode);
@@ -340,7 +341,7 @@ public class RepositoryTest extends Abst
         node.addNode(nodeName);
         session.save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             assertTrue(session2.nodeExists(newNode));
         }
@@ -384,7 +385,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi string", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi string");
             assertTrue(property.isMultiple());
@@ -415,7 +416,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi long", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi long");
             assertTrue(property.isMultiple());
@@ -446,7 +447,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi double", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi double");
             assertTrue(property.isMultiple());
@@ -477,7 +478,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi boolean", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi boolean");
             assertTrue(property.isMultiple());
@@ -508,7 +509,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi decimal", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi decimal");
             assertTrue(property.isMultiple());
@@ -541,7 +542,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi date", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi date");
             assertTrue(property.isMultiple());
@@ -572,7 +573,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi uri", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi uri");
             assertTrue(property.isMultiple());
@@ -603,7 +604,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi name", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi name");
             assertTrue(property.isMultiple());
@@ -634,7 +635,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi path", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi path");
             assertTrue(property.isMultiple());
@@ -689,7 +690,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi binary", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi binary");
             assertTrue(property.isMultiple());
@@ -730,7 +731,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi reference", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi reference");
             assertTrue(property.isMultiple());
@@ -771,7 +772,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi weak reference", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi weak reference");
             assertTrue(property.isMultiple());
@@ -794,7 +795,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi empty", values, PropertyType.BOOLEAN);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi empty");
             assertTrue(property.isMultiple());
@@ -814,7 +815,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi empty", values, PropertyType.BOOLEAN);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi empty");
             assertTrue(property.isMultiple());
@@ -837,7 +838,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi with null", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi with null");
             assertTrue(property.isMultiple());
@@ -880,7 +881,7 @@ public class RepositoryTest extends Abst
         assertFalse(property.isNew());
         property.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property2 = session2.getProperty(TEST_PATH + "/string");
             assertEquals("new value", property2.getString());
@@ -895,7 +896,7 @@ public class RepositoryTest extends Abst
         Node parentNode = getNode(TEST_PATH);
         addProperty(parentNode, "NaN", getSession().getValueFactory().createValue(Double.NaN));
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property2 = session2.getProperty(TEST_PATH + "/NaN");
             assertTrue(Double.isNaN(property2.getDouble()));
@@ -920,7 +921,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("multi string2", values);
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             Property property = session2.getProperty(TEST_PATH + "/multi string2");
             assertTrue(property.isMultiple());
@@ -940,7 +941,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("newProperty", "some value");
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();
         try {
             session2.getProperty(TEST_PATH + "/newProperty").setValue((String) null);
             session2.save();
@@ -949,7 +950,7 @@ public class RepositoryTest extends Abst
             session2.logout();
         }
 
-        Session session3 = getRepository().login();
+        Session session3 = createAnonymousSession();;
         try {
             assertFalse(session3.propertyExists(TEST_PATH + "/newProperty"));
         }
@@ -964,7 +965,7 @@ public class RepositoryTest extends Abst
         parentNode.setProperty("newProperty", "some value");
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();;
         try {
             session2.getProperty(TEST_PATH + "/newProperty").remove();
             session2.save();
@@ -973,7 +974,7 @@ public class RepositoryTest extends Abst
             session2.logout();
         }
 
-        Session session3 = getRepository().login();
+        Session session3 = createAnonymousSession();;
         try {
             assertFalse(session3.propertyExists(TEST_PATH + "/newProperty"));
         }
@@ -988,7 +989,7 @@ public class RepositoryTest extends Abst
         parentNode.addNode("newNode");
         parentNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();;
         try {
             session2.getNode(TEST_PATH + "/newNode").remove();
             assertTrue(session2.getNode(TEST_PATH).isModified());
@@ -998,7 +999,7 @@ public class RepositoryTest extends Abst
             session2.logout();
         }
 
-        Session session3 = getRepository().login();
+        Session session3 = createAnonymousSession();;
         try {
             assertFalse(session3.nodeExists(TEST_PATH + "/newNode"));
             assertFalse(session3.getNode(TEST_PATH).isModified());
@@ -1010,8 +1011,8 @@ public class RepositoryTest extends Abst
 
     @Test
     public void sessionSave() throws RepositoryException {
-        Session session1 = getRepository().login();
-        Session session2 = getRepository().login();
+        Session session1 = createAnonymousSession();;
+        Session session2 = createAnonymousSession();;
         try {
             // Add some items and ensure they are accessible through this session
             session1.getNode("/").addNode("node1");
@@ -1060,7 +1061,7 @@ public class RepositoryTest extends Abst
 
     @Test
     public void sessionRefresh() throws RepositoryException {
-        Session session = getRepository().login();
+        Session session = createAnonymousSession();;
         try {
             // Add some items and ensure they are accessible through this session
             session.getNode("/").addNode("node1");
@@ -1102,8 +1103,8 @@ public class RepositoryTest extends Abst
 
     @Test
     public void sessionRefreshFalse() throws RepositoryException {
-        Session session1 = getRepository().login();
-        Session session2 = getRepository().login();
+        Session session1 = createAnonymousSession();;
+        Session session2 = createAnonymousSession();;
         try {
             Node foo = session1.getNode("/foo");
             foo.addNode("added");
@@ -1123,8 +1124,8 @@ public class RepositoryTest extends Abst
 
     @Test
     public void sessionRefreshTrue() throws RepositoryException {
-        Session session1 = getRepository().login();
-        Session session2 = getRepository().login();
+        Session session1 = createAnonymousSession();;
+        Session session2 = createAnonymousSession();;
         try {
             Node foo = session1.getNode("/foo");
             foo.addNode("added");
@@ -1144,8 +1145,8 @@ public class RepositoryTest extends Abst
 
     @Test
     public void sessionIsolation() throws RepositoryException {
-        Session session1 = getRepository().login();
-        Session session2 = getRepository().login();
+        Session session1 = createAnonymousSession();;
+        Session session2 = createAnonymousSession();;
         try {
             session1.getRootNode().addNode("node1");
             session2.getRootNode().addNode("node2");
@@ -1169,8 +1170,8 @@ public class RepositoryTest extends Abst
 
     @Test
     public void saveRefreshConflict() throws RepositoryException {
-        Session session1 = getRepository().login();
-        Session session2 = getRepository().login();
+        Session session1 = createAnonymousSession();;
+        Session session2 = createAnonymousSession();;
         try {
             session1.getRootNode().addNode("node");
             session2.getRootNode().addNode("node");
@@ -1200,8 +1201,8 @@ public class RepositoryTest extends Abst
         getSession().getRootNode().addNode("node");
         getSession().save();
 
-        Session session1 = getRepository().login();
-        Session session2 = getRepository().login();
+        Session session1 = createAnonymousSession();;
+        Session session2 = createAnonymousSession();;
         try {
             session1.getNode("/node").remove();
             session2.getNode("/node").addNode("2");
@@ -1226,7 +1227,7 @@ public class RepositoryTest extends Abst
 
     @Test
     public void liveNodes() throws RepositoryException {
-        Session session = getRepository().login();
+        Session session = createAnonymousSession();;
         try {
             Node n1 = (Node) session.getItem(TEST_PATH);
             Node n2 = (Node) session.getItem(TEST_PATH);
@@ -1331,7 +1332,7 @@ public class RepositoryTest extends Abst
         testNode.setPrimaryType("nt:folder");
         getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();;
         try {
             testNode = session2.getNode(TEST_PATH);
             assertEquals("nt:folder", testNode.getPrimaryNodeType().getName());
@@ -1408,7 +1409,7 @@ public class RepositoryTest extends Abst
         testNode.addMixin("mix:test");
         testNode.getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();;
         try {
             mix = session2.getNode(TEST_PATH).getMixinNodeTypes();
             assertEquals(1, mix.length);
@@ -1421,7 +1422,7 @@ public class RepositoryTest extends Abst
         testNode.removeMixin("mix:test");
         testNode.getSession().save();
 
-        session2 = getRepository().login();
+        session2 = createAnonymousSession();;
         try {
             mix = session2.getNode(TEST_PATH).getMixinNodeTypes();
             assertEquals(0, mix.length);
@@ -1701,7 +1702,7 @@ public class RepositoryTest extends Abst
         assertTrue(added.isNew());
         getSession().save();
 
-        Session session2 = getRepository().login();
+        Session session2 = createAnonymousSession();;
         try {
             assertTrue(session2.propertyExists(propertyPath));
             Value value2 = session2.getProperty(propertyPath).getValue();

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Wed May  9 15:11:45 2012
@@ -49,7 +49,7 @@ public class QueryTest extends AbstractR
     @Test
     public void simple() throws RepositoryException {
         Repository repository = getRepository();
-        Session session = repository.login();
+        Session session = createAnonymousSession();
         try {
             Node hello = session.getRootNode().addNode("hello");
             hello.setProperty("id",  "1");

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java?rev=1336237&r1=1336236&r2=1336237&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/qom/QomTest.java
Wed May  9 15:11:45 2012
@@ -70,8 +70,7 @@ public class QomTest extends AbstractRep
 
     @Before
     public void before() throws RepositoryException {
-        Repository repository = getRepository();
-        Session session = repository.login();
+        Session session = getSession();
         vf = session.getValueFactory();
         QueryManager qm = session.getWorkspace().getQueryManager();
         f = qm.getQOMFactory();



Mime
View raw message