jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1236819 - in /jackrabbit/trunk/jackrabbit-jcr-server: pom.xml src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java src/main/java/org/apache/jackrabbit/server/package-info.java
Date Fri, 27 Jan 2012 18:54:53 GMT
Author: jukka
Date: Fri Jan 27 18:54:53 2012
New Revision: 1236819

URL: http://svn.apache.org/viewvc?rev=1236819&view=rev
Log:
JCR-3222: Allow servlet filters to specify custom session providers

Extend SessionProviderImpl to support custom session providers made available through an request
attribute.

Export the org.apache.jackrabbit.server package to OSGi clients so they can implement the
SessionProvider interface.

Added:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/package-info.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/pom.xml
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/pom.xml?rev=1236819&r1=1236818&r2=1236819&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/pom.xml Fri Jan 27 18:54:53 2012
@@ -71,13 +71,8 @@
         <configuration>
           <instructions>
             <Export-Package>
-              !*
+              org.apache.jackrabbit.server
             </Export-Package>
-            <Private-Package>
-              org.apache.jackrabbit.server.*,
-              org.apache.jackrabbit.webdav.jcr.*,
-              org.apache.jackrabbit.webdav.simple
-            </Private-Package>
           </instructions>
         </configuration>
       </plugin>
@@ -208,7 +203,12 @@
       <version>1.6.0</version>
       <scope>provided</scope>
     </dependency>
-    
+    <dependency>
+      <groupId>biz.aQute</groupId>
+      <artifactId>bndlib</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java?rev=1236819&r1=1236818&r2=1236819&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
Fri Jan 27 18:54:53 2012
@@ -18,7 +18,10 @@ package org.apache.jackrabbit.server;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
@@ -34,7 +37,12 @@ import org.apache.jackrabbit.util.Text;
 import org.apache.jackrabbit.webdav.util.LinkHeaderFieldParser;
 
 /**
- * This Class implements a default session provider uses a credentials provider.
+ * This class implements a default session provider based on a given
+ * {@link CredentialsProvider credentials provider}. Additionally,
+ * since Jackrabbit 2.4, if another session provider is available as
+ * the "org.apache.jackrabbit.server.SessionProvider" request attribute,
+ * then that provider is asked first for a session before the default
+ * credential-based login mechanism is used.
  */
 public class SessionProviderImpl implements SessionProvider {
 
@@ -46,6 +54,15 @@ public class SessionProviderImpl impleme
     private CredentialsProvider cp;
 
     /**
+     * Map of sessions acquired from custom session providers looked up
+     * from request attributes. We need to keep track of such providers
+     * so we can route the {@link #releaseSession(Session)} call to the
+     * correct provider.
+     */
+    private final Map<Session, SessionProvider> externalSessions =
+            Collections.synchronizedMap(new HashMap<Session, SessionProvider>());
+
+    /**
      * Creates a new SessionProvider
      * 
      * @param cp
@@ -60,12 +77,26 @@ public class SessionProviderImpl impleme
     public Session getSession(HttpServletRequest request,
             Repository repository, String workspace) throws LoginException,
             RepositoryException, ServletException {
-        Credentials creds = cp.getCredentials(request);
-        Session s;
-        if (creds == null) {
-            s = repository.login(workspace);
-        } else {
-            s = repository.login(creds, workspace);
+        Session s = null;
+
+        // JCR-3222: Check if a custom session provider is available as a
+        // request attribute. If one is available, ask it first for a session.
+        Object object = request.getAttribute(SessionProvider.class.getName());
+        if (object instanceof SessionProvider) {
+            SessionProvider provider = (SessionProvider) object;
+            s = provider.getSession(request, repository, workspace);
+            if (s != null) {
+                externalSessions.put(s, provider);
+            }
+        }
+
+        if (s == null) {
+            Credentials creds = cp.getCredentials(request);
+            if (creds == null) {
+                s = repository.login(workspace);
+            } else {
+                s = repository.login(creds, workspace);
+            }
         }
 
         // extract information from Link header fields
@@ -86,7 +117,14 @@ public class SessionProviderImpl impleme
      * {@inheritDoc }
      */
     public void releaseSession(Session session) {
-        session.logout();
+        // JCR-3222: If the session was acquired from a custom session
+        // provider, we need to ask that provider to release the session.
+        SessionProvider provider = externalSessions.remove(session);
+        if (provider != null) {
+            provider.releaseSession(session);
+        } else {
+            session.logout();
+        }
     }
 
     // find first link relation for JCR User Data

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/package-info.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/package-info.java?rev=1236819&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/package-info.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/package-info.java
Fri Jan 27 18:54:53 2012
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+@aQute.bnd.annotation.Version("1.0")
+package org.apache.jackrabbit.server;

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message