LicenseSpring C++ SDK 7.31.0
Easily add Software Licensing to your application
LicenseSpring::LicenseManager Class Reference

Class for performing basic requests to LicenseSpring backend and managing licenses. More...

#include <LicenseSpring/LicenseManager.h>

Inheritance diagram for LicenseSpring::LicenseManager:
LicenseSpring::BaseManager

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_tgetLicenseUsers (const Customer &customer)
 Get license users list by given customer (license owner). More...
 
std::vector< LicenseUser::ptr_tgetLicenseUsers (const std::string &customerEmail)
 Overloaded method. See notes above. Get license users list by given customer email. More...
 
- Public Member Functions inherited from LicenseSpring::BaseManager
 BaseManager (Configuration::ptr_t config, LicenseStorage::ptr_t storage=nullptr)
 Create and intialize license manager with given configuration. More...
 
 BaseManager (const BaseManager &)=delete
 
BaseManageroperator= (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

- Protected Member Functions inherited from LicenseSpring::BaseManager
void reset ()
 Reset (delete) members. More...
 
- Protected Attributes inherited from LicenseSpring::BaseManager
Configuration::ptr_t m_config
 
std::shared_ptr< DataHandler > m_dataHandler
 
LicenseService * m_pLicenseService
 
License::ptr_t m_currentLicense
 

Detailed Description

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.

Member Typedef Documentation

◆ ptr_t

Definition at line 20 of file LicenseManager.h.

Constructor & Destructor Documentation

◆ LicenseManager()

LicenseSpring::LicenseManager::LicenseManager ( Configuration::ptr_t  config,
LicenseStorage::ptr_t  storage = nullptr 
)

Construct LicenseManager object and initialize it with given configuration.

Exceptions
ConfigurationExceptionIf config is null

◆ ~LicenseManager()

LicenseSpring::LicenseManager::~LicenseManager ( )
override

Destroy license manager and its configuration if there is no more references to the configuration.

Member Function Documentation

◆ create()

static LicenseManager::ptr_t LicenseSpring::LicenseManager::create ( Configuration::ptr_t  config,
LicenseStorage::ptr_t  storage = nullptr 
)
static

Creates LicenseManager object and initialize it with given configuration.

Parameters
configConfiguration object to use
storageStorage for local license, by default local license is saved in a file
Exceptions
ConfigurationExceptionIf config is null
Returns
Shared pointer to LicenseManager object.

◆ getTrialLicense() [1/2]

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).

Parameters
userCustomer information. Optional param for key-based products, but required for user-based products.
licensePolicyOptional license policy code, if omited the default license policy for the product will be used.
Returns
Trial license identifier ready for activation.
Exceptions
TrialNotAllowedExceptionIn case getting trial is not allowed by product license policy
ProductNotFoundExceptionIn case configured product does not exist
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, for example unexpected server response
Warning
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. The password will need to be added manually.
Note
There are multiple methods with the same name and different parameters.

◆ getTrialLicense() [2/2]

LicenseID LicenseSpring::LicenseManager::getTrialLicense ( const std::string &  userEmail)

Request trial license from LicenseSpring backend.

Parameters
userEmailUser ID, usually email address
Returns
Trial license identifier ready for activation.
Exceptions
TrialNotAllowedExceptionIn case getting trial is not allowed by product license policy
ProductNotFoundExceptionIn case configured product does not exist
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support
Warning
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. The password will need to be added manually.
Note
There are multiple methods with the same name and different parameters.

◆ getSSOUrl()

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.

Parameters
accountCodeCustomer account code
useAuthCodeBoolean value indicating whether this method should create the redirect_uri with auth code instead of id_token.
Returns
URL for Single sign-on.
Exceptions
SSOExceptionIn case customer was not found or SSO is not enabled
ProductNotFoundExceptionIn case configured product does not exist
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support

◆ getAirGapActivationCode()

std::string LicenseSpring::LicenseManager::getAirGapActivationCode ( const std::string &  initializationCode,
const std::string &  licenseKey 
)

Get air gap Activation code.

Parameters
initializationCodeCode received from the air gap activation portal.
licenseKeyLicense key of air gap license.
Returns
Air gap Activation code. Empty string in case of error.

◆ activateAirGapLicense()

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.

Parameters
confirmationCodeCode received from the air gap activation portal.
policyPathPolicy file path or folder path which contains several policy files.
licenseKeyLicense key.
policyIdId of the license policy.
Returns
License if activation succeeded.
Exceptions
SignatureMismatchExceptionIn case signature inside activation file is not valid.
LicenseActivationExceptionIf invalid policy file provided.
AirGapActivationExceptionIn case confirmation code from the air gap activation portal is invalid.

◆ activateLicense() [1/2]

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.

Parameters
licenseIDLicense identifier that needs to be activated
Returns
Shared pointer to License if activation succeeded, throws exceptions in case of errors.
Exceptions
InvalidCredentialExceptionIf user and password combination is incorrect
ProductNotFoundExceptionIn case configured product does not exist
LicenseNotFoundExceptionIn case provided license was not found
LicenseStateExceptionIf license is disabled or expired
LicenseNoAvailableActivationsExceptionIf license was already activated maximum number of times
CannotBeActivatedNowExceptionIf start_date field is set for the license and current date is behind start date
SignatureMismatchExceptionIn case signature returned by LicenseSpring server is not valid
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support
Note
There are multiple methods with the same name and different parameters.

◆ activateLicense() [2/2]

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.

Parameters
authDataid_token or code you get after user authorization with SSO
accountCodeCustomer account code
useAuthCodeWhether to use auth code instead of id_token for activation
Returns
Shared pointer to License if activation succeeded, throws exceptions in case of errors.
Exceptions
SSOExceptionIn case customer was not found or SSO is not enabled
SSOTokenExceptionIn case SSO token is invalid or expired
ProductNotFoundExceptionIn case configured product does not exist
LicenseNotFoundExceptionIn case provided license was not found
LicenseStateExceptionIf license is disabled or experid
LicenseNoAvailableActivationsExceptionIf license was already activated maximum number of times
CannotBeActivatedNowExceptionIf start_date field is set for the license and current date is behind start date
SignatureMismatchExceptionIn case signature returned by LicenseSpring server is not valid
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support
Note
There are multiple methods with the same name and different parameters.

◆ activateLicenseOffline()

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'.

Parameters
activationResponseFileActivation response file path, empty means use default location and file name
Returns
Shared pointer to License if activation succeeded or null if file not found.
Exceptions
SignatureMismatchExceptionIn case signature inside activation file is not valid or license does not belong to current device.
LocalLicenseExceptionIf invalid activation file provided
ProductMismatchExceptionIf license product code does not correspond to configuration product code
DeviceNotLicensedExceptionIf license file does not belong to current device.

◆ relinkLicense()

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.

Parameters
deviceIdAlgorithmDevice id algorithm generation you would like to upgrade to
userPasswordOptional param, user password, meaningful only for user-based licenses
Returns
License if reactivation succeeded
Exceptions
ProductNotFoundExceptionThrown when there is no local license exists
ProductMismatchExceptionIf license product code does not correspond to configuration product code
DeviceNotLicensedExceptionIf reactivation is not possible (e.g. license copied from other device)

◆ changePassword()

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.

Parameters
userUser ID, usually email in lowercase
passwordUser password
newPasswordNew password
Returns
True if successfully changed.
Exceptions
PasswordChangeNotAllowedExceptionIf changing password is forbidden
InvalidCredentialExceptionIf user or password is wrong
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support

◆ getVersionList()

std::vector< std::string > LicenseSpring::LicenseManager::getVersionList ( const LicenseID licenseID,
const InstallFileFilter filter = InstallFileFilter() 
)

Get app version list available for given license.

Parameters
licenseIDLicense identifier
filterOptional, you can filter install files by environment and channel
Returns
List of versions available for the license.
Exceptions
ProductNotFoundExceptionIn case configured product does not exist
LicenseNotFoundExceptionIn case provided license was not found
LicenseStateExceptionIf license is disabled
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support

◆ getInstallationFile()

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.

Parameters
licenseIDLicense identifier
versionDesired product (app) version, optional, if not provided then last available version assumed
filterOptional, you can filter install files by environment and channel
Returns
Shared pointer to InstallationFile object.
Exceptions
ProductNotFoundExceptionIn case configured product does not exist
ProductVersionExceptionIf installation file not found for requested app version
LicenseNotFoundExceptionIn case provided license was not found
LicenseStateExceptionIf license is disabled
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support

◆ createOfflineActivationFile()

std::wstring LicenseSpring::LicenseManager::createOfflineActivationFile ( const LicenseID licenseID,
const std::wstring &  activationRequestFile = std::wstring() 
)

Creates offline activation file request.

Parameters
licenseIDLicense identifier
activationRequestFileActivation request file path, null means use default path (Desktop)/ls_activation.req
Returns
Path to offline activation request file.

◆ isOnline()

bool LicenseSpring::LicenseManager::isOnline ( bool  throwExceptions = false) const

Helper method, it checks connection to the LicenseSpring backend.

Parameters
throwExceptionsIndicates whether this method should throw exceptions
Returns
True if SDK is able to connect to the LicenseSpring backend and false otherwise.
Exceptions
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support

◆ getLicenseUsers() [1/2]

std::vector< LicenseUser::ptr_t > LicenseSpring::LicenseManager::getLicenseUsers ( const Customer customer)

Get license users list by given customer (license owner).

See also
https://docs.licensespring.com/docs/apiv4customerlicenseusers
Parameters
customerCustomer who ordered the license(s)
Returns
List of license users for given customer.
Exceptions
ProductNotFoundExceptionIn case configured product does not exist
NoInternetExceptionIf cannot reach the server
NetworkTimeoutExceptionIn case of network timeout
LicenseServerExceptionIn case of internal server error
UnknownLicenseSpringExceptionIn rare case if something went wrong, please contact support
Note
There are multiple methods with the same name and different parameters.

◆ getLicenseUsers() [2/2]

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.

Parameters
customerEmailCustomer email
Returns
List of license users for given customer email.
Note
There are multiple methods with the same name and different parameters.

The documentation for this class was generated from the following file: