jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r805770 - in /jackrabbit/trunk: jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
Date Wed, 19 Aug 2009 12:08:36 GMT
Author: mduerig
Date: Wed Aug 19 12:08:36 2009
New Revision: 805770

URL: http://svn.apache.org/viewvc?rev=805770&view=rev
Log:
JCR-2265: AbstractReadableRepositoryService should pass credentials to createSessionInfo

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java?rev=805770&r1=805769&r2=805770&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
Wed Aug 19 12:08:36 2009
@@ -29,10 +29,10 @@
 import javax.jcr.Credentials;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.LoginException;
+import javax.jcr.PropertyType;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.PropertyType;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 
 import junit.framework.TestCase;
@@ -64,8 +64,8 @@
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.Subscription;
 import org.apache.jackrabbit.spi.commons.AbstractReadableRepositoryService;
-import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
+import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 
 /**
  * Abstract base class for jcr2spi tests. This class implements {@link RepositoryService}
@@ -73,6 +73,8 @@
  * individual methods as needed.
  */
 public abstract class AbstractJCR2SPITest extends TestCase implements RepositoryService {
+    private static final String DEFAULT_WSP = "default";
+
     protected RepositoryService repositoryService;
     protected RepositoryConfig config;
     protected Repository repository;
@@ -87,7 +89,7 @@
 
     protected RepositoryService getRepositoryService() throws RepositoryException, ParseException
{
         return new AbstractReadableRepositoryService(getDescriptors(), getNameSpaces(), getCndReader(),
-                getWspNames()) {
+                getWspNames(), DEFAULT_WSP) {
 
             @Override
             protected void checkCredentials(Credentials credentials, String workspaceName)
@@ -171,7 +173,7 @@
     }
 
     protected List<String> getWspNames() {
-        return Collections.singletonList("default");
+        return Collections.singletonList(DEFAULT_WSP);
     }
 
     protected RepositoryConfig getRepositoryConfig() {
@@ -445,7 +447,7 @@
             throws RepositoryException {
         return repositoryService.createConfiguration(sessionInfo, nodeId);
     }
-    
+
     //----------------------------------------------------------< Searching >---
 
     public String[] getSupportedQueryLanguages(SessionInfo sessionInfo) throws RepositoryException
{

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java?rev=805770&r1=805769&r2=805770&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
Wed Aug 19 12:08:36 2009
@@ -16,60 +16,61 @@
  */
 package org.apache.jackrabbit.spi.commons;
 
-import org.apache.jackrabbit.spi.Batch;
-import org.apache.jackrabbit.spi.SessionInfo;
-import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.LockInfo;
-import org.apache.jackrabbit.spi.EventFilter;
-import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.Subscription;
-import org.apache.jackrabbit.spi.EventBundle;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.spi.PropertyId;
-import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.ItemInfo;
-import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefReader;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.ValueFormatException;
 import javax.jcr.AccessDeniedException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Credentials;
 import javax.jcr.InvalidItemStateException;
-import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.LoginException;
 import javax.jcr.MergeException;
 import javax.jcr.NamespaceException;
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.RepositoryException;
 import javax.jcr.SimpleCredentials;
-import javax.jcr.query.InvalidQueryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFormatException;
 import javax.jcr.lock.LockException;
-import javax.jcr.version.VersionException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeTypeExistsException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.version.VersionException;
+
+import org.apache.jackrabbit.spi.Batch;
+import org.apache.jackrabbit.spi.EventBundle;
+import org.apache.jackrabbit.spi.EventFilter;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.ItemInfo;
+import org.apache.jackrabbit.spi.LockInfo;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QueryInfo;
+import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.Subscription;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
+import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
 
 /**
  * <code>AbstractReadableRepositoryService</code> provides an abstract base
@@ -109,6 +110,11 @@
     protected final List<String> wspNames;
 
     /**
+     * The name of the default workspace
+     */
+    protected final String defaulWsp;
+
+    /**
      * Creates a new <code>AbstractReadableRepositoryService</code>.
      *
      * @param descriptors the repository descriptors. Maps descriptor keys to
@@ -117,14 +123,21 @@
      *                    URIs.
      * @param cnd         a reader on the compact node type definition.
      * @param wspNames    a list of workspace names.
-     * @throws RepositoryException if the namespace mappings are invalid.
-     * @throws ParseException      if an error occurs while parsing the CND.
+     * @param defaultWsp  name of the default workspace
+     * @throws RepositoryException       if the namespace mappings are invalid.
+     * @throws ParseException            if an error occurs while parsing the CND.
+     * @throws IllegalArgumentException  if <code>defaultWsp</code> is <code>null</code>
      */
     public AbstractReadableRepositoryService(Map<String, QValue[]> descriptors,
                                              Map<String, String> namespaces,
                                              Reader cnd,
-                                             List<String> wspNames)
-            throws RepositoryException, ParseException {
+                                             List<String> wspNames,
+                                             String defaultWsp)
+            throws RepositoryException, ParseException, IllegalArgumentException {
+
+        if (defaultWsp == null) {
+            throw new IllegalArgumentException("Default workspace is null");
+        }
         this.descriptors = Collections.unmodifiableMap(new HashMap<String, QValue[]>(descriptors));
         for (Map.Entry<String, String> entry : namespaces.entrySet()) {
             this.namespaces.setMapping(entry.getKey(), entry.getValue());
@@ -134,6 +147,7 @@
             nodeTypeDefs.put(def.getName(), def);
         }
         this.wspNames = Collections.unmodifiableList(new ArrayList<String>(wspNames));
+        this.defaulWsp = defaultWsp;
     }
 
     //---------------------------< subclass responsibility >--------------------
@@ -147,67 +161,113 @@
     protected abstract QNodeDefinition createRootNodeDefinition()
             throws RepositoryException;
 
+    //---------------------< may be overwritten by subclasses>------------------
+
     /**
-     * Checks if the given <code>credentials</code> are valid.
+     * Checks if the given <code>credentials</code> are valid. This default
+     * implementation is empty thus allowing all credentials.
      *
      * @param credentials the credentials to check.
      * @param workspaceName the workspace to access.
      * @throws LoginException if the credentials are invalid.
      */
-    protected abstract void checkCredentials(Credentials credentials,
-                                             String workspaceName)
-            throws LoginException;
+    protected void checkCredentials(Credentials credentials, String workspaceName) throws
LoginException {
+        // empty
+    }
 
-    //---------------------< may be overwritten by subclasses>------------------
+    /**
+     * Checks whether the <code>workspaceName</code> is valid.
+     * @param workspaceName  name of the workspace to check
+     * @throws NoSuchWorkspaceException  if <code>workspaceName</code> is neither
in the
+     *   list of workspaces nor null (i.e. default workspace).
+     */
+    protected void checkWorkspace(String workspaceName) throws NoSuchWorkspaceException {
+        if (workspaceName != null && !wspNames.contains(workspaceName)) {
+            throw new NoSuchWorkspaceException(workspaceName);
+        }
+    }
 
     /**
-     * Checks the type of the <code>sessionInfo</code> instance. This default
-     * implementation checks if <code>sessionInfo</code> is of type
-     * {@link SessionInfoImpl}, otherwise throws a {@link RepositoryException}.
+     * Creates a session info instance for the given <code>credentials</code>
and
+     * <code>workspaceName</code>. This default implementation creates a
+     * {@link SessionInfoImpl} instance and sets the <code>userId</code> and
+     * workspaceName. The user <code>userId</code> is <code>null</code>
or the
+     * <code>userId</code> from <code>credentials</code> if it is
of type
+     * {@link SimpleCredentials}.
      *
-     * @param sessionInfo the session info to check.
-     * @throws RepositoryException if the given <code>sessionInfo</code> is not
-     *                             of the required type for this repository
-     *                             service implementation.
+     * @param credentials the credentials.
+     * @param workspaceName the name of the workspace to access.
+     * @return a session info instance for the given <code>credentials</code>
and
+     *         <code>workspaceName</code>.
+     * @throws RepositoryException
      */
-    protected void checkSessionInfo(SessionInfo sessionInfo)
+    protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName)
             throws RepositoryException {
-        if (sessionInfo instanceof SessionInfoImpl) {
-            return;
+
+        String userId = null;
+        if (credentials instanceof SimpleCredentials) {
+            userId = ((SimpleCredentials) credentials).getUserID();
         }
-        throw new RepositoryException("SessionInfo not of type "
-                + SessionInfoImpl.class.getName());
+
+        SessionInfoImpl s = new SessionInfoImpl();
+        s.setUserID(userId);
+        s.setWorkspacename(workspaceName);
+        return s;
     }
 
     /**
-     * Creates a session info instance for the given <code>userId</code> and
+     * Creates a session info instance for the given <code>sessionInfo</code>
and
      * <code>workspaceName</code>. This default implementation creates a
-     * {@link SessionInfoImpl} instance and sets the userId and workspaceName.
+     * {@link SessionInfoImpl} instance and sets the <code>userId</code> and
+     * workspaceName. The user <code>userId</code> is set to the return value
of
+     * {@link SessionInfo#getUserID()}.
      *
-     * @param userId the userId.
+     * @param sessionInfo the sessionInfo.
      * @param workspaceName the name of the workspace to access.
-     * @return a session info instance for the given <code>userId</code> and
+     * @return a session info instance for the given <code>credentials</code>
and
      *         <code>workspaceName</code>.
+     * @throws RepositoryException
      */
-    protected SessionInfo createSessionInfo(String userId,
-                                            String workspaceName) {
+    protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName)
+            throws RepositoryException {
+
+        String userId = sessionInfo.getUserID();
+
         SessionInfoImpl s = new SessionInfoImpl();
         s.setUserID(userId);
         s.setWorkspacename(workspaceName);
         return s;
     }
 
+    /**
+     * Checks the type of the <code>sessionInfo</code> instance. This default
+     * implementation checks if <code>sessionInfo</code> is of type
+     * {@link SessionInfoImpl}, otherwise throws a {@link RepositoryException}.
+     *
+     * @param sessionInfo the session info to check.
+     * @throws RepositoryException if the given <code>sessionInfo</code> is not
+     *                             of the required type for this repository
+     *                             service implementation.
+     */
+    protected void checkSessionInfo(SessionInfo sessionInfo)
+            throws RepositoryException {
+        if (sessionInfo instanceof SessionInfoImpl) {
+            return;
+        }
+        throw new RepositoryException("SessionInfo not of type "
+                + SessionInfoImpl.class.getName());
+    }
+
     //----------------------------< login >-------------------------------------
 
     /**
      * This default implementation does:
      * <ul>
      * <li>calls {@link #checkCredentials(Credentials, String)}</li>
-     * <li>checks if the given <code>workspaceName</code> is in
-     * {@link #wspNames} otherwise throws a {@link NoSuchWorkspaceException}.</li>
-     * <li>calls {@link #createSessionInfo(String, String)} with a <code>null</code>
-     * <code>userId</code> or the <code>userId</code> from <code>credentials</code>
-     * if it is of type {@link SimpleCredentials}.</li>
+     * <li>calls {@link #checkWorkspace(String)}</li>
+     * <li>calls {@link #createSessionInfo(Credentials, String)} passing
+     * <code>workspaceName</code> or the name of the default workspace if
+     * <code>null</code></li>.
      * </ul>
      * @param credentials the credentials for the login.
      * @param workspaceName the name of the workspace to log in.
@@ -219,26 +279,22 @@
     public SessionInfo obtain(Credentials credentials, String workspaceName)
             throws LoginException, NoSuchWorkspaceException, RepositoryException {
         checkCredentials(credentials, workspaceName);
-        if (!wspNames.contains(workspaceName)) {
-            throw new NoSuchWorkspaceException(workspaceName);
-        }
-        String userId = null;
-        if (credentials instanceof SimpleCredentials) {
-            userId = ((SimpleCredentials) credentials).getUserID();
-        }
-        return createSessionInfo(userId, workspaceName);
+        checkWorkspace(workspaceName);
+        return createSessionInfo(credentials, workspaceName == null ? defaulWsp : workspaceName);
     }
 
     /**
      * This default implementation returns the session info retuned by the call
-     * to {@link #createSessionInfo(String, String)} with the userId taken
-     * from the passed <code>sessionInfo</code>.
+     * to {@link #createSessionInfo(SessionInfo, String)} passing
+     * <code>workspaceName</code> or the name of the default workspace if
+     * <code>null</code></li>.
      */
     public SessionInfo obtain(SessionInfo sessionInfo, String workspaceName)
             throws LoginException, NoSuchWorkspaceException, RepositoryException {
-        return createSessionInfo(sessionInfo.getUserID(), workspaceName);
+        return createSessionInfo(sessionInfo, workspaceName == null ? defaulWsp : workspaceName);
     }
 
+
     /**
      * This default implementation returns the session info returned by the call
      * to {@link #obtain(Credentials, String)} with the workspaceName taken from
@@ -782,7 +838,7 @@
         throw new UnsupportedRepositoryOperationException();
 
     }
-    
+
     //-------------------------------< query >----------------------------------
 
     public String[] getSupportedQueryLanguages(SessionInfo sessionInfo) throws
@@ -792,7 +848,7 @@
     }
 
     public String[] checkQueryStatement(SessionInfo sessionInfo, String statement,
-                                    String language, Map namespaces) throws
+                                    String language, Map<String, String> namespaces)
throws
             InvalidQueryException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }



Mime
View raw message