org.mockejb
Class MockUser

java.lang.Object
  extended byorg.mockejb.MockUser
All Implemented Interfaces:
java.security.Principal

public class MockUser
extends java.lang.Object
implements java.security.Principal

Provides simple implementation of java.security.Principal. Also stores the roles for the principal. The only purpose of this class is to support two security-related methods on EJBContext, so the implementation is very simple.

Author:
Alexander Ananiev

Field Summary
static MockUser ANONYMOUS_USER
           
 
Constructor Summary
MockUser(java.lang.String name)
           
MockUser(java.lang.String name, java.lang.String role)
           
MockUser(java.lang.String name, java.lang.String[] roles)
           
 
Method Summary
 java.lang.String getName()
           
 boolean hasRole(java.lang.String role)
          Checks if the given role belongs to this user
 void setRole(java.lang.String role)
          Sets the role that this user has meaning that this user only has one role
 void setRoles(java.lang.String[] roles)
          Sets the roles that this user has
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.security.Principal
equals, hashCode
 

Field Detail

ANONYMOUS_USER

public static final MockUser ANONYMOUS_USER
Constructor Detail

MockUser

public MockUser(java.lang.String name)

MockUser

public MockUser(java.lang.String name,
                java.lang.String role)

MockUser

public MockUser(java.lang.String name,
                java.lang.String[] roles)
Method Detail

setRoles

public void setRoles(java.lang.String[] roles)
Sets the roles that this user has

Parameters:
roles - role names

setRole

public void setRole(java.lang.String role)
Sets the role that this user has meaning that this user only has one role

Parameters:
role - name of the role

hasRole

public boolean hasRole(java.lang.String role)
Checks if the given role belongs to this user

Parameters:
role - role to check
Returns:
true if this user has the given role

getName

public java.lang.String getName()
Specified by:
getName in interface java.security.Principal
See Also:
Principal.getName()

toString

public java.lang.String toString()
Specified by:
toString in interface java.security.Principal