jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r744954 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/RepositoryImpl.java main/java/org/apache/jackrabbit/core/SessionImpl.java test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
Date Mon, 16 Feb 2009 16:10:16 GMT
Author: jukka
Date: Mon Feb 16 16:09:59 2009
New Revision: 744954

URL: http://svn.apache.org/viewvc?rev=744954&view=rev
Log:
JCR-1932: Session.getAttributes( ) call always returns an empty array

Added a protected SessionImpl.setAttribute() method to set the attributes of a session.

Use the method in RepositoryImpl.login() when a SimpleCredentials instance has been passed.

Added a test case for this.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=744954&r1=744953&r2=744954&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Mon Feb 16 16:09:59 2009
@@ -83,6 +83,7 @@
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
@@ -1409,9 +1410,17 @@
             // not preauthenticated -> try login with credentials
             AuthContext authCtx = getSecurityManager().getAuthContext(credentials, new Subject());
             authCtx.login();
-            // create session
-            return createSession(authCtx, workspaceName);
 
+            // create session, and add SimpleCredentials attributes (JCR-1932)
+            SessionImpl session = createSession(authCtx, workspaceName);
+            if (credentials instanceof SimpleCredentials) {
+                SimpleCredentials sc = (SimpleCredentials) credentials;
+                String[] names = sc.getAttributeNames();
+                for (int i = 0; i < names.length; i++) {
+                    session.setAttribute(names[i], sc.getAttribute(names[i]));
+                }
+            }
+            return session;
         } catch (SecurityException se) {
             throw new LoginException("Unable to access authentication information", se);
         } catch (javax.security.auth.login.LoginException le) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=744954&r1=744953&r2=744954&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Mon Feb 16 16:09:59 2009
@@ -493,6 +493,23 @@
     }
 
     /**
+     * Sets the named attribute. If the value is <code>null</code>, then
+     * the named attribute is removed.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1932">JCR-1932</a>
+     * @param name attribute name
+     * @param value attribute value
+     * @since Apache Jackrabbit 1.6
+     */
+    protected void setAttribute(String name, Object value) {
+        if (value != null) {
+            attributes.put(name, value);
+        } else {
+            attributes.remove(name);
+        }
+    }
+
+    /**
      * Retrieves the referenceable node with the given <code>UUID</code>.
      *
      * @param uuid uuid of the node to be retrieved

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java?rev=744954&r1=744953&r2=744954&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
Mon Feb 16 16:09:59 2009
@@ -21,6 +21,7 @@
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
@@ -48,4 +49,25 @@
             session.logout();
         }
     }
+
+    /**
+     * JCR-1932: Session.getAttributes( ) call always returns an empty array
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-1932">JCR-1932</a>
+     */
+    public void testSessionAttributes() throws RepositoryException {
+        SimpleCredentials credentials =
+            new SimpleCredentials("admin", "admin".toCharArray());
+        credentials.setAttribute("test", "attribute");
+        Session session = helper.getRepository().login(credentials);
+        try {
+            String[] names = session.getAttributeNames();
+            assertEquals(1, names.length);
+            assertEquals("test", names[0]);
+            assertEquals("attribute", session.getAttribute("test"));
+        } finally {
+            session.logout();
+        }
+    }
+
 }



Mime
View raw message