jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r908084 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/authentication/ test/java/org/apache/jackrabbit/core/security/authentication/
Date Tue, 09 Feb 2010 15:50:24 GMT
Author: angela
Date: Tue Feb  9 15:50:23 2010
New Revision: 908084

URL: http://svn.apache.org/viewvc?rev=908084&view=rev
Log:
minor improvement: javadoc, @Override annotations, log output, tests

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/DefaultLoginModule.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthentication.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java?rev=908084&r1=908083&r2=908084&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java
Tue Feb  9 15:50:23 2010
@@ -349,9 +349,8 @@
      * there is no principal set the login is considered as ignored.
      * <p/>
      * The implementation stores the principal associated to the UserID and all
-     * the Groups it is member of.
-     * An instance of (#link SimpleCredentials} containing only the UserID used
-     * to login is set to the Subject's public Credentials.
+     * the Groups it is member of with the Subject and in addition adds an
+     * instance of (#link SimpleCredentials} to the Subject's public credentials.
      *
      * @return true if this method succeeded, or false if this
      *         <code>LoginModule</code> should be ignored.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/DefaultLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/DefaultLoginModule.java?rev=908084&r1=908083&r2=908084&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/DefaultLoginModule.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/DefaultLoginModule.java
Tue Feb  9 15:50:23 2010
@@ -57,6 +57,7 @@
      *
      * @see AbstractLoginModule#doInit(CallbackHandler, Session, Map)
      */
+    @Override
     protected void doInit(CallbackHandler callbackHandler, Session session, Map options)
throws LoginException {
         if (!(session instanceof SessionImpl)) {
             throw new LoginException("Unable to initialize LoginModule: SessionImpl expected.");
@@ -79,6 +80,7 @@
      * @return a user principal or <code>null</code>.
      * @see AbstractLoginModule#getPrincipal(Credentials)
      */
+    @Override
     protected Principal getPrincipal(Credentials credentials) {
         Principal principal = null;
         String userId = getUserID(credentials);
@@ -98,6 +100,7 @@
     /**
      * @see AbstractLoginModule#getAuthentication(Principal, Credentials)
      */
+    @Override
     protected Authentication getAuthentication(Principal principal, Credentials creds) throws
RepositoryException {
         if (user != null) {
             Authentication authentication = new SimpleCredentialsAuthentication(user);
@@ -124,6 +127,7 @@
      *                                       if credentials don't allow to impersonate to
principal
      * @see AbstractLoginModule#impersonate(Principal, Credentials)
      */
+    @Override
     protected boolean impersonate(Principal principal, Credentials credentials)
             throws RepositoryException, FailedLoginException {
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthentication.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthentication.java?rev=908084&r1=908083&r2=908084&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthentication.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthentication.java
Tue Feb  9 15:50:23 2010
@@ -27,13 +27,10 @@
 import java.security.NoSuchAlgorithmException;
 
 /**
- * This {@link Authentication} implementation handles all
+ * This <code>Authentication</code> implementation compairs
  * {@link javax.jcr.SimpleCredentials SimpleCredentials} stored
- * for a given {@link org.apache.jackrabbit.api.security.user.User#getCredentials() User}.<br>
- * For verification the <code>SimpleCredentials</code>
- * {@link javax.jcr.SimpleCredentials#getUserID() UserID} and
- * {@link javax.jcr.SimpleCredentials#getPassword() Password} are tested.
- * If both are equal to the ones stored at the User, verification succeeded.
+ * for a given {@link org.apache.jackrabbit.api.security.user.User#getCredentials() User}
+ * to the credentials passed to {@link #authenticate(Credentials)}.
  *
  * @see org.apache.jackrabbit.core.security.authentication.Authentication
  * @see javax.jcr.SimpleCredentials
@@ -45,9 +42,9 @@
     private final CryptedSimpleCredentials creds;
 
     /**
-     * Create an Authentication for this User
+     * Create a new <code>Authentication</code> instance for the given <code>User</code>.
      *
-     * @param user to create the Authentication for
+     * @param user to create the Authentication.
      * @throws javax.jcr.RepositoryException If an error occurs.
      */
     SimpleCredentialsAuthentication(User user) throws RepositoryException {
@@ -73,10 +70,10 @@
      * This Authentication is able to handle the validation of SimpleCredentials.
      *
      * @param credentials to test
-     * @return <code>true</code> if the given Credentials are of type
-     *         {@link javax.jcr.SimpleCredentials SimpleCredentials} and if the
-     *         <code>User</code> used to construct this <code>Autentication</code>
-     *         has any SimpleCredentials
+     * @return <code>true</code> if the specified Credentials are
+     * <code>SimpleCredentials</code> and if the <code>User</code>
used to
+     * construct this instance provides credentials that can be compared to
+     * <code>SimpleCredentials</code>.
      * @see Authentication#canHandle(Credentials)
      */
     public boolean canHandle(Credentials credentials) {
@@ -84,16 +81,18 @@
     }
 
     /**
-     * Compairs any of the <code>SimpleCredentials</code> of the <code>User</code>
-     * with the one given.<br>
-     * If both, UserID and Password of the credentials are equal, the authentication
-     * succeded and <code>true</code> is returned;
+     * Compairs the
+     * {@link org.apache.jackrabbit.api.security.user.User#getCredentials() Credentials}
obtained from the <code>User</code>
+     * with the specified <code>credentials</code>.<br>
+     * If the specified <code>credentials</code> are an instance of
+     * <code>SimpleCredentials</code> and match the user's credentials this
+     * method returns <code>true</code>; otherwise <code>false</code>.
      *
      * @param credentials Credentials to be used for the authentication.
-     * @return true if the given Credentials' UserID/Password pair match any
-     * of the credentials attached to the user this SimpleCredentialsAuthentication has
-     * been built for.
-     * @throws RepositoryException
+     * @return true if the given Credentials' UserID/Password pair match
+     * the credentials attached to the user this SimpleCredentialsAuthentication
+     * has been built for.
+     * @throws RepositoryException If an error occurs.
      */
     public boolean authenticate(Credentials credentials) throws RepositoryException {
         if (!(credentials instanceof SimpleCredentials)) {
@@ -104,9 +103,9 @@
                 return true;
             }
         } catch (NoSuchAlgorithmException e) {
-            log.debug("Failed to verify Credentials with {}: {} -> test next", credentials.toString(),
e);
+            log.debug("Failed to verify Credentials with {}: {}.", credentials.toString(),
e);
         } catch (UnsupportedEncodingException e) {
-            log.debug("Failed to verify Credentials with {}: {} -> test next", credentials.toString(),
e);
+            log.debug("Failed to verify Credentials with {}: {}.", credentials.toString(),
e);
         }
         return false;
     }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java?rev=908084&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
Tue Feb  9 15:50:23 2010
@@ -0,0 +1,183 @@
+/*
+ * 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.core.security.authentication;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.Impersonation;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Credentials;
+import javax.jcr.RepositoryException;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+import java.security.Principal;
+import java.util.Iterator;
+
+/**
+ * <code>SimpleCredentialsAuthenticationTest</code>...
+ */
+public class SimpleCredentialsAuthenticationTest extends AbstractJCRTest {
+
+    private static final Credentials creds = new Credentials(){};
+    private static final SimpleCredentials simpleAA = new SimpleCredentials("a", "a".toCharArray());
+    private static final SimpleCredentials simpleBB = new SimpleCredentials("b", "b".toCharArray());
+    private static final SimpleCredentials simpleAB = new SimpleCredentials("a", "b".toCharArray());
+    private static final SimpleCredentials simpleNull = new SimpleCredentials(null, new char[0]);
+    private static final SimpleCredentials simpleEmpty = new SimpleCredentials("", new char[0]);
+
+    private User user;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (superuser instanceof JackrabbitSession) {
+            String userID = superuser.getUserID();
+            user = (User) ((JackrabbitSession) superuser).getUserManager().getAuthorizable(userID);
+        } else {
+            throw new NotExecutableException();
+        }
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testCanHandle() throws RepositoryException {
+        Authentication a = new SimpleCredentialsAuthentication(user);
+        assertFalse(a.canHandle(null));
+        assertFalse(a.canHandle(creds));
+        assertTrue(a.canHandle(simpleEmpty));
+        assertTrue(a.canHandle(simpleNull));
+
+
+        a = new SimpleCredentialsAuthentication(new DummyUserImpl(null));
+        assertFalse(a.canHandle(null));
+        assertFalse(a.canHandle(creds));
+        assertFalse(a.canHandle(simpleEmpty));
+
+        a = new SimpleCredentialsAuthentication(new DummyUserImpl(creds));
+        assertFalse(a.canHandle(null));
+        assertFalse(a.canHandle(creds));
+        assertFalse(a.canHandle(simpleEmpty));
+
+        a = new SimpleCredentialsAuthentication(new DummyUserImpl(simpleAA));
+        assertFalse(a.canHandle(null));
+        assertFalse(a.canHandle(creds));
+        assertTrue(a.canHandle(simpleEmpty));
+        assertTrue(a.canHandle(simpleNull));
+        assertTrue(a.canHandle(simpleAB));
+    }
+
+    public void testAuthenticate() throws RepositoryException {
+        Authentication a = new SimpleCredentialsAuthentication(user);
+        assertFalse(a.authenticate(simpleEmpty));
+        assertFalse(a.authenticate(simpleNull));
+        assertFalse(a.authenticate(simpleAA));
+
+        a = new SimpleCredentialsAuthentication(new DummyUserImpl(null));
+        assertFalse(a.authenticate(simpleEmpty));
+        assertFalse(a.authenticate(simpleAA));
+
+        a = new SimpleCredentialsAuthentication(new DummyUserImpl(creds));
+        assertFalse(a.authenticate(simpleEmpty));
+        assertFalse(a.authenticate(simpleAA));
+
+        a = new SimpleCredentialsAuthentication(new DummyUserImpl(simpleAA));
+        assertFalse(a.authenticate(simpleEmpty));
+        assertFalse(a.authenticate(simpleBB));
+        assertFalse(a.authenticate(simpleAB));
+        assertTrue(a.authenticate(simpleAA));
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Internal class used for tests.
+     */
+    private class DummyUserImpl implements User {
+
+        private final Credentials creds;
+
+        private DummyUserImpl(Credentials creds) {
+            this.creds = creds;
+        }
+
+        public boolean isAdmin() {
+            return false;
+        }
+
+        public Credentials getCredentials() throws RepositoryException {
+            return creds;
+        }
+
+        public Impersonation getImpersonation() throws RepositoryException {
+            return null;
+        }
+
+        public void changePassword(String password) throws RepositoryException {
+        }
+
+        public String getID() throws RepositoryException {
+            return null;
+        }
+
+        public boolean isGroup() {
+            return false;
+        }
+
+        public Principal getPrincipal() throws RepositoryException {
+            return null;
+        }
+
+        public Iterator<Group> declaredMemberOf() throws RepositoryException {
+            return null;
+        }
+
+        public Iterator<Group> memberOf() throws RepositoryException {
+            return null;
+        }
+
+        public void remove() throws RepositoryException {
+        }
+
+        public Iterator<String> getPropertyNames() throws RepositoryException {
+            return null;
+        }
+
+        public boolean hasProperty(String name) throws RepositoryException {
+            return false;
+        }
+
+        public void setProperty(String name, Value value) throws RepositoryException {
+        }
+
+        public void setProperty(String name, Value[] value) throws RepositoryException {
+        }
+
+        public Value[] getProperty(String name) throws RepositoryException {
+            return new Value[0];
+        }
+
+        public boolean removeProperty(String name) throws RepositoryException {
+            return false;
+        }
+    }
+}
+

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/SimpleCredentialsAuthenticationTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/TestAll.java?rev=908084&r1=908083&r2=908084&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authentication/TestAll.java
Tue Feb  9 15:50:23 2010
@@ -28,6 +28,7 @@
 
         suite.addTestSuite(GuestLoginTest.class);
         suite.addTestSuite(NullLoginTest.class);
+        suite.addTestSuite(SimpleCredentialsAuthenticationTest.class);
         suite.addTestSuite(CryptedSimpleCredentialsTest.class);
 
         return suite;



Mime
View raw message