Authentication subclasses Principal, so it's directly usable by classes that want a Principal. No implementations need to change if they subclass AbstractAuthenticationToken, as it implements the one and only method required by Principal.

This commit is contained in:
Ben Alex 2004-05-04 07:35:41 +00:00
parent 4152df1225
commit 8713d4d52c
3 changed files with 9 additions and 1 deletions

View File

@ -15,6 +15,9 @@
package net.sf.acegisecurity; package net.sf.acegisecurity;
import java.security.Principal;
/** /**
* Represents an authentication request. * Represents an authentication request.
* *
@ -30,7 +33,7 @@ package net.sf.acegisecurity;
* @author Ben Alex * @author Ben Alex
* @version $Id$ * @version $Id$
*/ */
public interface Authentication { public interface Authentication extends Principal {
//~ Methods ================================================================ //~ Methods ================================================================
public void setAuthenticated(boolean isAuthenticated); public void setAuthenticated(boolean isAuthenticated);

View File

@ -27,6 +27,10 @@ import net.sf.acegisecurity.Authentication;
public abstract class AbstractAuthenticationToken implements Authentication { public abstract class AbstractAuthenticationToken implements Authentication {
//~ Methods ================================================================ //~ Methods ================================================================
public String getName() {
return this.getPrincipal().toString();
}
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof AbstractAuthenticationToken) { if (obj instanceof AbstractAuthenticationToken) {
AbstractAuthenticationToken test = (AbstractAuthenticationToken) obj; AbstractAuthenticationToken test = (AbstractAuthenticationToken) obj;

View File

@ -55,6 +55,7 @@ public class AbstractAuthenticationTokenTests extends TestCase {
"ROLE_TWO")}); "ROLE_TWO")});
assertEquals("Test", token.getPrincipal()); assertEquals("Test", token.getPrincipal());
assertEquals("Password", token.getCredentials()); assertEquals("Password", token.getCredentials());
assertEquals("Test", token.getName());
} }
public void testObjectsEquals() throws Exception { public void testObjectsEquals() throws Exception {