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 Form| Constructor and Description |
|---|
UserContext(AuthenticationScheme authenticationScheme)
Creates a user context based on the provided auth. scheme.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addProxyPrivilege(String privilege)
Gives the given privilege to all calls to hasPrivilege.
|
Authenticated |
authenticate(Credentials credentials)
Authenticate user with the provided credentials.
|
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() |
protected Integer |
getDefaultLocationId(User user) |
Locale |
getLocale() |
Location |
getLocation() |
Integer |
getLocationId() |
boolean |
hasPrivilege(String privilege)
Tests whether 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) |
void |
setLocationId(Integer locationId) |
public UserContext(AuthenticationScheme authenticationScheme)
authenticationScheme - The auth. scheme that applies for this user context.public Authenticated authenticate(Credentials credentials) throws ContextAuthenticationException
Context.getAuthenticationScheme().credentials - The credentials to use to authenticateContextAuthenticationException - if authentication failspublic void refreshAuthenticatedUser()
getAuthenticatedUser() User object.public User becomeUser(String systemId) throws ContextAuthenticationException
systemId - ContextAuthenticationExceptionpublic User getAuthenticatedUser()
nullpublic 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
Exceptionpublic Set<Role> getAllRoles(User user) throws Exception
user - Exceptionpublic boolean hasPrivilege(String privilege)
privilege - public Integer getLocationId()
public void setLocationId(Integer locationId)
locationId - locationId to setpublic Location getLocation()
public void setLocation(Location location)
location - the location to set toCopyright © 2024 OpenMRS Inc.. All rights reserved.