License4J Java Software Licensing, License Manager
- Latest version 4.6.8 -
Videos | Runtime Library Integration | Quick Start Integration | License Manager GUI | Online.License4J
easyValidate Integration | Floating License Server | Auto License Generation and Activation Server

License4J Runtime Library Integration

License Manager Download package includes sample applications for license validation of all supported license types. Basically, runtime library has static methods for license validation(LicenseValidator.validate) and activation(LicenseValidator.autoActivate), after validation or activation of a license, status can be obtained with other static methods (LicenseValidator.getValidationStatus, LicenseValidator.getActivationStatus. Result of validation and activation status are enumeration objects.

License Text Validation:

License text usually is provided to customers in a text file. License file contents should be read into a string before validation, for this you can use a simple class provided in com.license4j.util.FileUtils package.
        String licenseString = FileUtils.readFile("path to license file");
                
        License license = LicenseValidator.validate(
                                    licenseString,          // REQUIRED - license string
                                    publickeyString,        // REQUIRED - public key
                                    "My Product ID",        // REQUIRED - product id
                                    "MY Product Edition",   // product edition if needed
                                    "My Product Version",   // product version if needed
                                    null,                   // current date, null for current date
                                    null);                  // product release date if needed
                

License object has a getValidationStatus method which returns an enumeration object.

        switch (license.getValidationStatus()) {
                case LICENSE_VALID:
                  
                    break;
                case LICENSE_INVALID:
                  
                    break;
                case LICENSE_EXPIRED:
                  
                    break;
                case LICENSE_MAINTENANCE_EXPIRED:
                  
                    break;
                case INCORRECT_SYSTEM_TIME:
                  
                    break;
                case MISMATCH_HARDWARE_ID:
                  
                    break;
                case MISMATCH_PRODUCT_ID:
                  
                    break;
                case MISMATCH_PRODUCT_EDITION:
                  
                    break;
                case MISMATCH_PRODUCT_VERSION:
                  
                    break;
            }                            
                

If license activation features are defined, activation status is obtained with getActivationStatus method which returns another enumeration object.

        switch (license.getActivationStatus()) {
            case ACTIVATION_REQUIRED:

                break;
            case ACTIVATION_NOT_REQUIRED:

                break;
            case ACTIVATION_COMPLETED:

                break;
            case ALREADY_ACTIVATED_ON_ANOTHER_COMPUTER:

                break;
            case MULTIPLE_ACTIVATION_LIMIT_REACHED:
               
                break;
            case ACTIVATION_SERVER_CONNECTION_ERROR:
               
                break;
            case LICENSE_NOT_FOUND_ON_ACTIVATION_SERVER:
               
                break;
            }                            
                

If license activation is enabled, autoActivate method activates license on Online.License4J.

        License activatedLicense = LicenseValidator.autoActivate(license);
                

autoActivate method has another parameter as activation host to perform online activation on any defined Auto License Generation and Activation Server.

        License activatedLicense = LicenseValidator.autoActivate(license, activationServer);
                
While activating a license, user information can also be collected and send to server; thus it is possible to update user information for license during activation.
        License activatedLicense = LicenseValidator.autoActivate(
                                        license
                                        modifyOnlyOnFirstActivation,
                                        fullName,
                                        registeredTo,
                                        email,
                                        company,
                                        street,
                                        telNumber,
                                        faxNumber,
                                        city,
                                        zip,
                                        country);
                

License features in a license text are obtained with getter methods some examples are given below. See JavaDoc documentation for all getter method names and descriptions.

        license.getLicenseText().getUserFullName();
        license.getLicenseText().getUserEMail();
        license.getLicenseText().getUserCountry();
                

License Key Validation:

        License license = LicenseValidator.validate(
                                    "AHD3D-DYAUV-WM4HR-5ZUAB-KCKNC",    // REQUIRED - license key
                                    publickeyString,                    // REQUIRED - public key
                                    "example",                          // REQUIRED IF BASIC LICENSE KEY - Internal hidden string
                                    null,                               // Customer name for validation
                                    null,                               // Customer's company name for validation
                                    0);                                 // Hardware ID selection
                

License object has a getValidationStatus method which returns an enumeration object.

        switch (license.getValidationStatus()) {
                case LICENSE_VALID:
                  
                    break;
                case LICENSE_INVALID:
                  
                    break;
            }                            
                

If license activation is enabled for license key, autoActivate method is used to activate the license.


Online License Key Floating Over Internet Validation:

Online license key validation is very similar to license key and license text validation. Returned license object has ValidationStatus enumaration object. The following code validates license key on Online.License4J.
        License license = LicenseValidator.validate(
                                    "AHD3D-DYAUV-WM4HR-5ZUAB-KCKNC",    // REQUIRED - license key
                                    publickeyString,                    // REQUIRED - public key
                                    "My Product ID",        // REQUIRED - product id
                                    "MY Product Edition",   // REQUIRED - product edition
                                    "My Product Version",   // REQUIRED - product version
                                    null,                   // current date
                                    null,                   // current product version release date
                                    new DefaultOnlineLicenseKeyCheckTimerHandlerImpl("Online License Key can not be obtained.", false)); // invalid key handler timer
                
The following code defines an Auto License Generation and Activation Server and connects it to validate license.
        License license = LicenseValidator.validate(
                                    "AHD3D-DYAUV-WM4HR-5ZUAB-KCKNC",    // REQUIRED - license key
                                    publickeyString,                    // REQUIRED - public key
                                    "My Product ID",        // REQUIRED - product id
                                    "MY Product Edition",   // REQUIRED - product edition
                                    "My Product Version",   // REQUIRED - product version
                                    null,                   // current date
                                    null,                   // current product version release date
                                    "http://YourServerName:Port/algas/validateobk",
                                    new DefaultOnlineLicenseKeyCheckTimerHandlerImpl("Online License Key can not be obtained.", false)); // invalid key handler timer
                

Floating License Validation:

        License license = LicenseValidator.validate(
                                    publickeyString,        // REQUIRED - public key
                                    "My Product ID",        // REQUIRED - product id
                                    "MY Product Edition",   // product edition
                                    "My Product Version",   // product version
                                    null,                   // current date, null for current date
                                    null,                  // product release date if needed
                                    host,                   // REQUIRED - license server host
                                    portnumber,             // REQUIRED - license server port number
                                    null,                   // floating license valid handler
                                    null,                   // floating license invalid handler
                                    null);                  // floating license server connection error handler
                

As in license text validation a License object returns and getValidationStatus gives information about validation status with additional information for floating license types.

        switch (license.getValidationStatus()) {
                case LICENSE_VALID:
                  
                    break;
                case LICENSE_INVALID:
                  
                    break;
                case LICENSE_EXPIRED:
                  
                    break;
                case LICENSE_MAINTENANCE_EXPIRED:
                  
                    break;
                case INCORRECT_SYSTEM_TIME:
                  
                    break;
                case MISMATCH_PRODUCT_EDITION:
                  
                    break;
                case MISMATCH_PRODUCT_VERSION:
                  
                    break;
                case FLOATING_LICENSE_SERVER_NOT_AVAILABLE:
                  
                    break;
                case FLOATING_LICENSE_NOT_FOUND:
                  
                    break;
                case FLOATING_LICENSE_NOT_AVAILABLE_ALL_IN_USE:
                  
                    break;
            }                            
                

License Availability Check (black-list check):

Runtime library has a method named LicenseValidator.checkOnlineAvailability to check for any license on server whether it is deleted or available. It checks for both a license and activation. When a license is deleted or an activation is moved to another computer, this method will always return 0. If license or activation is still available on server it will ways return 1. If client computer is not connected to Internet or there is a connection problem with server it will return -1.

This method is very useful when one of your license is published on Internet or an activation is moved to another computer. If method returns 0, you can be sure that it is an illegal license, so you can display an error dialog and shutdown software.

The code below will check for license availability on a Auto License Generation and Activation Server.

        License license = LicenseValidator.checkOnlineAvailability(publickey, license, "http://YourServer:Port/algas/checkavailability", 3000);
        System.out.println(license.getModificationStatus());
                

The code below will check for license availability on Online.License4J Servers.

        License license = LicenseValidator.checkOnlineAvailability(publickey, license, 3000);
        System.out.println(license.getModificationStatus());
                

License Modification Key Usage:

        License license = LicenseValidator.modifyLicense(activatedLicenseObject, "URG6V-9SFBY-X2MJ5-Z9KW7-PKAFZ");
        System.out.println(license.getModificationStatus());
                

The code above use a modification key to modify an activated license. ModificationStatus is a new enumeration class, and includes status codes for modification action.


SSL Certificate Verification:

By default runtime library verifies certificate and hostname if HTTPS connection is used in activation, deactivation, modification, or online validation. If you want to bypass certificate verification for testing add the following code block before connection to license server.

        // Create a trust manager which does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }
        };

        // Create all trusting host name verifier
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };

        try {
            // Install the trust manager
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            // Install the host verifier
            HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
                
Privacy Terms of Use Contact Us