![]() |
LicenseSpring C++ SDK
7.31.0
Easily add Software Licensing to your application
|
Class for performing basic requests to LicenseSpring backend and managing licenses. More...
#include <LicenseSpring/LicenseManager.h>
Public Types | |
using | ptr_t = std::shared_ptr< LicenseManager > |
Public Member Functions | |
LicenseManager (Configuration::ptr_t config, LicenseStorage::ptr_t storage=nullptr) | |
Construct LicenseManager object and initialize it with given configuration. More... | |
~LicenseManager () override | |
Destroy license manager and its configuration if there is no more references to the configuration. More... | |
LicenseID | getTrialLicense (Customer::ptr_t user=nullptr, const std::string &licensePolicy=std::string()) |
Request trial license from LicenseSpring backend. More... | |
LicenseID | getTrialLicense (const std::string &userEmail) |
Request trial license from LicenseSpring backend. More... | |
std::string | getSSOUrl (const std::string &accountCode=std::string(), bool useAuthCode=true) |
Get URL for Single sign-on license activation. More... | |
std::string | getAirGapActivationCode (const std::string &initializationCode, const std::string &licenseKey) |
Get air gap Activation code. More... | |
const License::ptr_t | activateAirGapLicense (const std::string &confirmationCode, const std::wstring &policyPath, const std::string &licenseKey, uint32_t policyId) |
Verify Confirmation code and activate air gap license using given license policy or policies. More... | |
const License::ptr_t | activateLicense (const LicenseID &licenseID) |
Activate license with given LicenseID. More... | |
const License::ptr_t | activateLicense (const std::string &authData, const std::string &accountCode=std::string(), bool useAuthCode=true) |
Activate license using SSO. More... | |
const License::ptr_t | activateLicenseOffline (const std::wstring &activationResponseFile=std::wstring()) |
Activate license offline with provided activation file. More... | |
const License::ptr_t | relinkLicense (DeviceIDAlgorithm deviceIdAlgorithm, const std::string &userPassword="") |
This method helps upgrade to new device id algorithm. It deactivates current license with old device id and activate with new one. Internet connection is required. More... | |
bool | changePassword (const std::string &user, const std::string &password, const std::string &newPassword) |
Change user password, meaningful only for user-based products. More... | |
std::vector< std::string > | getVersionList (const LicenseID &licenseID, const InstallFileFilter &filter=InstallFileFilter()) |
Get app version list available for given license. More... | |
InstallationFile::ptr_t | getInstallationFile (const LicenseID &licenseID, const std::string &version=std::string(), const InstallFileFilter &filter=InstallFileFilter()) |
Get InstallationFile information for given license. More... | |
std::wstring | createOfflineActivationFile (const LicenseID &licenseID, const std::wstring &activationRequestFile=std::wstring()) |
Creates offline activation file request. More... | |
bool | isOnline (bool throwExceptions=false) const |
Helper method, it checks connection to the LicenseSpring backend. More... | |
std::vector< LicenseUser::ptr_t > | getLicenseUsers (const Customer &customer) |
Get license users list by given customer (license owner). More... | |
std::vector< LicenseUser::ptr_t > | getLicenseUsers (const std::string &customerEmail) |
Overloaded method. See notes above. Get license users list by given customer email. More... | |
![]() | |
BaseManager (Configuration::ptr_t config, LicenseStorage::ptr_t storage=nullptr) | |
Create and intialize license manager with given configuration. More... | |
BaseManager (const BaseManager &)=delete | |
BaseManager & | operator= (const BaseManager &)=delete |
virtual | ~BaseManager () |
Destroy LicenseManger with current configuration. More... | |
Configuration::ptr_t | currentConfig () const |
Returns current configuration. More... | |
void | reconfigure (Configuration::ptr_t config) |
Change current configuration. More... | |
ProductDetails | getProductDetails (bool includeLatestVersion=false) |
Get basic information from the backend on product which corresponds to the current configuration. More... | |
const License::ptr_t | getCurrentLicense () |
Load license from local storage (if not yet loaded). More... | |
const License::ptr_t | reloadLicense () |
Resets current license and loads it again from local storage. More... | |
void | clearLocalStorage () |
Remove local license, other files and folders created by LicenseSpring, usually should be called at app uninstallation. More... | |
const std::wstring & | dataLocation () const |
Absolute folder path where LicenseSpring data is stored. More... | |
void | setDataLocation (const std::wstring &path) |
Set absolute or relative path to folder where LicenseSpring data should be stored. More... | |
std::wstring | licenseFileName () const |
Return license file name with extension, unless filename was explicitly set to be without extension. More... | |
void | setLicenseFileName (const std::wstring &name) |
Set license file name, it can be with or without extension. More... | |
std::wstring | licenseFilePath () const |
Return concatenated dataLocation() and licenseFileName(). More... | |
Static Public Member Functions | |
static LicenseManager::ptr_t | create (Configuration::ptr_t config, LicenseStorage::ptr_t storage=nullptr) |
Creates LicenseManager object and initialize it with given configuration. More... | |
Additional Inherited Members | |
![]() | |
void | reset () |
Reset (delete) members. More... | |
![]() | |
Configuration::ptr_t | m_config |
std::shared_ptr< DataHandler > | m_dataHandler |
LicenseService * | m_pLicenseService |
License::ptr_t | m_currentLicense |
Class for performing basic requests to LicenseSpring backend and managing licenses.
Used mainly for activating licenses (online/offline/trial). Also useful for getting the SSO URL, changing a user's password, and getting other information such as list of versions for a product, installation files, and license users.
Definition at line 17 of file LicenseManager.h.
using LicenseSpring::LicenseManager::ptr_t = std::shared_ptr<LicenseManager> |
Definition at line 20 of file LicenseManager.h.
LicenseSpring::LicenseManager::LicenseManager | ( | Configuration::ptr_t | config, |
LicenseStorage::ptr_t | storage = nullptr |
||
) |
Construct LicenseManager object and initialize it with given configuration.
ConfigurationException | If config is null |
|
override |
Destroy license manager and its configuration if there is no more references to the configuration.
|
static |
Creates LicenseManager object and initialize it with given configuration.
config | Configuration object to use |
storage | Storage for local license, by default local license is saved in a file |
ConfigurationException | If config is null |
LicenseID LicenseSpring::LicenseManager::getTrialLicense | ( | Customer::ptr_t | user = nullptr , |
const std::string & | licensePolicy = std::string() |
||
) |
Request trial license from LicenseSpring backend.
If you provide user (customer) information please note that user's email is required field.
Furthermore, if the initial password for the corresponding user's email has been changed, the license identifier returned will have an empty string for a password.
If user is null you will get anonymous trial (available only for key-based products).
user | Customer information. Optional param for key-based products, but required for user-based products. |
licensePolicy | Optional license policy code, if omited the default license policy for the product will be used. |
TrialNotAllowedException | In case getting trial is not allowed by product license policy |
ProductNotFoundException | In case configured product does not exist |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, for example unexpected server response |
LicenseID LicenseSpring::LicenseManager::getTrialLicense | ( | const std::string & | userEmail | ) |
Request trial license from LicenseSpring backend.
userEmail | User ID, usually email address |
TrialNotAllowedException | In case getting trial is not allowed by product license policy |
ProductNotFoundException | In case configured product does not exist |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
std::string LicenseSpring::LicenseManager::getSSOUrl | ( | const std::string & | accountCode = std::string() , |
bool | useAuthCode = true |
||
) |
Get URL for Single sign-on license activation.
You can omit accountCode param if you already set customer account code through the Configuration.
accountCode | Customer account code |
useAuthCode | Boolean value indicating whether this method should create the redirect_uri with auth code instead of id_token. |
SSOException | In case customer was not found or SSO is not enabled |
ProductNotFoundException | In case configured product does not exist |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
std::string LicenseSpring::LicenseManager::getAirGapActivationCode | ( | const std::string & | initializationCode, |
const std::string & | licenseKey | ||
) |
Get air gap Activation code.
initializationCode | Code received from the air gap activation portal. |
licenseKey | License key of air gap license. |
const License::ptr_t LicenseSpring::LicenseManager::activateAirGapLicense | ( | const std::string & | confirmationCode, |
const std::wstring & | policyPath, | ||
const std::string & | licenseKey, | ||
uint32_t | policyId | ||
) |
Verify Confirmation code and activate air gap license using given license policy or policies.
confirmationCode | Code received from the air gap activation portal. |
policyPath | Policy file path or folder path which contains several policy files. |
licenseKey | License key. |
policyId | Id of the license policy. |
SignatureMismatchException | In case signature inside activation file is not valid. |
LicenseActivationException | If invalid policy file provided. |
AirGapActivationException | In case confirmation code from the air gap activation portal is invalid. |
const License::ptr_t LicenseSpring::LicenseManager::activateLicense | ( | const LicenseID & | licenseID | ) |
Activate license with given LicenseID.
Send activate license request to the backend, creates a local license file if succesful.
licenseID | License identifier that needs to be activated |
InvalidCredentialException | If user and password combination is incorrect |
ProductNotFoundException | In case configured product does not exist |
LicenseNotFoundException | In case provided license was not found |
LicenseStateException | If license is disabled or expired |
LicenseNoAvailableActivationsException | If license was already activated maximum number of times |
CannotBeActivatedNowException | If start_date field is set for the license and current date is behind start date |
SignatureMismatchException | In case signature returned by LicenseSpring server is not valid |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
const License::ptr_t LicenseSpring::LicenseManager::activateLicense | ( | const std::string & | authData, |
const std::string & | accountCode = std::string() , |
||
bool | useAuthCode = true |
||
) |
Activate license using SSO.
You can omit accountCode param if you already set customer account code through the Configuration.
authData | id_token or code you get after user authorization with SSO |
accountCode | Customer account code |
useAuthCode | Whether to use auth code instead of id_token for activation |
SSOException | In case customer was not found or SSO is not enabled |
SSOTokenException | In case SSO token is invalid or expired |
ProductNotFoundException | In case configured product does not exist |
LicenseNotFoundException | In case provided license was not found |
LicenseStateException | If license is disabled or experid |
LicenseNoAvailableActivationsException | If license was already activated maximum number of times |
CannotBeActivatedNowException | If start_date field is set for the license and current date is behind start date |
SignatureMismatchException | In case signature returned by LicenseSpring server is not valid |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
const License::ptr_t LicenseSpring::LicenseManager::activateLicenseOffline | ( | const std::wstring & | activationResponseFile = std::wstring() | ) |
Activate license offline with provided activation file.
Default location for activation files is Desktop location, default file name is 'ls_activation.lic'.
activationResponseFile | Activation response file path, empty means use default location and file name |
SignatureMismatchException | In case signature inside activation file is not valid or license does not belong to current device. |
LocalLicenseException | If invalid activation file provided |
ProductMismatchException | If license product code does not correspond to configuration product code |
DeviceNotLicensedException | If license file does not belong to current device. |
const License::ptr_t LicenseSpring::LicenseManager::relinkLicense | ( | DeviceIDAlgorithm | deviceIdAlgorithm, |
const std::string & | userPassword = "" |
||
) |
This method helps upgrade to new device id algorithm. It deactivates current license with old device id and activate with new one. Internet connection is required.
Local license is required to call this method. May throw exceptions the same as ActivateLicense and License::deactivate methods.
deviceIdAlgorithm | Device id algorithm generation you would like to upgrade to |
userPassword | Optional param, user password, meaningful only for user-based licenses |
ProductNotFoundException | Thrown when there is no local license exists |
ProductMismatchException | If license product code does not correspond to configuration product code |
DeviceNotLicensedException | If reactivation is not possible (e.g. license copied from other device) |
bool LicenseSpring::LicenseManager::changePassword | ( | const std::string & | user, |
const std::string & | password, | ||
const std::string & | newPassword | ||
) |
Change user password, meaningful only for user-based products.
user | User ID, usually email in lowercase |
password | User password |
newPassword | New password |
PasswordChangeNotAllowedException | If changing password is forbidden |
InvalidCredentialException | If user or password is wrong |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
std::vector<std::string> LicenseSpring::LicenseManager::getVersionList | ( | const LicenseID & | licenseID, |
const InstallFileFilter & | filter = InstallFileFilter() |
||
) |
Get app version list available for given license.
licenseID | License identifier |
filter | Optional, you can filter install files by environment and channel |
ProductNotFoundException | In case configured product does not exist |
LicenseNotFoundException | In case provided license was not found |
LicenseStateException | If license is disabled |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
InstallationFile::ptr_t LicenseSpring::LicenseManager::getInstallationFile | ( | const LicenseID & | licenseID, |
const std::string & | version = std::string() , |
||
const InstallFileFilter & | filter = InstallFileFilter() |
||
) |
Get InstallationFile information for given license.
licenseID | License identifier |
version | Desired product (app) version, optional, if not provided then last available version assumed |
filter | Optional, you can filter install files by environment and channel |
ProductNotFoundException | In case configured product does not exist |
ProductVersionException | If installation file not found for requested app version |
LicenseNotFoundException | In case provided license was not found |
LicenseStateException | If license is disabled |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
std::wstring LicenseSpring::LicenseManager::createOfflineActivationFile | ( | const LicenseID & | licenseID, |
const std::wstring & | activationRequestFile = std::wstring() |
||
) |
Creates offline activation file request.
licenseID | License identifier |
activationRequestFile | Activation request file path, null means use default path (Desktop)/ls_activation.req |
bool LicenseSpring::LicenseManager::isOnline | ( | bool | throwExceptions = false | ) | const |
Helper method, it checks connection to the LicenseSpring backend.
throwExceptions | Indicates whether this method should throw exceptions |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
std::vector<LicenseUser::ptr_t> LicenseSpring::LicenseManager::getLicenseUsers | ( | const Customer & | customer | ) |
Get license users list by given customer (license owner).
customer | Customer who ordered the license(s) |
ProductNotFoundException | In case configured product does not exist |
NoInternetException | If cannot reach the server |
NetworkTimeoutException | In case of network timeout |
LicenseServerException | In case of internal server error |
UnknownLicenseSpringException | In rare case if something went wrong, please contact support |
std::vector<LicenseUser::ptr_t> LicenseSpring::LicenseManager::getLicenseUsers | ( | const std::string & | customerEmail | ) |
Overloaded method. See notes above. Get license users list by given customer email.
customerEmail | Customer email |