@ThingworxExtensionApiClass(since={6,6}) public final class SecurityContext extends 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(); }
ThreadLocalContext
,
User
,
Group
,
Thing
Modifier | Constructor and Description |
---|---|
protected |
SecurityContext() |
Modifier and Type | Method and 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 |
isSecurityAdministratorAccount()
|
boolean |
isSuperUserContext()
|
compareTo, findByName, getEntityName, getName, getReference, getSubEntityName, getType, matches, toString
@ThingworxExtensionApiMethod(since={6,6}) public boolean isAdministrativeAccount()
@ThingworxExtensionApiMethod(since={6,6}) public boolean isSecurityAdministratorAccount()
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createSuperUserContext()
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createSystemUserContext()
@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createUserContext(User user)
user
- The user that will be used to create the security context.@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createGroupContext(Group group)
group
- The user that will be used to create the security context.@ThingworxExtensionApiMethod(since={6,6}) public static SecurityContext createThingContext(Thing thing)
thing
- The thing that will be used to create the security context.@ThingworxExtensionApiMethod(since={6,6}) public java.lang.String getDescription()
getDescription
in class EntityReference
@ThingworxExtensionApiMethod(since={6,6}) public boolean isSuperUserContext()
@ThingworxExtensionApiMethod(since={6,6}) public EntityReferenceCollection getGroups()
@ThingworxExtensionApiMethod(since={6,6}) public boolean hasGroup(java.lang.String group)
@ThingworxExtensionApiMethod(since={6,6}) public EntityReferenceCollection getOrganizations()
@ThingworxExtensionApiMethod(since={6,6}) public boolean hasOrganization(java.lang.String name)
@ThingworxExtensionApiMethod(since={6,6}) public EntityReferenceCollection getOrganizationalUnits()
@ThingworxExtensionApiMethod(since={6,6}) public java.lang.String getAccount()