org.apache.click.servlet
Class MockPrincipal

java.lang.Object
  extended by org.apache.click.servlet.MockPrincipal
All Implemented Interfaces:
Principal

public class MockPrincipal
extends Object
implements Principal

Mock implementation of a user principal. This class also provides convenient methods for specifying the user principal roles.

Example usage with MockContext:

 MockContext mockContext = MockContext.initContext();

 // Create a new user principal with the roles "user" and "manager"
 MockPrincipal principal = new MockPrincipal("Bob", "user", "manager");

 // Set the user principal on the request object
 mockContext.getMockRequest().setUserPrincipal(principal); 

Example usage with MockContainer:

 MockContainer container = new MockContainer("c:/dev/myapp/web");

 // Create a new user principal with the roles "user" and "manager"
 MockPrincipal principal = new MockPrincipal("Bob", "user", "manager");

 // Set the user principal on the request object
 container.getRequest().setUserPrincipal(principal); 


Constructor Summary
MockPrincipal()
          Constructs a new MockPrincipal instance.
MockPrincipal(String name)
          Constructs a new MockPrincipal instance for the given name.
MockPrincipal(String name, Set<String> roles)
          Constructs a new MockPrincipal instance for the given name and roles.
MockPrincipal(String name, String... roles)
          Constructs a new MockPrincipal instance for the given name and roles.
 
Method Summary
 void addRoles(String... roles)
          Add the roles of this principal.
 String getName()
          Returns the name of this principal.
 Set<String> getRoles()
          Returns the roles of this principal.
 void setName(String name)
          Set the name of this principal.
 void setRoles(Set<String> roles)
          Sets the roles of this principal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.security.Principal
equals, hashCode, toString
 

Constructor Detail

MockPrincipal

public MockPrincipal()
Constructs a new MockPrincipal instance.


MockPrincipal

public MockPrincipal(String name)
Constructs a new MockPrincipal instance for the given name.

Parameters:
name - the name of the principal

MockPrincipal

public MockPrincipal(String name,
                     Set<String> roles)
Constructs a new MockPrincipal instance for the given name and roles.

Parameters:
name - the name of the principal
roles - the principal roles

MockPrincipal

public MockPrincipal(String name,
                     String... roles)
Constructs a new MockPrincipal instance for the given name and roles.

Parameters:
name - the name of the principal
roles - the principal roles
Method Detail

getName

public String getName()
Returns the name of this principal.

Specified by:
getName in interface Principal
Returns:
the name of this principal.

setName

public void setName(String name)
Set the name of this principal.

Parameters:
name - the name of the princpal

getRoles

public Set<String> getRoles()
Returns the roles of this principal.

Returns:
the roles of this principal.

setRoles

public void setRoles(Set<String> roles)
Sets the roles of this principal.

Parameters:
roles - set the roles of this principal.

addRoles

public void addRoles(String... roles)
Add the roles of this principal.

Parameters:
roles - set the roles of this principal.