Class SecurityContext
- java.lang.Object
-
- com.thingworx.entities.EntityReference
-
- com.thingworx.security.context.SecurityContext
-
- All Implemented Interfaces:
java.lang.Comparable<EntityReference>
@ThingworxExtensionApiClass(since={6,6}) public final class SecurityContext extends EntityReference
A context object containing a reference to a managed account, typically aUser
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
, andThing
.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:
ThreadLocalContext
,User
,Group
,Thing
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SecurityContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SecurityContext
createGroupContext(Group group)
static SecurityContext
createSuperUserContext()
static SecurityContext
createSystemUserContext()
static SecurityContext
createThingContext(Thing thing)
static SecurityContext
createUserContext(User user)
java.lang.String
getAccount()
java.lang.String
getDescription()
EntityReferenceCollection
getGroups()
EntityReferenceCollection
getOrganizationalUnits()
EntityReferenceCollection
getOrganizations()
boolean
hasGroup(java.lang.String group)
boolean
hasOrganization(java.lang.String name)
boolean
isAdministrativeAccount()
boolean
isAuditor()
boolean
isSecurityAdministratorAccount()
boolean
isSuperUserContext()
-
Methods inherited from class com.thingworx.entities.EntityReference
compareTo, findByName, getEntityName, getName, getReference, getSubEntityName, getType, matches, toString
-
-
-
-
Method Detail
-
isAdministrativeAccount
@ThingworxExtensionApiMethod(since={6,6}) public boolean isAdministrativeAccount()
- Returns:
- true if the current security context is an Administrative Account
-
isAuditor
@ThingworxExtensionApiMethod(since={9,0,0}) public boolean isAuditor()
- Returns:
- true if the current security context is in Auditors User Group
-
isSecurityAdministratorAccount
@ThingworxExtensionApiMethod(since={6,6}) public boolean isSecurityAdministratorAccount()
- Returns:
- true if the current security context is the security Administrator Account
-
createSuperUserContext
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createSuperUserContext()
- Returns:
- The created superuser security context.
-
createSystemUserContext
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext 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
@ThingworxExtensionApiMethod(since={6,6}) public java.lang.String getDescription()
- Overrides:
getDescription
in classEntityReference
- Returns:
- The description
-
isSuperUserContext
@ThingworxExtensionApiMethod(since={6,6}) public boolean isSuperUserContext()
- Returns:
- true if is the superuser context.
-
getGroups
@ThingworxExtensionApiMethod(since={6,6}) public EntityReferenceCollection getGroups()
- Returns:
- A group entity reference collection.
-
hasGroup
@ThingworxExtensionApiMethod(since={6,6}) public boolean hasGroup(java.lang.String group)
-
getOrganizations
@ThingworxExtensionApiMethod(since={6,6}) public EntityReferenceCollection getOrganizations()
-
hasOrganization
@ThingworxExtensionApiMethod(since={6,6}) public boolean hasOrganization(java.lang.String name)
-
getOrganizationalUnits
@ThingworxExtensionApiMethod(since={6,6}) public EntityReferenceCollection getOrganizationalUnits()
-
getAccount
@ThingworxExtensionApiMethod(since={6,6}) public java.lang.String getAccount()
-
-