Interface UserContextService
- All Superinterfaces:
Service
public interface UserContextService extends Service
Service for acquiring and manipulating
PlatformUserContext
and PlatformUserProfile
objects.-
Method Summary
Modifier and Type Method Description PlatformUserContext
createContext(java.lang.Long userId, java.lang.Long roleId)
Given a user id and role id, initialize and returns a suitable PlatformUserContext.PlatformUserContext
createContext(java.lang.String userName, java.lang.String roleName, java.lang.String roleEnt, java.lang.String roleOrg, java.lang.String roleSite)
Given natural key information for a user and role, returns a suitable PlatformUserContext.PlatformUserContext
createDefaultEnterpriseAdminContext(java.lang.Long valueChainId, java.lang.String enterpriseName)
Returns a context with Administrative privileges for the Enterprise with the given id and enterprise name.PlatformUserContext
createDefaultInstanceAdminContext()
Returns a context with Administrative privileges for the entire Platform instance (permissions cross all Value Chains).PlatformUserContext
createDefaultValueChainAdminContext(java.lang.Long valueChainId)
Returns a context with Administrative privileges for the ValueChain with the given id.PlatformUserContext
fromJSONObject(org.json.JSONObject platformUserContextParams)
Creates PlatformUserContext object from JSON object.PlatformUserProfile
getPlatformUserProfile(PlatformUserContext userContext)
Creates a new PlatformUserProfile using the given user and user's preferred LocalePlatformUserProfile
getPlatformUserProfile(PlatformUserContext userContext, java.util.Locale locale)
Deprecated.use#getUserLocale(PlatformUserContext)
PlatformUserProfile
getPlatformUserProfile(javax.servlet.http.HttpServletRequest request)
Fetches and returns thePlatformUserProfile
from the current web session
-
Method Details
-
createContext
Given a user id and role id, initialize and returns a suitable PlatformUserContext.- Parameters:
userId
- surrogate id of the user for which to create a contextroleId
- surrogate id of the role the user should play ... may be null, in which case the user's last used role will be used. If no last role id on user, then first available role will be used. If user has no roles available, then exception will be thrown. If explicit roleId is provided and no such role exists then an exception will be thrown.- Returns:
- PlatformUserContext context object which uses the given user/role information
-
createContext
PlatformUserContext createContext(java.lang.String userName, java.lang.String roleName, java.lang.String roleEnt, java.lang.String roleOrg, java.lang.String roleSite)Given natural key information for a user and role, returns a suitable PlatformUserContext.- Parameters:
userName
- user nameroleName
- role nameroleEnt
- role enterprise name (or null if VC role)roleOrg
- role org name (or null if VC or Ent role)roleSite
- role site name (or n ull if VC or Ent or Org role)- Returns:
- PlatformUserContext context object which uses the given user/role information
-
createDefaultEnterpriseAdminContext
PlatformUserContext createDefaultEnterpriseAdminContext(java.lang.Long valueChainId, java.lang.String enterpriseName)Returns a context with Administrative privileges for the Enterprise with the given id and enterprise name. The Enterprise Admin has permission to all data within the given enterprise, so this context can be used with APIs likeModelDataService
to execute queries free of role type permissions. Throws aRuntimeException
if no user is found with administrative privileges for the Enterprise. When choosing a default Enterprise Administrator context, first preference is given to a role having name {enterpriseName}Admin,e.g. if enterprise name is SampleEnterprise then the role name used will be SampleEnterpriseAdmin. If role with such a name is not found (or has no users), then any available role of type ENTERPRISE_ADMINISTRATOR is used (ordered by name alphabetically when choosing a default). If multiple users are have this role, the user with the first name appearing alphabetically will be used.- Parameters:
valueChainId
- id of the ValueChain for which we want a default admin contextenterpriseName
- enterprise name for which we want a default enterprise admin context- Returns:
- PlatformUserContext context with Administrative privileges for the Enterprise with the given id and enterprise name.
-
createDefaultValueChainAdminContext
Returns a context with Administrative privileges for the ValueChain with the given id. The Value Chain Admin has permission to all data within the given value chain, so this context can be used in context with APIs likeModelDataService
to execute queries free of role type permissions.- Parameters:
valueChainId
- id of the ValueChain for which we want a default admin context- Returns:
- PlatformUserContext context with Administrative privileges for the ValueChain with the given id.
-
createDefaultInstanceAdminContext
PlatformUserContext createDefaultInstanceAdminContext()Returns a context with Administrative privileges for the entire Platform instance (permissions cross all Value Chains). Instance Admin users have access to all data across all value chains, and so can be used in context with APIs likeModelDataService
to execute queries completely free of permissoins.- Returns:
- PlatformUserContext context with Administrative privileges for the entire Platform instance
-
fromJSONObject
Creates PlatformUserContext object from JSON object. JSON object should be in the format like below. { RoleName: ..., RoleTypeName: ..., UserName: ..., UserEntId: ..., UserEntName: ..., EntName: ..., OrgName: ..., SiteName: ..., ValueChainId: ..., ValueChainName: ..., UserId: ..., EntId: ..., OrgId: ..., SiteId: ..., RoleId: ... }- Parameters:
platformUserContextParams
-- Returns:
-
getPlatformUserProfile
Fetches and returns thePlatformUserProfile
from the current web session- Parameters:
request
- http request- Returns:
PlatformUserProfile
from the current web session
-
getPlatformUserProfile
PlatformUserProfile getPlatformUserProfile(PlatformUserContext userContext, java.util.Locale locale)Deprecated.use#getUserLocale(PlatformUserContext)
Creates a new PlatformUserProfile using the given user and a client-provided Locale- Parameters:
request
- http requestlocale
- Loacle to use when internationalizing the given user's content- Returns:
PlatformUserProfile
containing the given user and locale
-
getPlatformUserProfile
Creates a new PlatformUserProfile using the given user and user's preferred Locale- Parameters:
request
- http request- Returns:
PlatformUserProfile
containing the given user and user's preferred locale
-