Android Initialization

Jump to: Kotlin, Java

Initialize a UMFAClient instance from the ZSM module by creating an instance of the ZSMConfig class with the necessary configuration parameters such as host_url, application_id, and consumer_id. Then, use the UMFAClient constructor to create the instance, which is required for performing all Universal MFA operations.

Custom logging can be defined when initializing the UMFAClient object. If a custom logging function is not provided, a default logging method is used. This method uses Android's built-in logging methods and maps to the LogLevel enum defined within the API.

Kotlin

Usage

 private fun initializeZSM() {
        val config = ZSMConfig(JSONObject().apply {
            put("host_url", hostUrl.value)
            put("application_id", applicationId.value)
            put("consumer_id", consumerId.value)
            put("authentication_host", authenticationHost.value)
            put("api_key", apiKey.value)

            logLevel = LogLevel.TRACE // Set the lowest level of logging
            logging = { _, message ->
                Log.d("Custom log", message)
            }
        })

        val client = UMFAClient(context, config)
    }

Returns

The initialized UMFAClient instance.

Configuration Parameters

Initialize the ZSMConfig object with the required configuration.

Parameters

Parameter NameData TypeDescriptionDefault Value
host_urlStringThe URL of the ZSM server.Required
application_idStringThe unique application identifier.Required
application_environmentStringThe environment name (e.g., "TEST", "PROD").Required, "TEST"
consumer_idStringThe consumer identifier.Required
authentication_hostStringAuthentication service host URL (if different from host_url).Same as host_url
headersJSONObject?Headers used while performing remote transactions.null
metadataJSONObject?Metadata provided with the request.null
request_timeout_msUIntNetwork timeout while performing remote transactions (in milliseconds).30000u
retry_countUIntNumber of retries for network transactions.0u
perform_network_health_checkBooleanWhether to perform a health check prior to instantiation.false
log_levelLogLevelThe logging level for the API..DEBUG
mpc_algorithmMPCAlgorithmThe encryption algorithm for transactions..ECDSAP256
requires_biometricsBooleanWhether to require biometrics (assumes implementation outside the API).true
logging(LogLevel, String) -> Unit)?A callback function for custom log handling.null

Configuring Logging

The ZSM SDK provides flexible logging configuration options. You can set the log level and provide a custom logging implementation to route log messages to your application's logging infrastructure.

Setting Log Level

You can set the log level either during initial configuration or after creating the ZSMConfig object:

// Option 1: During initialization
val config = ZSMConfig(JSONObject().apply {
    put("host_url", hostUrl)
    put("application_id", applicationId)
    put("consumer_id", consumerId)
    // Set log level directly in the config
    put("log_level", "TRACE")
})

// Option 2: After initialization
config.logLevel = LogLevel.TRACE

Custom Logging Implementation

You can provide a custom logging function that receives both the log level and message. This allows you to integrate with your application's logging infrastructure:

// Set custom logging function
config.logging = { level, message ->
    // Format the log message as needed
    val formattedMessage = "$level - $message"
    
    // Route to your logging system
    when (level) {
        LogLevel.TRACE -> Log.v("ZSM", formattedMessage)
        LogLevel.DEBUG -> Log.d("ZSM", formattedMessage)
        LogLevel.INFO -> Log.i("ZSM", formattedMessage)
        LogLevel.WARN -> Log.w("ZSM", formattedMessage)
        LogLevel.ERROR, LogLevel.FATAL -> Log.e("ZSM", formattedMessage)
    }
}

The logging function is called with two parameters:

  • level: A LogLevel enum value indicating the severity
  • message: The log message as a String

Log Levels

enum class LogLevel(val value: Int) {
    TRACE(-1),
    DEBUG(0),
    INFO(1),
    WARN(2),
    ERROR(3),
    FATAL(4)
}
LevelDescription
TRACEUsed for debugging purposes. This level of logging provides the most granular information at the lowest detailed level and includes network round trips.
DEBUGUsed for debugging purposes. This reveals timing information at a general level.
INFOUsed to record informational messages that highlight the progress of the application at a high level.
WARNIndicates potentially harmful situations.
ERRORUsed to record error events that might still allow the application to continue running.
FATALRecords very severe error events that will presumably lead the application to abort.

Returns

The initialized ZSMConfig object.

Java

The Java-friendly API allows the methods to be called using lambdas for seamless integration.

Usage

ZSMConfig config = new ZSMConfig(new JSONObject()
                    .put("host_url", this.getHostUrl())
                    .put("application_id", "########-####-####-####-############")
                    .put("consumer_id", this.getConsumerId())
                    .put("api_key", this.getApiKey())
                    .put("authentication_host", this.getApplicationHost())
            );

config.setLogLevel(LogLevel.TRACE); // Set the lowest level of logging
config.setLogging((level, message) -> {
    Log.d("Custom log", message);
});
UMFAClient client = new UMFAClient(context, config);

Returns

The initialized UMFAClient instance.

ZSMConfig Properties

PropertyTypeDescriptionDefault Value
host_urlStringThe URL of the ZSM server.Required
application_idStringUnique application identifierRequired
application_environmentStringThe environment name (e.g., "TEST", "PROD").Required, "TEST"
consumer_idStringThe consumer identifier.Required
authentication_hostStringAuthentication service host URL (if different from host_url).Same as host_url
headersJSONObject?Headers used while performing remote transactions.null
metadataJSONObject?Metadata provided with the request.null
request_timeout_msintNetwork timeout while performing remote transactions (in milliseconds).30000
retry_countintNumber of retries for network transactions.0
perform_network_health_checkbooleanWhether to perform a health check prior to instantiation.false
log_levelLogLevelThe logging level for the API.LogLevel.DEBUG
mpc_algorithmMPCAlgorithmThe encryption algorithm for transactions.MPCAlgorithm.ECDSAP256
requires_biometricsbooleanWhether to require biometrics (assumes implementation outside the API).true
loggingBiConsumer<LogLevel, String>A callback function for custom log handling.null

Configuring Logging

The ZSM SDK provides flexible logging configuration options. You can set the log level and provide a custom logging implementation to route log messages to your application's logging infrastructure.

Setting Log Level

You can set the log level either during initial configuration or after creating the ZSMConfig object:

// Option 1: During initialization
JSONObject configJson = new JSONObject()
    .put("host_url", hostUrl)
    .put("application_id", applicationId)
    .put("consumer_id", consumerId)
    // Set log level directly in the config
    .put("log_level", "TRACE");

ZSMConfig config = new ZSMConfig(configJson);

// Option 2: After initialization
config.setLogLevel(LogLevel.TRACE);

Custom Logging Implementation

You can provide a custom logging function that receives both the log level and message. This allows you to integrate with your application's logging infrastructure:

// Set custom logging function
config.setLogging((level, message) -> {
    // Format the log message as needed
    String formattedMessage = level + " - " + message;
    
    // Route to your logging system
    switch (level) {
        case TRACE:
            Log.v("ZSM", formattedMessage);
            break;
        case DEBUG:
            Log.d("ZSM", formattedMessage);
            break;
        case INFO:
            Log.i("ZSM", formattedMessage);
            break;
        case WARN:
            Log.w("ZSM", formattedMessage);
            break;
        case ERROR:
        case FATAL:
            Log.e("ZSM", formattedMessage);
            break;
    }
});

The logging function is called with two parameters:

  • level: A LogLevel enum value indicating the severity
  • message: The log message as a String

Log Levels

enum LogLevel {
    TRACE(-1),
    DEBUG(0),
    INFO(1),
    WARN(2),
    ERROR(3),
    FATAL(4);
}
LevelDescription
TRACEUsed for debugging purposes. This level of logging provides the most granular information at the lowest detailed level and includes network round trips.
DEBUGUsed for debugging purposes. This reveals timing information at a general level.
INFOUsed to record informational messages that highlight the progress of the application at a high level.
WARNIndicates potentially harmful situations.
ERRORUsed to record error events that might still allow the application to continue running.
FATALRecords very severe error events that will presumably lead the application to abort.

Returns

The initialized ZSMConfig object.