Configuring the Activation
The license is represented by the Activation
object, and there should be only a single instance of the Activation
class created for every seat in your app (usually only one, in case your application needs to hold multiple activation instances for more products, see "Multiple Activations Support" page). The state of the Activation
can be accessed through the Activation.getState()
method.
Configure Activation instance
The following command will create a new instance of the Activation
object in Uninitialized
state. Before configuring the activation, collect the Tenant ID and Licensing API URL from the Account -> API Credentials page in the UI.
ActivationOptions activationOptions = new ActivationOptions(
tenandId,
productId,
() -> seatId,
storage,
onlineActivationOptions,
offlineActivationOptions,
activationOperationLock);
// configure the options by following the instructions below
IActivation activation = new Activation(activationOptions, persistence);
There are the following configuration options available:
Tenant ID - ID of the tenant. Can be retrieved from the API Credentials page.
Product ID - the product for which we are implementing the licensing.
Seat ID - represents the machine, the user, or some other element which the license should be linked with. Because the seat ID usually depends on the information that is only available at runtime, it is configured as a function. We recommend using the Device Fingerprint functionality for the machine-specific seat ID.
Storage - holds the licensing data, which needs to be persisted on the machine, where your application is running. In the case of the desktop application, the usual choice is a file, and that's why we are providing a PlainTextActivationFileStorage in our SDK. Please note that the data in our PlainTextActivationFileStorage implementation are not encrypted, which allows the user to manipulate and export the licensing data.
Depending on your use case, we recommend using your own implementation of the
IActivationStorage
interface or the SecureActivationStorage that leverages the Zentitle2Core library secure storage implementation.IActivationStorage storage = new PlainTextFileActivationStorage("pathToTheFile")
Online Activation - allows the license activation when there is a network connection to the Licensing server. For the online activation, the following options need to be configured:
Licensing API URL - Licensing API base URL
HTTP Client Factory - HttpClient callback providing an HTTP Client for executing the Licensing API calls. The factory method enables the implementation of the proper HTTP Client's lifetime management, depending on your app's type. See the Documentation for more details.
IPersistence persistence = new Persistence( licenseStorage, new DateTimeProvider()); LicensingApiOptions licensingApiOptions = new LicensingApiOptions( apiUrl, tenantId, persistence::getAccessToken, persistence::getApiNonce, persistence::setApiNonce); CloseableHttpClient httpClient = HttpClientFactory.createHttpClient( licensingApiOptions); OnlineActivationOptions onlineActivationOptions = new OnlineActivationOptions( licensingApiUrl, () -> httpClient);
Offline Activation - In rare cases when a machine lacks a network connection but the license needs to be activated anyway, offline activation can be configured in your application.
Logging - SDK's logs are available via the implementation of the
SLF4J
interface. To have access to logs, it is necessary to add a logging framework implementing theSLF4J
interface (Logback, Log4j, etc.) as a dependency. It is also necessary to configure the logging framework properly.Activation Operation Lock - the
Activation
class uses a locking mechanism that makes it thread-safe and prevents the parallel execution of multiple activation methods, which might lead to an inconsistent activation state. The default lock leverages Semaphore, but if you need a custom locking mechanism, you can provide your own implementation of theIActivationOperationLock
interface.State Transition Callback - if you want to "hook your own code" into the activation's state transition logic, you can define a callback, which is executed after the state has been changed.
activationOptions.setTransitionToNewStateCallback((oldState, updatedActivation) -> logger.info("Activation state changed from [{}] to [{}]", oldState, updatedActivation.getState()));
Last updated
Was this helpful?