com.boylesoftware.cb2.util
Class PrincipalWithRoles

java.lang.Object
  extended bycom.boylesoftware.cb2.util.PrincipalWithRoles
All Implemented Interfaces:
java.security.Principal, java.io.Serializable

public class PrincipalWithRoles
extends java.lang.Object
implements java.security.Principal, java.io.Serializable

Simple implementation of Java's Principal interface, which adds a list of security roles attached to the principal.

Version:
$Id: PrincipalWithRoles.java,v 1.1 2004/04/04 20:13:45 levahim Exp $
Author:
Lev Himmelfarb
See Also:
Serialized Form

Constructor Summary
PrincipalWithRoles(java.lang.String name, java.util.Set roles)
          Constructs a principal.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Checks if this principal is the same as another.
 java.lang.String getName()
          Gets the principal's unique name.
 int hashCode()
          Returns the object's hash code.
 boolean isInRole(java.lang.String role)
          Checks if this principal plays the specified role.
 java.lang.String toString()
          Gets string representation of this principal.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrincipalWithRoles

public PrincipalWithRoles(java.lang.String name,
                          java.util.Set roles)
Constructs a principal.

Parameters:
name - the principal's unique name.
roles - collection of principal's roles, contains objects of String. Cannot be null.
Method Detail

getName

public java.lang.String getName()
Gets the principal's unique name.

Specified by:
getName in interface java.security.Principal
Returns:
the principal's name.

equals

public boolean equals(java.lang.Object obj)
Checks if this principal is the same as another. This implementation assumes that principal's are the same if the specified one is of class PrincipalWithRoles or derived and has equal name.

Specified by:
equals in interface java.security.Principal
Parameters:
obj - another principal.
Returns:
true if principals are the same.

hashCode

public int hashCode()
Returns the object's hash code. This implementation returns the principal name's hash code.

Specified by:
hashCode in interface java.security.Principal
Returns:
the object's hash code.

toString

public java.lang.String toString()
Gets string representation of this principal. This implementation returns the principal's name.

Specified by:
toString in interface java.security.Principal
Returns:
string representation of this principal.

isInRole

public boolean isInRole(java.lang.String role)
Checks if this principal plays the specified role. This implementation always returns true for role "user" and always false for role "nobody".

Parameters:
role - the role name.
Returns:
true if this principal plays the role.


Copyright © 2002,2003,2004 - Boyle Software, Inc.