public class AuthletePropertiesConfiguration extends Object implements AuthleteConfiguration
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.encryptedis 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.encryptedis 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";AuthleteConfigurationconf = newAuthletePropertiesConfiguration(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.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_FILE
The default value of the name of the configuration file
(
authlete.properties). |
static String |
DEFAULT_IV
The default value of the initial vector to decode encrypted property values
(
b6f5d0f0dd7146b0e3915ebd2dd078f3). |
static String |
DEFAULT_KEY
The default value of the secret key to decode encrypted property values
(
a281ac2de1195e8c91ea383d38d05d1c). |
static String |
SYSTEM_PROPERTY_AUTHLETE_CONFIGURATION_FILE
The system property key to specify the name of an Authlete
configuration file (
authlete.configuration.file). |
| Constructor and Description |
|---|
AuthletePropertiesConfiguration()
Constructor with no argument.
|
AuthletePropertiesConfiguration(byte[] key,
byte[] iv)
Constructor with a pair of secret key and initial vector to decode
encrypted property values.
|
AuthletePropertiesConfiguration(String file)
Constructor with a configuration file name.
|
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.
|
AuthletePropertiesConfiguration(String key,
String iv)
Constructor with a pair of secret key and initial vector to decode
encrypted property values.
|
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.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getBaseUrl()
Get the base URL.
|
String |
getServiceApiKey()
Get the service API key.
|
String |
getServiceApiSecret()
Get the service API secret.
|
String |
getServiceOwnerApiKey()
Get the service owner API key.
|
String |
getServiceOwnerApiSecret()
Get the service owner API secret.
|
public static final String DEFAULT_KEY
a281ac2de1195e8c91ea383d38d05d1c).public static final String DEFAULT_IV
b6f5d0f0dd7146b0e3915ebd2dd078f3).public static final String DEFAULT_FILE
authlete.properties).public static final String SYSTEM_PROPERTY_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.public AuthletePropertiesConfiguration(String key, String iv)
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.
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".IllegalArgumentException - key is null
iv is null
NumberFormatException - key is not a valid hex string.
iv is not a valid hex string.
public AuthletePropertiesConfiguration(byte[] key,
byte[] iv)
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.
key - The secret key to decode encrypted property values.iv - The initial vector to decode encrypted property values.IllegalArgumentException - key is null
iv is null
public AuthletePropertiesConfiguration(String file, String key, String iv)
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".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.
public AuthletePropertiesConfiguration(String file)
This constructor is an alias of this(file, DEFAULT_KEY, DEFAULT_IV).
file - The name of the configuration file. The file system and then
the classpath are searched for the file.IllegalArgumentException - file is null.public AuthletePropertiesConfiguration()
This constructor is an alias of this(file, DEFAULT_KEY, DEFAULT_IV) where
file is either authlete.properties or the value of the system property authlete.configuration.file
if the value is not empty.
public AuthletePropertiesConfiguration(String file, byte[] key, byte[] iv)
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.IllegalArgumentException - file is null
key is null
iv is null
public String getBaseUrl()
getBaseUrl in interface AuthleteConfigurationpublic String getServiceOwnerApiKey()
getServiceOwnerApiKey in interface AuthleteConfigurationpublic String getServiceOwnerApiSecret()
getServiceOwnerApiSecret in interface AuthleteConfigurationpublic String getServiceApiKey()
getServiceApiKey in interface AuthleteConfigurationpublic String getServiceApiSecret()
getServiceApiSecret in interface AuthleteConfigurationCopyright © 2017. All rights reserved.