mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-30 15:52:15 +00:00
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:
parent
4152df1225
commit
8713d4d52c
@ -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);
|
||||||
|
@ -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;
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user