public class UserContext
extends java.lang.Object
implements java.io.Serializable
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.Context,
Serialized Form| Constructor and Description |
|---|
UserContext()
Default public constructor
|
| Modifier and Type | Method and Description |
|---|---|
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() |
Location |
getLocation() |
java.lang.Integer |
getLocationId() |
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 |
refreshAuthenticatedUser()
Refresh the authenticated user object in 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) |
void |
setLocation(Location location) |
void |
setLocationId(java.lang.Integer locationId) |
public User authenticate(java.lang.String username, java.lang.String password, ContextDAO contextDAO) throws ContextAuthenticationException
username - String login namepassword - String login passwordcontextDAO - ContextDAO implementation to use for authenticationContextAuthenticationExceptionContext.authenticate(String,String)public void refreshAuthenticatedUser()
getAuthenticatedUser() User object.public User becomeUser(java.lang.String systemId) throws ContextAuthenticationException
systemId - ContextAuthenticationExceptionpublic User getAuthenticatedUser()
nullpublic boolean isAuthenticated()
public void logout()
public void addProxyPrivilege(java.lang.String privilege)
try {
Context.addProxyPrivilege("AAA");
Context.get*Service().methodRequiringAAAPrivilege();
}
finally {
Context.removeProxyPrivilege("AAA");
}
privilege - to give to userspublic void removeProxyPrivilege(java.lang.String privilege)
privilege - Privilege to remove in string formpublic void setLocale(java.util.Locale locale)
locale - new locale for this contextpublic java.util.Locale getLocale()
public java.util.Set<Role> getAllRoles() throws java.lang.Exception
java.lang.Exceptionpublic java.util.Set<Role> getAllRoles(User user) throws java.lang.Exception
user - java.lang.Exceptionpublic boolean hasPrivilege(java.lang.String privilege)
privilege - public java.lang.Integer getLocationId()
public void setLocationId(java.lang.Integer locationId)
locationId - locationId to setpublic Location getLocation()
public void setLocation(Location location)
location - the location to set toCopyright © 2018 OpenMRS Inc.. All Rights Reserved.