SDKs
...
Java SDK
Java Modules

Java License Client

24min

License Client is the basic module in LicenseSpring implementation. For most use cases it's the only module required for a successful LicenseSpring implementation.

To include License Client to your Maven/Gradle project use this snippet:

XML
Java


Javadoc, Jar and OSGi bundle downloads can be found here.

Initializing the License Client

All of the methods are accessed via the LicenseManager singleton - this means you initialize the SDK only once and use it various places in your application. As soon as you initialize the SDK, it will contact the LicenseSpring server to check if there is an existing license for the current computer/product combination.

If there is a current license available, it will be immediately accessible as a License object.

At the minimum there are three parameters you will need to initialize the SDK:

  • apiKey, your company API key
  • sharedKey, company-specific encryption key, used when signing requests
  • productCode, an alphanumeric code identifying a specific product

The apiKey andsharedKey are available in the LicenseSpring Platform under "Setting -> Settings -> Keys tab". The productCode is tied to a specific product the license applies to and is defined while creating the product.

Optional Configuration parameters for initializing the License Client SDK:

  • licenseFilePath determines where the license file will be stored on user's computer. By default, it is set to current working directory of the application with the filename license.key
  • offlineMode enables offline mode. In this mode no requests are sent to LicenseSpring servers. Default is false.
  • enablePeriodicCheck indicates if the Consumption APIs should be invoked periodically. Use with Consumption type licenses - when caching license state is required.
  • checkPeriod period of invocation of the checkLicense  method. Defaults to 1 hour if Duration object is not provided. Enabled by the enablePeriodicCheck flag.
  • requestLogging request logging for debug purposes, default is no request logging.
  • appName name of the application using the SDK.
  • appVersion manually set the version of the application that's using the SDK.
  • identityProvider set a custom IdentityProvider which generates unique keys for a particular device. Default implementation is based on Motherboard/CPU/Disk. See Java Hardware (Device) IDs for more information.
  • cacheHardwareId set to true to allow caching of hardware IDs. Default is false
  • gracePeriodDays period of days in which user can check License locally if API license check fails, this can either be a connection error or internal server error. Maximum of 30 days.
  • ignoreServerExceptions similar to gracePeriodDays, SDK will check License locally if API license check fails, but with no time limit
  • enableNegativeConsumptions enables the option to send negative consumptions, default is false.
  • proxyPort and proxyHost used to setup a forward proxy, see more in Java Advanced Usage.
  • requestTimeout set the timeout of requests make to API (in seconds), default is 10 seconds
  • storeMachineInfo - false by default. This toggles the collection of additional machine data, which includes:
    • hostname
    • ipAddress
    • macAddress
    • vmInfo
    • osInfo
  • infoToStore - specify what information to store, ignored if storeMachineInfo is false, defaults to ALL if left empty.
  • airGappedPublicKey - public key generated in the platform for air-gapped Licences
Java


LicenseManager

After setting up the SDK, there are a number of methods and objects available to the app developer. LicenseManager is a singleton that needs to be initialized once per runtime but can be retrieved using the getInstance method unlimited number of times.

Java


getCurrent()

In case no active license is available from the LicenseRepository, the return value will be null.

Java


getTrialLicense(String email)

You can generate a trial key directly from the app using the SDK, which will automatically associate this license key with the provided email. You can later use this data from the LicenseSpring platform to send out email campaigns targeting trial users for example.

After you generate a trial key - the UnactivatedTrialLicense object will be returned, you still need to activate it using a call to licenseManager.activateLicense()

Java


getTrialLicense(Customer customer)

You can generate a trial key directly from the app using the SDK, which will automatically associate this license key with the provided customer. Customer object can be built using the builder, only email is required.

Java


activateLicense(ActivationLicense identity)

Attempts to activate the product using provided ActivationIdentity. Returns the License object that has been activated.

Java


deactivateLicense(LicenseIdentity identity)

License is deactivated using a method on the LicenseManager. You need to supply the current license identity.

Java


checkLicense(License license)

Checks the license on the LS servers and syncs any consumptions made.

Java


getInstallationFile(LicenseIdentity identity)

Returns the latest valid installation file, if installation files are defined in the LicenseSpring platform. For more details please see Product Versioning.

Java


getVersions(LicenseIdentity identity)

Returns all the available versions for the product configured via configuration settings.

Java


trackVariables(LicenseIdentity identity, Map<String, String> variables)

Tracks device based variables for end uses. Can use the Variable builder as a utility.

Java


getProductDetails()

Gets product details from LicenseSpring servers.

Shell


offlineActivationFile(LicenseIdentity identity, String destination)

Generates an offline activation file which can be uploaded to LicenseSpring platform and activate the license. Default location for saving the file is Desktop, or if it can't be found, user home, this only applies if destination string is null. Default name of the file is "ls_activation.req". For more information, see Offline License Activation.

Java


offlineDeactivationFile(LicenseIdentity identity, String destination)

Generates an offline deactivation file which can be uploaded to LicenseSpring platform and deactivate the license. Default location for saving the file is Desktop, or if it can't be found, user home, this only applies if destination string is null. Default file name is ls_deactivation.req.

Java


activateOfflineResponse(LicenseIdentity identity, String filePath)

Activates the license from a file that was generated on the LicenseSpring platform. If the filePath is null, SDK will look for the file ls_activation.lic in Desktop, or in user home.

Java


clearLocalStorage()

Clears all local license data.

Shell


setOfflineMode(boolean offlineMode)

Changes the offline mode while the app is running. While offline, no requests to LS servers are made.

Java


getAirGapActivationCode

Gets the activation code use for air gapped license

Needs the LicenseSpringConfiguration field: airGappedPublicKey to work with Air Gap Licences

Java


verifyAirGapConfirmationCode

Verifies the confirmation code for air gapped license

Needs the LicenseSpringConfiguration field: airGappedPublicKey to work with Air Gap Licences

Java


activateAirGapResponse

Activates the air gapped license from the license policy file

Needs the LicenseSpringConfiguration field: airGappedPublicKey to work with Air Gap Licences

Java




Updated 26 Jun 2024
Doc contributor
Doc contributor
Doc contributor
Did this page help you?