public class UserContext extends Object implements 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 FormConstructor and Description |
---|
UserContext()
Default public constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addProxyPrivilege(String privilege)
Gives the given privilege to all calls to hasPrivilege.
|
User |
authenticate(String username,
String password,
ContextDAO contextDAO)
Authenticate the user to this UserContext.
|
User |
becomeUser(String systemId)
Change current authentication to become another user.
|
Set<Role> |
getAllRoles()
Gets all the roles for the (un)authenticated user.
|
Set<Role> |
getAllRoles(User user)
Gets all the roles for a user.
|
User |
getAuthenticatedUser() |
Locale |
getLocale() |
Location |
getLocation() |
boolean |
hasPrivilege(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(String privilege)
Will remove one instance of privilege from the privileges that are
currently proxied
|
void |
setLocale(Locale locale) |
void |
setLocation(Location location) |
public User authenticate(String username, String password, ContextDAO contextDAO) throws ContextAuthenticationException
username
- String login namepassword
- String login passwordcontextDAO
- ContextDAO implementation to use for authenticationContextAuthenticationException
Context.authenticate(String,String)
public void refreshAuthenticatedUser()
getAuthenticatedUser()
User object.public User becomeUser(String systemId) throws ContextAuthenticationException
systemId
- ContextAuthenticationException
public User getAuthenticatedUser()
null
public boolean isAuthenticated()
public void logout()
public void addProxyPrivilege(String privilege)
try { Context.addProxyPrivilege("AAA"); Context.get*Service().methodRequiringAAAPrivilege(); } finally { Context.removeProxyPrivilege("AAA"); }
privilege
- to give to userspublic void removeProxyPrivilege(String privilege)
privilege
- Privilege to remove in string formpublic void setLocale(Locale locale)
locale
- new locale for this contextpublic Locale getLocale()
public Set<Role> getAllRoles() throws Exception
Exception
public Set<Role> getAllRoles(User user) throws Exception
user
- Exception
public boolean hasPrivilege(String privilege)
privilege
- public Location getLocation()
public void setLocation(Location location)
location
- the location to set toCopyright © 2018 OpenMRS LLC.. All Rights Reserved.