org.openmrs.api.context
Class UserContext

java.lang.Object
  extended by org.openmrs.api.context.UserContext

public class UserContext
extends java.lang.Object

Represents an OpenMRS User Context which stores the current user information. Only one User may be authenticated within a UserContext at any given time. The UserContext should not be accessed directly, but rather used through the Context. This class should be kept light-weight. There is one instance of this class per user that is logged into the system.

See Also:
Context

Constructor Summary
UserContext()
          Default public constructor
 
Method Summary
 void addProxyPrivilege(java.lang.String privilege)
          Gives the given privilege to all calls to hasPrivilege.
 User authenticate(java.lang.String username, java.lang.String password, ContextDAO contextDAO)
          Authenticate the user to this UserContext.
 User becomeUser(java.lang.String systemId)
          Change current authentication to become another user.
 java.util.Set<Role> getAllRoles()
          Gets all the roles for the (un)authenticated user.
 java.util.Set<Role> getAllRoles(User user)
          Gets all the roles for a user.
 User getAuthenticatedUser()
           
 java.util.Locale getLocale()
           
 boolean hasPrivilege(java.lang.String privilege)
          Tests whether or not currently authenticated user has a particular privilege
 boolean isAuthenticated()
           
 void logout()
          logs out the "active" (authenticated) user within this UserContext
 void removeProxyPrivilege(java.lang.String privilege)
          Will remove one instance of privilege from the privileges that are currently proxied
 void setLocale(java.util.Locale locale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserContext

public UserContext()
Default public constructor

Method Detail

authenticate

public User authenticate(java.lang.String username,
                         java.lang.String password,
                         ContextDAO contextDAO)
                  throws ContextAuthenticationException
Authenticate the user to this UserContext.

Parameters:
username - String login name
password - String login password
ContextDAO - contextDAO implementation to use for authentication
Returns:
User that has been authenticated
Throws:
ContextAuthenticationException
See Also:
Context.authenticate(String,String)

becomeUser

public User becomeUser(java.lang.String systemId)
                throws ContextAuthenticationException
Change current authentication to become another user. (You can only do this if you're already authenticated as a superuser.)

Parameters:
systemId -
Returns:
The new user that this context has been set to. (null means no change was made)
Throws:
ContextAuthenticationException

getAuthenticatedUser

public User getAuthenticatedUser()
Returns:
"active" user who has been authenticated, otherwise null

isAuthenticated

public boolean isAuthenticated()
Returns:
true if user has been authenticated in this UserContext

logout

public void logout()
logs out the "active" (authenticated) user within this UserContext

See Also:
authenticate(java.lang.String, java.lang.String, org.openmrs.api.db.ContextDAO)

addProxyPrivilege

public void addProxyPrivilege(java.lang.String privilege)
Gives the given privilege to all calls to hasPrivilege. This method was visualized as being used as follows: Context.addProxyPrivilege("AAA"); Context.get*Service().methodRequiringAAAPrivilege(); Context.removeProxyPrivilege("AAA");

Parameters:
privilege - to give to users

removeProxyPrivilege

public void removeProxyPrivilege(java.lang.String privilege)
Will remove one instance of privilege from the privileges that are currently proxied

Parameters:
String - privilege

setLocale

public void setLocale(java.util.Locale locale)
Parameters:
locale - new locale for this context

getLocale

public java.util.Locale getLocale()
Returns:
current locale for this context

getAllRoles

public java.util.Set<Role> getAllRoles()
                                throws java.lang.Exception
Gets all the roles for the (un)authenticated user. Anonymous and Authenticated roles are appended if necessary

Returns:
all expanded roles for a user
Throws:
java.lang.Exception

getAllRoles

public java.util.Set<Role> getAllRoles(User user)
                                throws java.lang.Exception
Gets all the roles for a user. Anonymous and Authenticated roles are appended if necessary

Parameters:
user -
Returns:
all expanded roles for a user
Throws:
java.lang.Exception

hasPrivilege

public boolean hasPrivilege(java.lang.String privilege)
Tests whether or not currently authenticated user has a particular privilege

Parameters:
privilege -
Returns:
true if authenticated user has given privilege

OpenMRS-trunk

Generated May 29 2008 02:01 AM. NOTE - these libraries are in active development and subject to change