Package org.openbravo.dal.core
Class OBContext
- java.lang.Object
-
- org.openbravo.dal.core.OBContext
-
- All Implemented Interfaces:
Serializable
,OBNotSingleton
,OBProvidable
public class OBContext extends Object implements OBNotSingleton, Serializable
Models the context in which Data Access Layer actions are executed. Contains the user, the client and the allowed organizations. This class contains specific logic to compute the allowed organizations and clients for both read and write access. The OBContext instance is made available to other threads through the static ThreadLocal and the getInstance method. The OBContext can be serialized as part of the Tomcat persistent session mechanism.- Author:
- mtaal
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONTEXT_PARAM
-
Constructor Summary
Constructors Constructor Description OBContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addWritableOrganization(String orgId)
Adds a new organization for which write access is allowed.static void
clearAdminModeStack()
Clears the admin context stack.static OBContext
createOBContext(String userId)
Creates the context without setting the context in the thread.boolean
doAccessLevelCheck()
Defines whether entity check should or not compare entity's access level with role's user level in order to completely prevent access to that entity.boolean
doOrgClientAccessCheck()
static void
enableAsAdminContext()
Deprecated.usesetAdminMode()
AcctSchemaStructureProvider
getAcctSchemaStructureProvider()
AcctSchemaStructureProvider
getAcctSchemaStructureProvider(String clientId)
Client
getCurrentClient()
Organization
getCurrentOrganization()
Set<String>
getDeactivatedOrganizations()
EntityAccessChecker
getEntityAccessChecker()
Language
getLanguage()
static OBContext
getOBContext()
Returns the OBContext currently set in the thread.OrganizationStructureProvider
getOrganizationStructureProvider()
OrganizationStructureProvider
getOrganizationStructureProvider(String clientId)
String[]
getReadableClients()
String[]
getReadableOrganizations()
Role
getRole()
User
getUser()
String
getUserLevel()
Warehouse
getWarehouse()
Set<String>
getWritableOrganizations()
static boolean
hasTranslationInstalled()
boolean
initialize(String userId)
boolean
initialize(String userId, String roleId, String clientId, String orgId)
boolean
isAdminContext()
boolean
isInAdministratorMode()
boolean
isInCrossOrgAdministratorMode()
boolean
isInitialized()
boolean
isNewUI()
boolean
isPortalRole()
static boolean
isRightToLeft()
boolean
isRTL()
boolean
isTranslationInstalled()
boolean
isWebServiceEnabled()
void
removeFromWritableOrganization(String orgId)
void
removeWritableOrganization(String orgId)
static void
resetAsAdminContext()
Deprecated.static void
restorePreviousCrossOrgReferenceMode()
Used to restore the previous privileges after enabling Cross Organization Reference Administrator privileges by callingsetCrossOrgReferenceAdminMode()
.static void
restorePreviousMode()
Is used to restore the previous privileges after enabling Administrator privileges by callingsetAdminMode()
.static void
setAdminContext()
Deprecated.usesetAdminMode()
static void
setAdminMode()
Let's the current user run with Administrator privileges.static void
setAdminMode(boolean doOrgClientAccessCheck)
Let's the current user run with Administrator privileges.static void
setAdminTraceSize(int s)
Sets the size of stack trace to display in case of logging unbalanced set/restore admin modes callsvoid
setCheckAccessLevel(boolean checkAccessLevel)
static void
setCrossOrgReferenceAdminMode()
Cross Organization Reference Administrator mode allows to create references from an object to another one that it is not in the same Organization's natural tree.void
setCurrentClient(Client currentClient)
void
setCurrentOrganization(Organization currentOrganization)
boolean
setFromRequest(javax.servlet.http.HttpServletRequest request)
Sets the OBContext using the information stored in the HttpSessionboolean
setInAdministratorMode(boolean inAdministratorMode)
Deprecated.usesetAdminMode()
andrestorePreviousMode()
.void
setInitialized(boolean isInitialized)
void
setLanguage(Language language)
void
setNewUI(boolean newUI)
static void
setOBContext(String userId)
Creates the context using the userId and sets it in the thread (as a ThreadLocal).static void
setOBContext(String userId, String roleId, String clientId, String orgId)
Creates the context using the userId, roleId, clientId, orgId and sets it in the thread (as ThreadLocal).static void
setOBContext(String userId, String roleId, String clientId, String orgId, String languageCode)
Creates the context using the userId, roleId, clientId, orgId and sets it in the thread (as ThreadLocal).static void
setOBContext(String userId, String roleId, String clientId, String orgId, String languageCode, String warehouseId)
Creates the context using the userId, roleId, clientId, orgId and sets it in the thread (as ThreadLocal).static void
setOBContext(javax.servlet.http.HttpServletRequest request)
Sets the OBContext through the information stored in the http session of the request (mainly the authenticated user).static void
setOBContext(OBContext obContext)
Set the context in the thread, this context will then be used by the Data Access Layer internals.static void
setOBContextInSession(javax.servlet.http.HttpServletRequest request, OBContext context)
Sets the passed OBContext in the http session.void
setReadableClients(Role role)
Computes the clients allowed for read access using the user level and the client of the role.void
setRole(Role role)
void
setRTL(boolean isRTL)
void
setUser(User user)
void
setUserLevel(String userLevel)
void
setWarehouse(Warehouse warehouse)
String
toString()
-
-
-
Field Detail
-
CONTEXT_PARAM
public static final String CONTEXT_PARAM
- See Also:
- Constant Field Values
-
-
Method Detail
-
isRightToLeft
public static boolean isRightToLeft()
- Returns:
- true if the current language is a RTL language, false in other cases
-
hasTranslationInstalled
public static boolean hasTranslationInstalled()
-
setAdminContext
@Deprecated public static void setAdminContext()
Deprecated.usesetAdminMode()
-
enableAsAdminContext
@Deprecated public static void enableAsAdminContext()
Deprecated.usesetAdminMode()
-
setAdminMode
public static void setAdminMode(boolean doOrgClientAccessCheck)
Let's the current user run with Administrator privileges. If there is no current user then the special Administrator context is used. To restore the previous privileges call therestorePreviousMode()
.- Parameters:
doOrgClientAccessCheck
- Whether entity access (client+org) should also be checked- Since:
- 2.50MP18
- See Also:
restorePreviousMode()
-
setAdminMode
public static void setAdminMode()
Let's the current user run with Administrator privileges. If there is no current user then the special Administrator context is used. To restore the previous privileges call therestorePreviousMode()
. If this method is used, entity access will also be checked. If you don't want entity access to be checked, you should usesetAdminMode(boolean checkEntityAccess)
- Since:
- 2.50MP18
- See Also:
restorePreviousMode()
-
setCrossOrgReferenceAdminMode
public static void setCrossOrgReferenceAdminMode()
Cross Organization Reference Administrator mode allows to create references from an object to another one that it is not in the same Organization's natural tree. This only applies for columns marked to allow this behavior.
-
resetAsAdminContext
@Deprecated public static void resetAsAdminContext()
Deprecated.
-
restorePreviousMode
public static void restorePreviousMode()
Is used to restore the previous privileges after enabling Administrator privileges by callingsetAdminMode()
.- Since:
- 2.50MP18
- See Also:
setAdminMode()
-
restorePreviousCrossOrgReferenceMode
public static void restorePreviousCrossOrgReferenceMode()
Used to restore the previous privileges after enabling Cross Organization Reference Administrator privileges by callingsetCrossOrgReferenceAdminMode()
.- See Also:
setCrossOrgReferenceAdminMode()
-
setAdminTraceSize
public static void setAdminTraceSize(int s)
Sets the size of stack trace to display in case of logging unbalanced set/restore admin modes calls
-
clearAdminModeStack
public static void clearAdminModeStack()
Clears the admin context stack.
-
setOBContext
public static void setOBContext(javax.servlet.http.HttpServletRequest request)
Sets the OBContext through the information stored in the http session of the request (mainly the authenticated user). Note will not set the context in the http session if the session is not present.- Parameters:
request
-
-
setOBContextInSession
public static void setOBContextInSession(javax.servlet.http.HttpServletRequest request, OBContext context)
Sets the passed OBContext in the http session. Will not set it if the passed context is the admin context or if the http session is invalidated.- Parameters:
request
- the http request used to get the http sessioncontext
- the context which will be stored in the session
-
setOBContext
public static void setOBContext(String userId)
Creates the context using the userId and sets it in the thread (as a ThreadLocal). The user denoted by the userId will be automatically logged in.- Parameters:
userId
- the id of the user (as present in the database)
-
setOBContext
public static void setOBContext(String userId, String roleId, String clientId, String orgId)
Creates the context using the userId, roleId, clientId, orgId and sets it in the thread (as ThreadLocal).- Parameters:
userId
- the id of the userroleId
- the id of the role under which the user is currently workingclientId
- the id of the user's clientorgId
- the ud of the user's organization
-
setOBContext
public static void setOBContext(String userId, String roleId, String clientId, String orgId, String languageCode)
Creates the context using the userId, roleId, clientId, orgId and sets it in the thread (as ThreadLocal).- Parameters:
userId
- the id of the userroleId
- the id of the role under which the user is currently workingclientId
- the id of the user's clientorgId
- the ud of the user's organizationlanguageCode
- the selected language, if null then the user language is read.
-
setOBContext
public static void setOBContext(String userId, String roleId, String clientId, String orgId, String languageCode, String warehouseId)
Creates the context using the userId, roleId, clientId, orgId and sets it in the thread (as ThreadLocal).- Parameters:
userId
- the id of the userroleId
- the id of the role under which the user is currently workingclientId
- the id of the user's clientorgId
- the ud of the user's organizationlanguageCode
- the selected language, if null then the user language is read.warehouseId
- the id of the current warehouse of the user.
-
createOBContext
public static OBContext createOBContext(String userId)
Creates the context without setting the context in the thread.- Parameters:
userId
- the user used for creating the context- Returns:
- the created context
-
setOBContext
public static void setOBContext(OBContext obContext)
Set the context in the thread, this context will then be used by the Data Access Layer internals.- Parameters:
obContext
- the context to set in the thread
-
getOBContext
public static OBContext getOBContext()
Returns the OBContext currently set in the thread. Will return null if no context was set.- Returns:
- the context in the thread, null if none present
-
getUserLevel
public String getUserLevel()
-
setUserLevel
public void setUserLevel(String userLevel)
-
setReadableClients
public void setReadableClients(Role role)
Computes the clients allowed for read access using the user level and the client of the role.- Parameters:
role
- the role used to initialize the readable clients
-
getCurrentClient
public Client getCurrentClient()
-
setCurrentClient
public void setCurrentClient(Client currentClient)
-
setCurrentOrganization
public void setCurrentOrganization(Organization currentOrganization)
-
getLanguage
public Language getLanguage()
-
setLanguage
public void setLanguage(Language language)
-
getCurrentOrganization
public Organization getCurrentOrganization()
-
removeWritableOrganization
public void removeWritableOrganization(String orgId)
-
removeFromWritableOrganization
public void removeFromWritableOrganization(String orgId)
-
addWritableOrganization
public void addWritableOrganization(String orgId)
Adds a new organization for which write access is allowed.- Parameters:
orgId
- the id of the additional writable organization
-
setFromRequest
public boolean setFromRequest(javax.servlet.http.HttpServletRequest request)
Sets the OBContext using the information stored in the HttpSession- Parameters:
request
- the http request used to set the OBContext- Returns:
- false if no user was specified in the session, true otherwise
-
initialize
public boolean initialize(String userId)
-
getUser
public User getUser()
-
setUser
public void setUser(User user)
-
getRole
public Role getRole()
-
setRole
public void setRole(Role role)
-
getOrganizationStructureProvider
public OrganizationStructureProvider getOrganizationStructureProvider()
-
getOrganizationStructureProvider
public OrganizationStructureProvider getOrganizationStructureProvider(String clientId)
-
getAcctSchemaStructureProvider
public AcctSchemaStructureProvider getAcctSchemaStructureProvider()
-
getAcctSchemaStructureProvider
public AcctSchemaStructureProvider getAcctSchemaStructureProvider(String clientId)
-
getReadableOrganizations
public String[] getReadableOrganizations()
-
getReadableClients
public String[] getReadableClients()
-
getEntityAccessChecker
public EntityAccessChecker getEntityAccessChecker()
-
isInAdministratorMode
public boolean isInAdministratorMode()
-
isInCrossOrgAdministratorMode
public boolean isInCrossOrgAdministratorMode()
-
doOrgClientAccessCheck
public boolean doOrgClientAccessCheck()
-
doAccessLevelCheck
public boolean doAccessLevelCheck()
Defines whether entity check should or not compare entity's access level with role's user level in order to completely prevent access to that entity.
-
setCheckAccessLevel
public void setCheckAccessLevel(boolean checkAccessLevel)
- See Also:
doAccessLevelCheck()
-
isAdminContext
public boolean isAdminContext()
-
setInAdministratorMode
@Deprecated public boolean setInAdministratorMode(boolean inAdministratorMode)
Deprecated.usesetAdminMode()
andrestorePreviousMode()
.
-
isInitialized
public boolean isInitialized()
-
setInitialized
public void setInitialized(boolean isInitialized)
-
getWarehouse
public Warehouse getWarehouse()
-
setWarehouse
public void setWarehouse(Warehouse warehouse)
-
isNewUI
public boolean isNewUI()
-
setNewUI
public void setNewUI(boolean newUI)
-
isRTL
public boolean isRTL()
-
isPortalRole
public boolean isPortalRole()
-
isWebServiceEnabled
public boolean isWebServiceEnabled()
-
setRTL
public void setRTL(boolean isRTL)
-
isTranslationInstalled
public boolean isTranslationInstalled()
-
-