Class InternalUserStore
java.lang.Object
com.inductiveautomation.ignition.gateway.authentication.impl.InternalUserStore
Utility class for persisting internal users and roles to disk for
InternalUserSource profiles.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.inductiveautomation.ignition.common.gson.Gson -
Constructor Summary
ConstructorsConstructorDescriptionInternalUserStore(GatewayContext context, String profileName, LoggerEx log) Create a newInternalUserStorefor the specified profile. -
Method Summary
Modifier and TypeMethodDescriptionGet the read lock to read the users and roles from disk.Get the write lock to write the users and roles to disk.voidpersist(List<InternalUserResource> users, List<InternalRoleResource> roles) Persist the users and roles to disk for the specified profile.read()Read the users and roles resource.
-
Field Details
-
GSON
public static final com.inductiveautomation.ignition.common.gson.Gson GSON
-
-
Constructor Details
-
InternalUserStore
Create a newInternalUserStorefor the specified profile.- Parameters:
context- TheGatewayContext.profileName- The name of the profile.log- TheLoggerExto log to.
-
-
Method Details
-
getReadLock
Get the read lock to read the users and roles from disk.- Returns:
- The read lock.
- See Also:
-
getWriteLock
Get the write lock to write the users and roles to disk.- Returns:
- The write lock.
- See Also:
-
persist
public void persist(List<InternalUserResource> users, List<InternalRoleResource> roles) throws PushException Persist the users and roles to disk for the specified profile.
This method will attempt to acquire a write lock before writing the users and roles to disk. This method will block until the write lock can be acquired. If the write lock is already owned by this thread, then the lock will immediately be acquired. It is recommended if you are modifying a resource, that you obtain the write lock prior to retrieving the resource, then release the write lock after you are done modifying the resource. This will prevent other threads from modifying the resource while you are working on it.userStore.getWriteLock().lock(); try { Optional<UsersJsonResource> optional = userStore.read(); if (optional.isPresent()) { UsersJsonResource resource = optional.get(); // Modify the resource based on existing state. userStore.persist(resource.getUsers(), resource.getRoles()); } } finally { userStore.getWriteLock().unlock(); }- Parameters:
users- The users to write.roles- The roles to write.- Throws:
PushException- If there is an error pushing the changes to disk.- See Also:
-
read
Read the users and roles resource.
This method will attempt to acquire a read lock before reading the users and roles from disk. This method will block until the read lock can be acquired. If the read lock is already owned by this thread, then the lock will immediately be acquired.- Returns:
- An
Optionalcontaining the users and roles if they exist, or an empty optional if they don't. - See Also:
-