Class LibraryConfigurationBinder

java.lang.Object
org.gcube.documentstore.configuration.LibraryConfigurationBinder

public class LibraryConfigurationBinder extends Object
The configuration of the Document Store Lib
Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • DOCUMENT_STORE_LIB_CONFIGURATION_FILE

      public static final String DOCUMENT_STORE_LIB_CONFIGURATION_FILE
      See Also:
    • CONFIGURATION_SECTION_KEY

      public static final String CONFIGURATION_SECTION_KEY
      See Also:
    • CONFIGURATION_LIFETIME

      public static final String CONFIGURATION_LIFETIME
      See Also:
    • AUTHORIZATION_SECTION_KEY

      public static final String AUTHORIZATION_SECTION_KEY
      See Also:
    • libraryConfigurationBinder

      protected static LibraryConfigurationBinder libraryConfigurationBinder
    • DEFAULT_LIFETIME

      protected static long DEFAULT_LIFETIME
    • creationTime

      protected Calendar creationTime
      The time when the library configuration was created.
    • configurationLifetime

      protected long configurationLifetime
      The time in milliseconds after which the configuration is considered expired. The default value is 5 minutes (see DEFAULT_LIFETIME). The configuration itself could contains the expiring time. So that we can decide the configuration lifetime.
    • authorizationProvider

      protected org.gcube.common.security.factories.AuthorizationProvider authorizationProvider
    • workingContext

      protected String workingContext
      The working Context of the library, chosen among the Contexts of its credentials; computed on first use and kept for the lifetime of this configuration.
  • Method Details

    • getInstance

      public static LibraryConfigurationBinder getInstance()
      Returns the singleton instance of LibraryConfigurationBinder. If the instance does not exist or the configuration has expired, a new instance is created.
      Returns:
      the singleton instance of LibraryConfigurationBinder
    • getAuthorizationProvider

      public org.gcube.common.security.factories.AuthorizationProvider getAuthorizationProvider() throws Exception
      Returns the authorization provider configured by the "dsl.yaml" file in GHN_HOME; the file is read once for the lifetime of this configuration. Its "authorization" section has the form of the one of SmartGears (AuthorizationSection); its optional "configuration" section gives the lifetime of this configuration in minutes ("configurationExpiringTime").
      Returns:
      the authorization provider, or null if the file has no authorization section
      Throws:
      Exception - if the file cannot be read or one of its sections is invalid
    • getWorkingContext

      public String getWorkingContext() throws Exception
      Returns the working Context of the library: the Context whose secret the library uses for its own operations. It is one of the Contexts of the credentials, chosen by chooseWorkingContext(Set), never the Context of the thread that happens to call.
      Returns:
      the working Context, or null if the credentials give no Context
      Throws:
      Exception - if the authorization provider cannot be built
    • getWorkingSecret

      public org.gcube.common.security.secrets.Secret getWorkingSecret() throws Exception
      Returns a secret for the working Context, obtained from the credentials of the "dsl.yaml" file. A new secret is requested at every call, so that an expired token is never reused.
      Returns:
      the secret, or null if the credentials give no Context
      Throws:
      Exception - if the secret cannot be obtained
    • chooseWorkingContext

      public static String chooseWorkingContext(Set<String> contexts)
      Chooses the working Context among the given Contexts, deterministically: the Context with the fewest path segments (the one closest to the root), and among those the first in lexicographic order.
      Parameters:
      contexts - the Contexts of the credentials, possibly null or empty
      Returns:
      the chosen Context, or null if there is none