jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r159358 - in incubator/jackrabbit/trunk: applications/test/ src/conf/ src/java/org/apache/jackrabbit/core/ src/java/org/apache/jackrabbit/core/security/ src/test/org/apache/jackrabbit/core/ src/test/org/apache/jackrabbit/test/api/ xdocs/
Date Tue, 29 Mar 2005 09:34:15 GMT
Author: mreutegg
Date: Tue Mar 29 01:34:12 2005
New Revision: 159358

URL: http://svn.apache.org/viewcvs?view=rev&rev=159358
Log:
JCR-81: Implement anonymous login with credentials

Modified:
    incubator/jackrabbit/trunk/applications/test/jaas.config
    incubator/jackrabbit/trunk/src/conf/jaas.config
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryLoginTest.java
    incubator/jackrabbit/trunk/xdocs/firststeps.xml

Modified: incubator/jackrabbit/trunk/applications/test/jaas.config
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/jaas.config?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/jaas.config (original)
+++ incubator/jackrabbit/trunk/applications/test/jaas.config Tue Mar 29 01:34:12 2005
@@ -1,3 +1,3 @@
 Jackrabbit {
-  org.apache.jackrabbit.core.security.SimpleLoginModule required;
+  org.apache.jackrabbit.core.security.SimpleLoginModule required anonymousId="anonymous";
 };

Modified: incubator/jackrabbit/trunk/src/conf/jaas.config
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/conf/jaas.config?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/src/conf/jaas.config (original)
+++ incubator/jackrabbit/trunk/src/conf/jaas.config Tue Mar 29 01:34:12 2005
@@ -1,3 +1,3 @@
 Jackrabbit {
-  org.apache.jackrabbit.core.security.SimpleLoginModule required;
+  org.apache.jackrabbit.core.security.SimpleLoginModule required anonymousId="anonymous";
 };

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Tue
Mar 29 01:34:12 2005
@@ -750,7 +750,7 @@
         if (!wspInfos.containsKey(workspaceName)) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
-/*
+
         if (credentials == null) {
             // null credentials, obtain the identity of the already-authenticated
             // subject from access control context
@@ -761,6 +761,9 @@
             } catch (SecurityException se) {
                 throw new LoginException(se.getMessage());
             }
+            if (subject == null) {
+                throw new LoginException("No Subject associated with AccessControlContext");
+            }
             // create session
             try {
                 return createSession(subject, workspaceName);
@@ -769,7 +772,7 @@
                 throw new LoginException(ade.getMessage());
             }
         }
-*/
+
         // login through JAAS login context
         CredentialsCallbackHandler cbHandler =
                 new CredentialsCallbackHandler(credentials);
@@ -1036,7 +1039,8 @@
         /**
          * Returns the search manager for this workspace
          *
-         * @return the search manager for this workspace
+         * @return the search manager for this workspace, or <code>null</code>
+         *  if no <code>SearchManager</code>
          * @throws RepositoryException if the search manager could not be created
          */
         synchronized SearchManager getSearchManager() throws RepositoryException {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
Tue Mar 29 01:34:12 2005
@@ -39,6 +39,12 @@
 
     private static Logger log = Logger.getLogger(SimpleLoginModule.class);
 
+    /** Name of the anonymous user id option in the LoginModule configuration */
+    private static final String OPT_ANONYMOUS = "anonymousId";
+
+    /** The default user id for anonymous login */
+    private static final String DEFAULT_ANONYMOUS_ID = "anonymous";
+
     // initial state
     private Subject subject;
     private CallbackHandler callbackHandler;
@@ -52,6 +58,9 @@
     // the principals, i.e. the authenticated identities
     private final Set principals = new HashSet();
 
+    /** Id of an anonymous user login */
+    private String anonymousUserId = DEFAULT_ANONYMOUS_ID;
+
     /**
      * Constructor
      */
@@ -71,6 +80,10 @@
 
         // initialize any configured options
         //someOpt = "true".equalsIgnoreCase((String)options.get("someOpt"));
+        String userId = (String) options.get(OPT_ANONYMOUS);
+        if (userId != null) {
+            anonymousUserId = userId;
+        }
     }
 
     /**
@@ -106,14 +119,14 @@
                         // @todo implement simple username/password authentication
                     }
 
-                    // assume the user we authenticated is the UserPrincipal
-                    principals.add(new UserPrincipal(sc.getUserId()));
+                    if (anonymousUserId.equals(sc.getUserId())) {
+                        principals.add(new AnonymousPrincipal());
+                    } else {
+                        // else assume the user we authenticated is the UserPrincipal
+                        principals.add(new UserPrincipal(sc.getUserId()));
+                    }
                     authenticated = true;
                 }
-            } else {
-                // null credentials, assume AnonymousPrincipal
-                principals.add(new AnonymousPrincipal());
-                authenticated = true;
             }
         } catch (java.io.IOException ioe) {
             throw new LoginException(ioe.toString());

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
Tue Mar 29 01:34:12 2005
@@ -115,12 +115,4 @@
         }
         return repository;
     }
-
-    /**
-     * Returns <code>null</code> to indicate anonymous access.
-     * @return <code>null</code> to indicate anonymous access.
-     */
-    public Credentials getReadOnlyCredentials() {
-        return null;
-    }
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryLoginTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryLoginTest.java?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryLoginTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryLoginTest.java
Tue Mar 29 01:34:12 2005
@@ -108,21 +108,4 @@
             s.logout();
         }
     }
-
-    /**
-     * Tests if {@link javax.jcr.Repository#login(Credentials credentials, String workspaceName)}
-     * does return a session, i. e. not null.
-     */
-    public void testSignatureWorkspaceName()
-            throws RepositoryException {
-
-        Session s = repository.login(workspaceName);
-        try {
-            assertNotNull("Repository.login(String workspaceName) " +
-                    "must not return null",
-                    s);
-        } finally {
-            s.logout();
-        }
-    }
 }

Modified: incubator/jackrabbit/trunk/xdocs/firststeps.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/xdocs/firststeps.xml?view=diff&r1=159357&r2=159358
==============================================================================
--- incubator/jackrabbit/trunk/xdocs/firststeps.xml (original)
+++ incubator/jackrabbit/trunk/xdocs/firststeps.xml Tue Mar 29 01:34:12 2005
@@ -59,7 +59,7 @@
       
       RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
       Repository r = (Repository) ctx.lookup("repo");
-      Session session = r.login(new SimpleCredentials("anonymous", "".toCharArray()), null);
+      Session session = r.login(new SimpleCredentials("userid", "".toCharArray()), null);
       Node rn=session.getRootNode();
       
       System.out.println(rn.getPrimaryNodeType().getName());
@@ -136,11 +136,15 @@
      In addition to the repository configuration file, you also need to
      create a
      <a href="http://java.sun.com/security/jaas/doc/api.html">JAAS configuration</a>
-     file used for Jackrabbit login settings. The contents of simple
-     configuration file named <code>jaas.config</code> is shown below:
+     file used for Jackrabbit login settings. The contents of a simple
+     configuration file named <code>jaas.config</code> is shown below. The
+     configuration for the SimpleLoginModule also contains an optional module
+     option to configure the user id of the anonymous user with read-only access
+     to the repository. If the option is omitted the anoymous user id default to
+     'anonymous'.
      <source>
 Jackrabbit {
-org.apache.jackrabbit.core.security.SimpleLoginModule required debug=false;
+org.apache.jackrabbit.core.security.SimpleLoginModule required anonymousId="anonymous";
 };
      </source>
    </p>
@@ -198,7 +202,7 @@
       
       RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
       Repository r = (Repository) ctx.lookup("repo");
-      Session session = r.login(new SimpleCredentials("anonymous", "".toCharArray()), null);
+      Session session = r.login(new SimpleCredentials("userid", "".toCharArray()), null);
       Node rn=session.getRootNode();
       
       System.out.println(rn.getPrimaryNodeType().getName());
@@ -314,7 +318,7 @@
 
       RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
       Repository r = (Repository) ctx.lookup("repo");
-      Session session = r.login(new SimpleCredentials("anonymous", "".toCharArray()), null);
+      Session session = r.login(new SimpleCredentials("userid", "".toCharArray()), null);
       Node rn=session.getRootNode();
 
       System.out.println(rn.getPrimaryNodeType().getName());



Mime
View raw message