User: starksm
Date: 01/06/10 23:15:57
Added: src/main/org/jboss/security AnybodyPrincipal.java
NobodyPrincipal.java
Log:
Utility principal implementations
Revision Changes Path
1.1 jboss/src/main/org/jboss/security/AnybodyPrincipal.java
Index: AnybodyPrincipal.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security;
import java.security.Principal;
/** An implementation of Principal and Comparable that represents any role.
Any Principal or name of a Principal when compared to an AnybodyPrincipal
using {@link #equals(Object) equals} or {@link #compareTo(Object) compareTo}
will always be found equals to the AnybodyPrincipal.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class AnybodyPrincipal implements Comparable, Principal
{
public static final String ANYBODY = "<ANYBODY>";
public static final AnybodyPrincipal ANYBODY_PRINCIPAL = new AnybodyPrincipal();
public int hashCode()
{
return ANYBODY.hashCode();
}
/**
@return "<ANYBODY>"
*/
public String getName()
{
return ANYBODY;
}
public String toString()
{
return ANYBODY;
}
/** This method always returns 0 to indicate equality for any argument.
This is only meaningful when comparing against other Principal objects
or names of Principals.
@return true to indicate equality for any argument.
*/
public boolean equals(Object another)
{
return true;
}
/** This method always returns 0 to indicate equality for any argument.
This is only meaningful when comparing against other Principal objects
or names of Principals.
@return 0 to indicate equality for any argument.
*/
public int compareTo(Object o)
{
return 0;
}
}
1.1 jboss/src/main/org/jboss/security/NobodyPrincipal.java
Index: NobodyPrincipal.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.security;
import java.security.Principal;
/** An implementation of Principal and Comparable that represents no role.
Any Principal or name of a Principal when compared to an NobodyPrincipal
using {@link #equals(Object) equals} or {@link #compareTo(Object) compareTo}
will always be found not equal to the NobodyPrincipal.
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class NobodyPrincipal implements Comparable, Principal
{
public static final String NOBODY = "<NOBODY>";
public static final NobodyPrincipal NOBODY_PRINCIPAL = new NobodyPrincipal();
public int hashCode()
{
return NOBODY.hashCode();
}
/**
@return "<NOBODY>"
*/
public String getName()
{
return NOBODY;
}
public String toString()
{
return NOBODY;
}
/** This method always returns 0 to indicate equality for any argument.
This is only meaningful when comparing against other Principal objects
or names of Principals.
@return false to indicate inequality for any argument.
*/
public boolean equals(Object another)
{
return false;
}
/** This method always returns 1 to indicate inequality for any argument.
This is only meaningful when comparing against other Principal objects
or names of Principals.
@return 1 to indicate inequality for any argument.
*/
public int compareTo(Object o)
{
return 1;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development