Class PropertyUserStore

All Implemented Interfaces:
Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Scanner.DiscreteListener, Scanner.Listener

public class PropertyUserStore extends UserStore implements Scanner.DiscreteListener

This class monitors a property file of the format mentioned below and notifies registered listeners of the changes to the the given file.

  username: password [,rolename ...]
 

Passwords may be clear text, obfuscated or checksummed. The class Password should be used to generate obfuscated passwords or password checksums.

If DIGEST Authentication is used, the password must be in a recoverable format, either plain text or obfuscated.

  • Field Details

    • _configResource

      protected Resource _configResource
    • _scanner

      protected Scanner _scanner
    • _reloadInterval

      protected int _reloadInterval
    • _firstLoad

      protected boolean _firstLoad
    • _listeners

      protected List<PropertyUserStore.UserListener> _listeners
  • Constructor Details

    • PropertyUserStore

      public PropertyUserStore()
  • Method Details

    • getConfig

      public Resource getConfig()
      Get the config (as a string)
      Returns:
      the config path as a string
    • setConfig

      public void setConfig(Resource config)
      Set the Config Path from a String reference to a file
      Parameters:
      config - the config file TODO: reintroduce setConfig(String) and internal ResourceFactory usage
    • getConfigResource

      @Deprecated(forRemoval=true) public Resource getConfigResource()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      the resource associated with the configured properties file, creating it if necessary
    • isHotReload

      @Deprecated public boolean isHotReload()
      Deprecated.
      Is hot reload enabled on this user store
      Returns:
      true if hot reload was enabled before startup
    • setHotReload

      @Deprecated public void setHotReload(boolean enable)
      Deprecated.
      Enable Hot Reload of the Property File
      Parameters:
      enable - true to enable to a 1 second scan, false to disable
    • setReloadInterval

      public void setReloadInterval(int scanSeconds)
      Enable Hot Reload of the Property File
      Parameters:
      scanSeconds - the period in seconds to scan for property file changes, or 0 for no scanning
    • getReloadInterval

      public int getReloadInterval()
      Get the period in seconds to scan for property file changes, or 0 for no scanning.
      Returns:
      the period in seconds to scan for property file changes, or 0 for no scanning
    • toString

      public String toString()
      Overrides:
      toString in class UserStore
    • loadUsers

      protected void loadUsers() throws IOException
      Load the user data from the property file.
      Throws:
      IOException - If the users cannot be loaded
    • doStart

      protected void doStart() throws Exception
      Depending on the value of the refresh interval, this method will either start up a scanner thread that will monitor the properties file for changes after it has initially loaded it. Otherwise the users will be loaded and there will be no active monitoring thread so changes will not be detected.
      Overrides:
      doStart in class ContainerLifeCycle
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • pathChanged

      public void pathChanged(Path path) throws Exception
      Description copied from interface: Scanner.DiscreteListener
      Called when a file is changed. Default implementation calls Scanner.DiscreteListener.fileChanged(String).
      Specified by:
      pathChanged in interface Scanner.DiscreteListener
      Parameters:
      path - the Path.toRealPath(LinkOption...) of the changed file
      Throws:
      Exception - May be thrown for handling errors
    • pathAdded

      public void pathAdded(Path path) throws Exception
      Description copied from interface: Scanner.DiscreteListener
      Called when a file is added. Default implementation calls Scanner.DiscreteListener.fileAdded(String).
      Specified by:
      pathAdded in interface Scanner.DiscreteListener
      Parameters:
      path - the Path.toRealPath(LinkOption...) of the added file
      Throws:
      Exception - May be thrown for handling errors
    • pathRemoved

      public void pathRemoved(Path path) throws Exception
      Description copied from interface: Scanner.DiscreteListener
      Called when a file is removed. Default implementation calls Scanner.DiscreteListener.fileRemoved(String).
      Specified by:
      pathRemoved in interface Scanner.DiscreteListener
      Parameters:
      path - the Path.toRealPath(LinkOption...) of the removed file
      Throws:
      Exception - May be thrown for handling errors
    • doStop

      protected void doStop() throws Exception
      Description copied from class: ContainerLifeCycle
      Stops the managed lifecycle beans in the reverse order they were added.
      Overrides:
      doStop in class ContainerLifeCycle
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • registerUserListener

      public void registerUserListener(PropertyUserStore.UserListener listener)
      Registers a listener to be notified of the contents of the property file
      Parameters:
      listener - the user listener