License Checks
License checks have a crucial role in the protection of your application.
This guide will explain online and offline license checks, their efficient organization within the application, and the implementation of a grace period.
Before proceeding, make sure you have completed the Getting Started Tutorial C++ or Getting Started Tutorial .Net and accomplished the following steps:
- Initialize LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.
- Activate a license for your application.
- Implement the mechanism to retrieve the current license.
Local check does not require an Internet connection and performs the following actions:
- Verify if the license is enabled, active, and valid. If the license is not in a valid state, it will raise LicenseStateException in C++ or the following exceptions in .Net:
- LicenseDeletedException,
- LicenseDisabledException,
- TrialLicenseExpiredException,
- LicenseExpiredException,
- LicenseInactiveException.
- Confirm if the license belongs to the configured product. If the product code of the license and configuration do not match, it will raise ProductMismatchException.
- Detect cheating with the system clock. If cheating is detected, it will raise ClockTamperedException (C++) or DateTimeCheatingException (.Net).
- Ensure that the license belongs to the device. If the license doesn't belong to the device, it will raise DeviceNotLicensedException.
- If VM detection is enabled, check if the device is a VM and if the license allows virtual machines. If VMs are not allowed, and the application is running on a VM, it will raise VMIsNotAllowedException.
- For floating licenses, verify if the floating timeout has expired. If the timeout is expired, it will raise FloatingTimeoutExpiredException.
To perform a local check, call the LocalCheck method:
- Verify if the license is enabled, active, and valid. If the license is not in a valid state, it will raise LicenseStateException in C++ or the following exceptions in .Net:
- LicenseDeletedException,
- LicenseDisabledException,
- TrialLicenseExpiredException,
- LicenseExpiredException,
- LicenseInactiveException.
- Synchronize the consumption of consumption licenses and features. If there is not enough consumption left, it will raise NotEnoughConsumptionException.
- Update the license with data from the license server.
- Retrieve the most recent installation file for the product.
- Register a floating license. If there are no floating slots available, it will raise MaxFloatingReachedException.
It can throw the exceptions related to connection issues: NetworkException, NetworkTimeoutException, and LicenseServerException. You can implement a grace period to allow using the application without connection to the server for a limited period.
To run the online check call Check method:
License checks can take up to a couple of seconds. It is recommended to run them in a background thread.
Perform local checks on every application startup to ensure the user has a valid license.
However, since calling an online check at every start of the application is redundant, we recommend performing it every few days, using the last check date value saved in the license.
If you need to synchronize consumption more often, you can use SyncConsumption and SyncFeatureConsumption methods.
A grace period can be helpful when you don't want to restrict application usage due to online check failures caused by the lack of an internet connection or internal LicenseSpring server issues.
To implement this, define how long it is allowed to use the application without connecting to the server and handle network exceptions accordingly.
The grace period feature is available in C++ SDK from v7.26.0 and in .Net SDK from v7.22.0. It covers License::check, License::syncConsumption, License::syncFeatureConsumption, and License::sendDeviceVariables methods.
Do not confuse grace period and subscription grace period. To learn more about the subscription grace period, see: Subscription Licenses
By default grace period is 48 hours. You can set another value using:
The License class has methods to check if the grace period started and get the grace period end date:
The grace period starts when one of the covered requests fails and resets after a successful request. For cloud floating licenses with a grace period, the exceptions on online checks will be ignored only if more than an hour of the floating period remains.