java.lang.Object
com.inductiveautomation.ignition.gateway.authentication.impl.InternalUserStore

public class InternalUserStore extends Object
Utility class for persisting internal users and roles to disk for InternalUserSource profiles.
  • Field Details

    • GSON

      public static final com.inductiveautomation.ignition.common.gson.Gson GSON
  • Constructor Details

  • Method Details

    • getReadLock

      public Lock getReadLock()
      Get the read lock to read the users and roles from disk.
      Returns:
      The read lock.
      See Also:
    • getWriteLock

      public Lock 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

      public Optional<UsersJsonResource> 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 Optional containing the users and roles if they exist, or an empty optional if they don't.
      See Also: