directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 57544 - in incubator/directory/janus/trunk/core: api/src/java/org/apache/janus/authentication api/src/java/org/apache/janus/authentication/realm impl/src/java/org/apache/janus/authentication/group impl/src/java/org/apache/janus/authentication/realm
Date Fri, 12 Nov 2004 21:57:14 GMT
Author: vtence
Date: Fri Nov 12 13:57:13 2004
New Revision: 57544

Added:
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/UnsupportedCredentialsException.java
Modified:
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/group/GroupPrincipal.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java
Log:
o Fixed bug where sub credential set contained class objects instead of instances o Made exceptions
more useful

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java
(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java
Fri Nov 12 13:57:13 2004
@@ -47,7 +47,7 @@
         m_credentials = new HashSet( credentials );
     }
 
-    public boolean add( Serializable c )
+    public boolean add( Object c )
     {
         return m_credentials.add( c );
     }
@@ -88,22 +88,21 @@
         final CredentialSet subSet = new CredentialSet();
         for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
         {
-            final Serializable credential = ( Serializable ) it.next();
-            if ( c.isInstance( credential ) ) subSet.add( c );
+            final Object credential = it.next();
+            if ( c.isInstance( credential ) ) subSet.add( credential );
         }
 
         return subSet;
     }
 
-    public Serializable getCredential( Class c )
+    public Object getUniqueCredential( Class c )
     {
-        for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
-        {
-            final Serializable credential = (Serializable ) it.next();
-            if ( c.isInstance( credential ) ) return credential;
-        }
+        CredentialSet creds = getCredentials( c );
+        if ( creds.isEmpty() ) throw new IllegalArgumentException( "No such credential: "
+ c.getName() );
+        if ( creds.size() > 1 ) throw new IllegalArgumentException( "Multiple matching
credentials: " + c.getName() );
 
-        throw new IllegalArgumentException( "No credential of class " + c.getName());
+        Object credential = creds.m_credentials.iterator().next();
+        return credential;
     }
 
     public int size()
@@ -114,7 +113,7 @@
     public boolean equals( Object o )
     {
         if ( this == o ) return true;
-        if ( !(o instanceof CredentialSet) ) return false;
+        if ( !( o instanceof CredentialSet ) ) return false;
 
         final CredentialSet credentialSet = ( CredentialSet ) o;
 
@@ -130,23 +129,15 @@
 
     public String toString()
     {
-        if ( isEmpty() ) return "{}";
-
         StringBuffer sb = new StringBuffer( "{" );
         for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
         {
             Serializable c = ( Serializable ) it.next();
-            sb.append( c ).append( ", " );
+            sb.append( c );
+            if ( it.hasNext() ) sb.append( ", " );
         }
-
-        removeTrailingSeparator( sb );
         sb.append( "}" );
 
         return sb.toString();
-    }
-
-    private void removeTrailingSeparator( StringBuffer sb )
-    {
-        sb.setLength( sb.length() - 2 );
     }
 }

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java
(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java
Fri Nov 12 13:57:13 2004
@@ -16,18 +16,27 @@
  */
 package org.apache.janus.authentication.realm;
 
+import org.apache.janus.authentication.CredentialSet;
+
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
 public class IdentityInUseException extends Exception
 {
-    public IdentityInUseException( String message )
+    private final CredentialSet m_identity;
+
+    public IdentityInUseException( CredentialSet identity )
+    {
+        m_identity = identity;
+    }
+
+    public CredentialSet getIdentity()
     {
-        super( message );
+        return m_identity;
     }
 
-    public IdentityInUseException( String message, Throwable cause )
+    public String getMessage()
     {
-        super( message, cause );
+        return "Credentials in use";
     }
 }

Added: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/UnsupportedCredentialsException.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/UnsupportedCredentialsException.java
Fri Nov 12 13:57:13 2004
@@ -0,0 +1,39 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.janus.authentication.realm;
+
+import org.apache.janus.authentication.CredentialSet;
+
+public class UnsupportedCredentialsException extends IllegalArgumentException
+{
+    private final CredentialSet m_credentials;
+
+    public UnsupportedCredentialsException( CredentialSet credentials )
+    {
+        m_credentials = credentials;
+    }
+
+    public CredentialSet getCredentials()
+    {
+        return m_credentials;
+    }
+
+    public String getMessage()
+    {
+        return "Credentials not supported by authentication method";
+    }
+}

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/group/GroupPrincipal.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/group/GroupPrincipal.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/group/GroupPrincipal.java
Fri Nov 12 13:57:13 2004
@@ -44,7 +44,7 @@
 
     public String toString()
     {
-        return "GroupPrincipal: " + super.toString() + "";
+        return "GroupPrincipal: " + super.toString();
     }
 
 }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
Fri Nov 12 13:57:13 2004
@@ -54,9 +54,9 @@
     {
         if ( !m_authenticationMethod.supports( credentials ) )
         {
-            throw new IllegalArgumentException( "Credentials not supported by authentication
method" );
+            throw new UnsupportedCredentialsException( credentials );
         }
-        if ( findIdentifiedMatch( credentials ) != null ) throw new IdentityInUseException(
"Credentials in use" );
+        if ( findIdentifiedMatch( credentials ) != null ) throw new IdentityInUseException(
credentials );
 
         m_identities.add( credentials );
     }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java
Fri Nov 12 13:57:13 2004
@@ -18,23 +18,21 @@
 
 import org.apache.janus.authentication.CredentialSet;
 
-import java.io.Serializable;
-
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
 public class UsernameCredentialMatcher implements CredentialsMatcher
 {
-    private final Serializable m_username;
+    private final UsernameCredential m_username;
 
-    public UsernameCredentialMatcher( Serializable username )
+    public UsernameCredentialMatcher( UsernameCredential username )
     {
         m_username = username;
     }
 
     public boolean matches( CredentialSet creds )
     {
-        Serializable username = creds.getCredential( UsernameCredential.class );
+        UsernameCredential username = (UsernameCredential) creds.getUniqueCredential( UsernameCredential.class
);
         return username.equals( m_username );
     }
 }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java
Fri Nov 12 13:57:13 2004
@@ -31,7 +31,7 @@
 
     public Principal principal( CredentialSet credentialSet )
     {
-        UsernameCredential username = (UsernameCredential ) credentialSet.getCredential(
UsernameCredential.class );
+        UsernameCredential username = (UsernameCredential) credentialSet.getUniqueCredential(
UsernameCredential.class );
         return new UsernamePrincipal( username.getUsername() );
     }
 
@@ -53,7 +53,7 @@
 
     public CredentialsMatcher identify( CredentialSet credentials )
     {
-        return new UsernameCredentialMatcher( credentials.getCredential( UsernameCredential.class
) );
+        return new UsernameCredentialMatcher( ( UsernameCredential ) credentials.getUniqueCredential(
UsernameCredential.class ) );
     }
 
 }

Mime
View raw message