Author: vtence Date: Tue Nov 30 05:40:34 2004 New Revision: 107004 URL: http://svn.apache.org/viewcvs?view=rev&rev=107004 Log: Added credential abstraction; improved string representation for debugging Added: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/ContainsCredentialsMatcher.java - copied, changed from r106210, incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java Removed: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.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/realm/PasswordCredential.java incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java
Added: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java?view=auto&rev=107004 ============================================================================== --- (empty file) +++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java Tue Nov 30 05:40:34 2004 @@ -0,0 +1,22 @@ +/* + * 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; + +public interface Credential +{ + Object getValue(); +} Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java&r1=107003&p2=incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java&r2=107004 ============================================================================== --- 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 Tue Nov 30 05:40:34 2004 @@ -47,9 +47,9 @@ m_credentials = new HashSet( credentials ); } - public boolean add( Object c ) + public boolean add( Object credential ) { - return m_credentials.add( c ); + return m_credentials.add( credential ); } /** @@ -103,6 +103,16 @@ Object credential = creds.m_credentials.iterator().next(); return credential; + } + + public boolean contains( Object credential ) + { + return m_credentials.contains( credential ); + } + + public boolean containsAll( CredentialSet credentials ) + { + return m_credentials.containsAll( credentials.elements() ); } public int size() Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java&r1=107003&p2=incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/realm/IdentityInUseException.java&r2=107004 ============================================================================== --- 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 Tue Nov 30 05:40:34 2004 @@ -37,6 +37,8 @@ public String getMessage() { - return "Credentials in use"; + final StringBuffer sb = new StringBuffer( "Credentials in use" ); + sb.append( ": ").append( m_identity ); + return sb.toString(); } } Copied: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/ContainsCredentialsMatcher.java (from r106210, incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java) Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/ContainsCredentialsMatcher.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java&r1=106210&p2=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/ContainsCredentialsMatcher.java&r2=107004 ============================================================================== --- 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/ContainsCredentialsMatcher.java Tue Nov 30 05:40:34 2004 @@ -21,18 +21,17 @@ /** * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> */ -public class UsernameCredentialMatcher implements CredentialsMatcher +public class ContainsCredentialsMatcher implements CredentialsMatcher { - private final UsernameCredential m_username; + private final CredentialSet m_credentials; - public UsernameCredentialMatcher( UsernameCredential username ) + public ContainsCredentialsMatcher( CredentialSet credentials ) { - m_username = username; + m_credentials = credentials; } public boolean matches( CredentialSet creds ) { - UsernameCredential username = (UsernameCredential) creds.getUniqueCredential( UsernameCredential.class ); - return username.equals( m_username ); + return creds.containsAll( m_credentials ); } } Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/PasswordCredential.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/PasswordCredential.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/PasswordCredential.java&r1=107003&p2=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/PasswordCredential.java&r2=107004 ============================================================================== --- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/PasswordCredential.java (original) +++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/PasswordCredential.java Tue Nov 30 05:40:34 2004 @@ -16,18 +16,23 @@ */ package org.apache.janus.authentication.realm; -import java.io.Serializable; +import org.apache.janus.authentication.Credential; /** * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Tence</a> */ -public class PasswordCredential implements Serializable +public class PasswordCredential implements Credential { private final String m_password; public PasswordCredential( String password ) { m_password = password; + } + + public Object getValue() + { + return m_password; } public boolean equals( Object o ) Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java&r1=107003&p2=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java&r2=107004 ============================================================================== --- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java (original) +++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredential.java Tue Nov 30 05:40:34 2004 @@ -16,18 +16,23 @@ */ package org.apache.janus.authentication.realm; -import java.io.Serializable; +import org.apache.janus.authentication.Credential; /** * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Tence</a> */ -public class UsernameCredential implements Serializable +public class UsernameCredential implements Credential { private final String m_username; public UsernameCredential( String name ) { m_username = name; + } + + public Object getValue() + { + return m_username; } public String getUsername() Deleted: /incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernameCredentialMatcher.java?view=auto&rev=107003 ============================================================================== Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java&r1=107003&p2=incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePasswordAuthentication.java&r2=107004 ============================================================================== --- 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 Tue Nov 30 05:40:34 2004 @@ -53,7 +53,7 @@ public CredentialsMatcher identify( CredentialSet credentials ) { - return new UsernameCredentialMatcher( ( UsernameCredential ) credentials.getUniqueCredential( UsernameCredential.class ) ); + return new ContainsCredentialsMatcher( credentials.getCredentials( UsernameCredential.class ) ); } } Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java?view=diff&rev=107004&p1=incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java&r1=107003&p2=incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java&r2=107004 ============================================================================== --- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java (original) +++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/testmodel/Groups.java Tue Nov 30 05:40:34 2004 @@ -18,24 +18,26 @@ import org.apache.janus.authentication.attribute.GroupPrincipal; +import java.security.Principal; + public class Groups { - public static GroupPrincipal canadians() + public static Principal canadians() { return new GroupPrincipal( "canadians" ); } - public static GroupPrincipal geeks() + public static Principal geeks() { return new GroupPrincipal( "geeks" ); } - public static GroupPrincipal men() + public static Principal men() { return new GroupPrincipal( "men" ); } - public static GroupPrincipal fruits() + public static Principal fruits() { return new GroupPrincipal( "fruits" ); }
