Class 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
    • Constructor Detail

      • OBContext

        public OBContext()
    • 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()
      • 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 the restorePreviousMode().
        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 the restorePreviousMode(). If this method is used, entity access will also be checked. If you don't want entity access to be checked, you should use setAdminMode(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.
      • restorePreviousMode

        public static void restorePreviousMode()
        Is used to restore the previous privileges after enabling Administrator privileges by calling setAdminMode().
        Since:
        2.50MP18
        See Also:
        setAdminMode()
      • 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 session
        context - 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 user
        roleId - the id of the role under which the user is currently working
        clientId - the id of the user's client
        orgId - 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 user
        roleId - the id of the role under which the user is currently working
        clientId - the id of the user's client
        orgId - the ud of the user's organization
        languageCode - 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 user
        roleId - the id of the role under which the user is currently working
        clientId - the id of the user's client
        orgId - the ud of the user's organization
        languageCode - 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)
      • getReadableOrganizations

        public String[] getReadableOrganizations()
      • getWritableOrganizations

        public Set<String> getWritableOrganizations()
      • getDeactivatedOrganizations

        public Set<String> getDeactivatedOrganizations()
      • getReadableClients

        public String[] getReadableClients()
      • 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()
      • 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()