Class SecurityContext
- All Implemented Interfaces:
Comparable<EntityReference>
User
instance.
A security context is a basic container for a Thingworx-managed account. These contexts are used in Thingworx to enforce permissions and
access control, and for tracking the currently authorized account in a request. Security contexts may refer to one of three types of
accounts: User
, Group
, and Thing
.
Security contexts can be generated using the factory methods provided in this class. A thing context stores the thing as the account with no associated groups, organizations, or privileges.
For extension development, if you need to access a secured resource that the user making the request may not have access to, you can generate the super user or system user contexts using the appropriate factory methods. You must ensure that the security context is only used to access the secured resources that are needed to ensure proper functionality.
The following code sample illustrates how the security context is used to access an associated entity:
{ @code SecurityContext systemContext = SecurityContext.createSystemUserContext(); ThreadLocalContext.setSecurityContext(systemContext); Thing associatedEntity = ThingUtilities.findThing("ExampleThing"); ThreadLocalContext.clearSecurityContext(); }
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic SecurityContext
createGroupContext
(Group group) static SecurityContext
static SecurityContext
static SecurityContext
createThingContext
(Thing thing) static SecurityContext
createUserContext
(User user) boolean
boolean
hasOrganization
(String name) boolean
boolean
boolean
boolean
Methods inherited from class com.thingworx.entities.EntityReference
compareTo, findByName, getEntityName, getName, getReference, getSubEntityName, getType, matches, toString
-
Constructor Details
-
SecurityContext
protected SecurityContext()
-
-
Method Details
-
isAdministrativeAccount
- Returns:
- true if the current security context is an Administrative Account
-
isAuditor
- Returns:
- true if the current security context is in Auditors User Group
-
isSecurityAdministratorAccount
- Returns:
- true if the current security context is the security Administrator Account
-
createSuperUserContext
- Returns:
- The created superuser security context.
-
createSystemUserContext
- Returns:
- The created system user security context from the cache if already available.
-
createUserContext
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createUserContext(User user) - Parameters:
user
- The user that will be used to create the security context.- Returns:
- The user based security context.
-
createGroupContext
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createGroupContext(Group group) - Parameters:
group
- The user that will be used to create the security context.- Returns:
- The group based security context.
-
createThingContext
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createThingContext(Thing thing) - Parameters:
thing
- The thing that will be used to create the security context.- Returns:
- The thing based security context.
-
getDescription
- Overrides:
getDescription
in classEntityReference
- Returns:
- The description
-
isSuperUserContext
- Returns:
- true if is the superuser context.
-
getGroups
- Returns:
- A group entity reference collection.
-
hasGroup
-
getOrganizations
-
hasOrganization
-
getOrganizationalUnits
-
getAccount
-