Class AuthletePropertiesConfiguration

  • All Implemented Interfaces:
    AuthleteConfiguration

    public class AuthletePropertiesConfiguration
    extends Object
    implements AuthleteConfiguration
    Implementation of AuthleteConfiguration based on a properties file.

    This is a utility class to load a configuration file that includes properties related to Authlete. Below is the list of configuration properties.

    base_url
    The base URL of Authlete Web API. The default value is "https://api.authlete.com".

    service_owner.api_key
    The service owner API key issued by Authlete.

    service_owner.api_secret.encrypted
    The service owner API secret issued by Authlete, encrypted by "AES/CBC/PKCS5Padding" and encoded in Base64. The secret key and the initial vector of the encryption have to be passed to the constructor of this class.

    service_owner.api_secret
    The service owner API secret issued by Authlete. The value of this configuration property is referred to only when service_owner.api_secret.encrypted is not found in the configuration file.

    service.api_key
    The service API key issued by Authlete.

    service.api_secret.encrypted
    The service API secret issued by Authlete, encrypted by "AES/CBC/PKCS5Padding" and encoded in Base64. The secret key and the initial vector of the encryption have to be passed to the constructor of this class.

    service.api_secret
    The service API secret issued by Authlete. The value of of this configuration property is referred to only when service.api_secret.encrypted is not found in the configuration file.

    The value of service_owner.api_secret.encrypted can be generated using openssl command like the following.

     echo -n "{Service-Owner-API-Secret}" | openssl aes-128-cbc -e -a \
       -K  "{Your-Secret-Key-in-Hex}" -iv "{Your-Initial-Vector-in-Hex}"

    "{Service-Owner-API-Secret}" is the service owner API secret issued by Authlete. Values of "{Your-Secret-Key-in-Hex}" and "{Your-Initial-Vector-in-Hex}" are 32-letter hex strings which you can determine. The following is an example to generate a random 32-letter hex string.

     ruby -e 'puts Random.new.bytes(16).unpack("H*")'

    Likewise, the value of service.api_secret.encrypted can be generated by openssl, too.

    If you encrypt your service owner API secret and service API secret as shown below:

     // Encrypt service owner API secret.
     $ echo -n "AF4Sms0cqs3HsTNlVrPbnWz5AXi3GtmMcveOklYKVCc" | openssl aes-128-cbc -e -a \
       -K a281ac2de1195e8c91ea383d38d05d1c -iv b6f5d0f0dd7146b0e3915ebd2dd078f3
     sKzcMU98a8xA5lwR23Crfkyu23klZnTuQlWApyllARpHFv84IItoZFZXj70OCrnF
    
     // Encrypt service API secret.
     $ echo -n "9La-ZhyyKK6sV6zsteNmcoTizHmC0NEVTFT9FUrIaYs" | openssl aes-128-cbc -e -a \
       -K a281ac2de1195e8c91ea383d38d05d1c -iv b6f5d0f0dd7146b0e3915ebd2dd078f3
     ERxV45wkpjJWXs+Mg9m6UyGHHGzBG5/2ytX0j0x3qNPuz5oWyciqkWjkBznLTWxb

    The configuration file will look like the following.

     base_url = https://evaluation-dot-authlete.appspot.com
     service_owner.api_key = etKXFbM0VumfC5j1XD6qGOk3yhHmsdqOILBFFIkDfmw
     service_owner.api_secret.encrypted = sKzcMU98a8xA5lwR23Crfkyu23klZnTuQlWApyllARpHFv84IItoZFZXj70OCrnF
     service.api_key = KNiA4bWqj2Ht0CJTqr4DTBgTIXeCskCHQ_vONBeth6M
     service.api_secret.encrypted = ERxV45wkpjJWXs+Mg9m6UyGHHGzBG5/2ytX0j0x3qNPuz5oWyciqkWjkBznLTWxb

    And to load the configuration file, an AuthletePropertiesConfiguration instance needs to be constructed as follows:

     String key = "a281ac2de1195e8c91ea383d38d05d1c";
     String iv  = "b6f5d0f0dd7146b0e3915ebd2dd078f3";
    
     AuthleteConfiguration conf = new AuthletePropertiesConfiguration(key, iv);

    Constructors without file parameter use "authlete.properties" as the name of the configuration file and search the file system and then the classpath for the file.

    • Field Detail

      • DEFAULT_KEY

        public static final String DEFAULT_KEY
        The default value of the secret key to decode encrypted property values (a281ac2de1195e8c91ea383d38d05d1c).
        Since:
        1.24
        See Also:
        Constant Field Values
      • DEFAULT_IV

        public static final String DEFAULT_IV
        The default value of the initial vector to decode encrypted property values (b6f5d0f0dd7146b0e3915ebd2dd078f3).
        Since:
        1.24
        See Also:
        Constant Field Values
      • DEFAULT_FILE

        public static final String DEFAULT_FILE
        The default value of the name of the configuration file (authlete.properties).
        Since:
        1.24
        See Also:
        Constant Field Values
      • SYSTEM_PROPERTY_AUTHLETE_CONFIGURATION_FILE

        public static final String SYSTEM_PROPERTY_AUTHLETE_CONFIGURATION_FILE
        The system property key to specify the name of an Authlete configuration file (authlete.configuration.file). When this system property has a value, it is used as the name of the configuration file. Otherwise, the default file (authlete.properties) is used.
        Since:
        1.29
        See Also:
        Constant Field Values
    • Constructor Detail

      • AuthletePropertiesConfiguration

        public AuthletePropertiesConfiguration​(String key,
                                               String iv)
        Constructor with a pair of secret key and initial vector to decode encrypted property values.

        This constructor is an alias of this(file, key, iv) where file is either authlete.properties or the value of the system property authlete.configuration.file if the value is not empty.

        Parameters:
        key - The secret key to decode encrypted property values in hex. For example, "9543837d590ef25312e7d156a435feda".
        iv - The initial vector to decode encrypted property values. For example, "e90ce45e6134d37e0aa2c3c870003639".
        Throws:
        IllegalArgumentException -
        • key is null
        • iv is null
        NumberFormatException -
        • key is not a valid hex string.
        • iv is not a valid hex string.
      • AuthletePropertiesConfiguration

        public AuthletePropertiesConfiguration​(byte[] key,
                                               byte[] iv)
        Constructor with a pair of secret key and initial vector to decode encrypted property values.

        This constructor is an alias of this(file, key, iv) where file is either authlete.properties or the value of the system property authlete.configuration.file if the value is not empty.

        Parameters:
        key - The secret key to decode encrypted property values.
        iv - The initial vector to decode encrypted property values.
        Throws:
        IllegalArgumentException -
        • key is null
        • iv is null
      • AuthletePropertiesConfiguration

        public AuthletePropertiesConfiguration​(String file,
                                               String key,
                                               String iv)
        Constructor with a configuration file name and a pair of secret key and initial vector to decode encrypted property values.
        Parameters:
        file - The name of the configuration file. The file system and then the classpath are searched for the file.
        key - The secret key to decode encrypted property values in hex. For example, "9543837d590ef25312e7d156a435feda".
        iv - The initial vector to decode encrypted property values. For example, "e90ce45e6134d37e0aa2c3c870003639".
        Throws:
        IllegalArgumentException -
        • file is null
        • key is null
        • iv is null
        NumberFormatException -
        • key is not a valid hex string.
        • iv is not a valid hex string.
      • AuthletePropertiesConfiguration

        public AuthletePropertiesConfiguration​(String file)
        Constructor with a configuration file name.

        This constructor is an alias of this(file, DEFAULT_KEY , DEFAULT_IV).

        Parameters:
        file - The name of the configuration file. The file system and then the classpath are searched for the file.
        Throws:
        IllegalArgumentException - file is null.
        Since:
        1.24
      • AuthletePropertiesConfiguration

        public AuthletePropertiesConfiguration​(String file,
                                               byte[] key,
                                               byte[] iv)
        Constructor with a configuration file name and a pair of secret key and initial vector to decode encrypted property values.
        Parameters:
        file - The name of the configuration file. The file system and then the classpath are searched for the file.
        key - The secret key to decode encrypted property values.
        iv - The initial vector to decode encrypted property values.
        Throws:
        IllegalArgumentException -
        • file is null
        • key is null
        • iv is null