License Features
Validating Licenses with Key-Value Features
When generating a license within the LICENSE4J system, you have the powerful option to define custom features
using key-value pairs directly within the license generation interface. This allows you to precisely tailor each
license to your specific requirements, embedding unique attributes and functionalities. Simply enter your
desired keys and their corresponding values in the designated fields to effectively define these features. This
granular control ensures the generated license perfectly aligns with your product's capabilities and your
business model.
The defined license features can be thoroughly verified at multiple stages to ensure compliance and prevent
unauthorized use. This verification can occur either during the initial license validation process on the
server-side—where the license server checks if the features presented by the client match those stored for the
activated license—or through a manual verification after the initial validation has taken place. This process
involves examining specific attributes and functionalities outlined in the license to confirm they align with
the granted terms. By rigorously validating these features, you can confidently confirm that the software is
being used in accordance with the agreed-upon licensing conditions, thereby upholding compliance and
safeguarding your intellectual property.
Feature Validation on the License Server
To ensure proper license validation and activation on the server, as well as the accurate recording of license
usage, it's critical that the features defined within the Builder class on the client-side precisely match those
configured on the license server. The server's process for validating licenses and generating usage records is
entirely contingent upon this alignment. If the feature key-value pairs transmitted from the client do not
correspond with the server's expected features for that specific product, the validation and activation will fail,
preventing unauthorized use and ensuring licensing terms are met.
In the example provided below, we've defined a license feature key as "edition." This allows you to associate a
specific software edition (e.g., "Standard," "Pro," "Enterprise") with a license. When your software performs a
license validation, it will check if the edition value from your application matches the "edition" feature value
stored within the license itself.
// Validate the given license key with edition
License.getInstance().getBuilder()
.product("some-hash-value")
.feature("edition", mySoftwareEdition)
.build();
This mechanism enables you to effectively validate licenses based on different editions of your software. If the
edition specified in your application does not align with the edition present in the validated license, the
license will not be considered valid, and its status will be marked accordingly. This ensures that users can only
access the software edition for which they are licensed.
To implement version-based license validation, define a key (e.g., "version," "software-version") and a maximum
valid version number (e.g., 1.99) when generating a license on your server. During license validation, set a
feature in your build method with the same key name and your software's current version. The license will be valid
for all versions up to and including the one defined in the license (e.g., 1.99). Ensure the version is in double
format, as the licensing library converts it to a double for comparison.
// Validate the given license key with version
License.getInstance().getBuilder()
.product("some-hash-value")
.feature("version", "1.1")
.build();
This approach ensures that users with a 1.x license can continue to use any minor or patch releases within that
major version. However, upon the release of version 2.x of your software, licenses tied to version 1.x will no
longer be valid. This provides a clear mechanism to manage software upgrades and ensure users acquire new licenses
for major version releases.
Manual Feature Verification Post-Validation/Activation
Beyond initial server-side validation, the LICENSE4J library allows for manual verification of individual license
features after a successful primary license validation. This approach is particularly useful when you intend to
license certain software functionalities independently.
The process involves first validating the core license without explicitly defining the desired feature in the
builder. Once the main license is validated, you can then programmatically check for the presence and value of
specific features within the validated license object.
This capability is ideal for implementing tiered licensing models or in-app purchases for additional features. For
instance, you might sell a basic license that covers core functionalities, with premium features available as
separate add-ons. When a customer attempts to use a "paid" feature within your software, you would simply query
the validated license to confirm if that specific feature is included before either allowing or rejecting the
operation. This provides immense flexibility, enabling scenarios like enabling or disabling specific modules,
controlling access to advanced tools, or even temporarily unlocking trial features based on license attributes.
As demonstrated in the example below, you can retrieve all features defined within a license and then compare them
against any desired value. This allows for flexible and granular control over software functionality based on the
specific entitlements embedded in each license.
// check a feature
License.getInstance()
.getLicenseInformation().getFeature("SomeFeature").getValue().equals("SomeValue");
// check a feature
License.getInstance()
.getLicenseInformation().getFeature("ThisIsATrialLicense").getValue().equals("true");
Versatile Validation of Licensing Features
The LICENSE4J library provides a wide array of options for effectively utilizing specific licensing features. This
robust flexibility allows any element of your software or service to be comprehensively validated, either during
the initial license validation process or subsequently, after the primary validation has taken place.
This dual-stage validation capability is crucial for implementing diverse licensing models tailored to various
user needs and intricate business scenarios. For instance, you can enforce base software access through initial
validation, then control access to individual modules, premium features, or specific usage limits by checking
custom features within the validated license. This flexibility empowers organizations to craft highly customized
licensing strategies that not only enhance compliance with licensing terms but also optimize the user experience
by delivering precisely the features and functionalities that users are entitled to.