You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by vt...@apache.org on 2004/02/21 22:19:49 UTC
svn commit: rev 6815 - in incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication: . realm
Author: vtence
Date: Sat Feb 21 13:19:49 2004
New Revision: 6815
Modified:
incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java
incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
Log:
o Added defensive copy of credential set
Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java (original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java Sat Feb 21 13:19:49 2004
@@ -24,16 +24,31 @@
/**
* Declared final so we make sure no imposter implementation is possible.
- *
+ *
* @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
*/
public final class CredentialSet
{
- private final Set credentials;
+ private final Set m_credentials;
+
+ public CredentialSet()
+ {
+ this( Collections.EMPTY_SET );
+ }
+
+ public CredentialSet( CredentialSet credentials )
+ {
+ this( credentials.elements() );
+ }
public CredentialSet( Set credentials )
{
- this.credentials = new HashSet( credentials );
+ m_credentials = new HashSet( credentials );
+ }
+
+ public boolean add( Credential c )
+ {
+ return m_credentials.add( c );
}
/**
@@ -44,7 +59,7 @@
*/
public boolean isEmpty()
{
- return credentials.isEmpty();
+ return m_credentials.isEmpty();
}
/**
@@ -53,9 +68,9 @@
*
* @return an unmodifiable collection of all the credentials in this set.
*/
- public Collection elements()
+ public Set elements()
{
- return Collections.unmodifiableSet( credentials );
+ return Collections.unmodifiableSet( m_credentials );
}
/**
@@ -69,19 +84,19 @@
*/
public CredentialSet getCredentials( String type )
{
- final Set subSet = new HashSet();
- for ( Iterator it = credentials.iterator(); it.hasNext(); )
+ final CredentialSet subSet = new CredentialSet();
+ for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
{
final Credential c = (Credential) it.next();
if ( c.isOfType( type ) ) subSet.add( c );
}
- return new CredentialSet( subSet );
+ return subSet;
}
public int size()
{
- return credentials.size();
+ return m_credentials.size();
}
public boolean equals( Object o )
@@ -91,14 +106,14 @@
final CredentialSet credentialSet = (CredentialSet) o;
- if ( !credentials.equals( credentialSet.credentials ) ) return false;
+ if ( !m_credentials.equals( credentialSet.m_credentials ) ) return false;
return true;
}
public int hashCode()
{
- return credentials.hashCode();
+ return m_credentials.hashCode();
}
public String toString()
@@ -106,7 +121,7 @@
if ( isEmpty() ) return "{}";
StringBuffer sb = new StringBuffer( "{" );
- for ( Iterator it = credentials.iterator(); it.hasNext(); )
+ for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
{
Credential c = (Credential) it.next();
sb.append( c ).append( ", " );
Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/realm/DefaultRealm.java (original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/realm/DefaultRealm.java Sat Feb 21 13:19:49 2004
@@ -47,14 +47,18 @@
public boolean addIdentity( CredentialSet credentials )
{
- if ( !m_authenticationMethod.supports( credentials ) ) throw new IllegalArgumentException( "Credentials not supported by authentication method" );
+ if ( !m_authenticationMethod.supports( credentials ) )
+ {
+ throw new IllegalArgumentException(
+ "Credentials not supported by authentication method" );
+ }
if ( contains( credentials ) ) return false;
- m_identities.add( credentials );
+ m_identities.add( new CredentialSet( credentials ) );
return true;
}
- private boolean contains(CredentialSet credentials)
+ private boolean contains( CredentialSet credentials )
{
CredentialsMatcher criterion = m_authenticationMethod.matcher( credentials );
return search( criterion );
@@ -64,8 +68,8 @@
{
for ( Iterator it = m_identities.iterator(); it.hasNext(); )
{
- CredentialSet creds = (CredentialSet) it.next();
- if (criterion.matches( creds )) return true;
+ CredentialSet creds = (CredentialSet) it.next();
+ if ( criterion.matches( creds ) ) return true;
}
return false;