org.jboss.security
Class NestablePrincipal

java.lang.Object
  extended by org.jboss.security.SimplePrincipal
      extended by org.jboss.security.NestablePrincipal
All Implemented Interfaces:
Serializable, Cloneable, Group, Principal

public class NestablePrincipal
extends SimplePrincipal
implements Group, Cloneable

An implementation of Group that allows that acts as a stack of Principals with a single Principal Group member active at any time. When one adds a Principal to a NestablePrincipal the Principal is pushed onto the active Princpal stack and any of the Group methods operate as though the Group contains only the Principal. When removing the Principal that corresponds to the active Principal, the active Principal is popped from the stack and the new active Principal is effectively 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 CallerPrincipal identity without destroying the current CallerPrincipal identity and roles.

Version:
$Revision: 1.2.26.4 $
Author:
Scott.Stark@jboss.org
See Also:
Serialized Form

Constructor Summary
NestablePrincipal(String name)
          Creates new NestablePrincipal with the given name
 
Method Summary
 boolean addMember(Principal user)
          Pushes the user onto the Principal stack and makes it the active Principal.
 Object clone()
           
 boolean isMember(Principal member)
          Returns true if the passed principal is a member of the group.
 Enumeration members()
          Returns an enumeration that contains the single active Principal.
 boolean removeMember(Principal user)
          Removes the first occurence of user from the Principal stack.
 
Methods inherited from class org.jboss.security.SimplePrincipal
equals, getName, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.security.Principal
equals, getName, hashCode, toString
 

Constructor Detail

NestablePrincipal

public NestablePrincipal(String name)
Creates new NestablePrincipal with the given name

Method Detail

members

public Enumeration members()
Returns an enumeration that contains the single active Principal.

Specified by:
members in interface Group
Returns:
an Enumeration of the single active Principal.

removeMember

public boolean removeMember(Principal user)
Removes the first occurence of user from the Principal stack.

Specified by:
removeMember in interface Group
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 user)
Pushes the user onto the Principal stack and makes it the active Principal.

Specified by:
addMember in interface Group
Returns:
true always.

isMember

public boolean isMember(Principal member)
Returns true if the passed principal is a member of the 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.

Specified by:
isMember in interface Group
Parameters:
member - the principal whose membership is to be checked.
Returns:
true if the principal is a member of this group, false otherwise.

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.