Package org.jboss.security
Class NestableGroup
- java.lang.Object
-
- org.jboss.security.SimplePrincipal
-
- org.jboss.security.NestableGroup
-
- All Implemented Interfaces:
Serializable,Cloneable,Group,Principal
public class NestableGroup extends SimplePrincipal implements Group, Cloneable
An implementation of Group that allows that acts as a stack of Groups with a single Group member active at any time. When one adds a Group to a NestableGroup the Group is pushed onto the active Group stack and any of the Group methods operate as though the NestableGroup contains only the Group. When removing the Group that corresponds to the active Group, the active Group is popped from the stack and the new active Group is set to the new top of the stack. The typical usage of this class is when doing a JAAS LoginContext login to runAs a new Principal with a new set of roles that should be added without destroying the current identity and roles.- Version:
- $Revision$
- Author:
- Scott.Stark@jboss.org
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NestableGroup(String name)Creates new NestableGroup with the given name
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddMember(Principal group)Pushes the group onto the Group stack and makes it the active Group.Objectclone()booleanisMember(Principal member)Returns true if the passed principal is a member of the active group.Enumeration<Principal>members()Returns an enumeration that contains the single active Principal.booleanremoveMember(Principal user)Removes the first occurence of user from the Principal stack.StringtoString()-
Methods inherited from class org.jboss.security.SimplePrincipal
equals, getName, hashCode
-
-
-
-
Constructor Detail
-
NestableGroup
public NestableGroup(String name)
Creates new NestableGroup with the given name
-
-
Method Detail
-
members
public Enumeration<Principal> members()
Returns an enumeration that contains the single active Principal.
-
removeMember
public boolean removeMember(Principal user)
Removes the first occurence of user from the Principal stack.- Specified by:
removeMemberin interfaceGroup- Parameters:
user- the principal to remove from this group.- Returns:
- true if the principal was removed, or false if the principal was not a member.
-
addMember
public boolean addMember(Principal group) throws IllegalArgumentException
Pushes the group onto the Group stack and makes it the active Group.- Specified by:
addMemberin interfaceGroup- Parameters:
group- the instance of Group that contains the roles to set as the active Group.- Returns:
- true always.
- Throws:
IllegalArgumentException- thrown if group is not an instance of Group.
-
isMember
public boolean isMember(Principal member)
Returns true if the passed principal is a member of the active group. This method does a recursive search, so if a principal belongs to a group which is a member of this group, true is returned.
-
toString
public String toString()
- Specified by:
toStringin interfacePrincipal- Overrides:
toStringin classSimplePrincipal
-
clone
public Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
-