Class LicenseManager
- java.lang.Object
-
- org.zkoss.zkex.license.LicenseManager
-
- All Implemented Interfaces:
java.rmi.Remote,LicenseCreator,LicenseVerifier
public class LicenseManager extends java.lang.Object implements LicenseCreator, LicenseVerifier
This is the top level class which manages all licensing aspects like for instance the creation, installation and verification of license keys. The license manager knows how to install, verify and uninstall full and trial licenses for a given subject and ensures the privacy of the license content in its persistent form (i.e. the license key). For signing, verifying and validating licenses, this class cooperates with aLicenseNotary.This class is thread safe.
- Version:
- $Id$
- Author:
- Christian Schlichtherle
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCN=> "CN="static java.lang.StringLICENSE_SUFFIXThe suffix for files which hold license certificates
-
Constructor Summary
Constructors Modifier Constructor Description protectedLicenseManager()Constructs a License Manager.LicenseManager(LicenseParam param)Constructs a License Manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]create(LicenseContent content)Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and returns it as a license key.protected byte[]create(LicenseContent content, LicenseNotary notary)Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and returns it as a license key.protected GenericCertificategetCertificate()Returns the license certificate cached from the last installation/verification of a license key ornullif there wasn't an installation/verification or a timeout has occured.javax.swing.filechooser.FileFiltergetFileFilter()Returns a suitable file filter for the subject of this license manager.protected byte[]getLicenseKey()Returns the current license key.protected LicenseNotarygetLicenseNotary()Returns a license notary configured to use the keystore parameters contained in the current license parameters -nullis never returned.LicenseParamgetLicenseParam()Returns the license configuration parameters.protected PrivacyGuardgetPrivacyGuard()Returns a privacy guard configured to use the cipher parameters contained in the current license parameters -nullis never returned.protected voidinitialize(LicenseContent content)Initializes the given licensecontentwith some reasonable defaults unless the respective properties have already been set.protected LicenseContentinstall(byte[] key, LicenseNotary notary)Decrypts, decompresses, decodes and verifies the license key inkey, validates its license content and installs it as the current license key.LicenseContentinstall(java.io.File keyFile)Loads, decrypts, decompresses, decodes and verifies the license key inkeyFile, validates its license content and installs it as the current license key.protected LicenseContentinstall(java.io.File keyFile, LicenseNotary notary)Loads, decrypts, decompresses, decodes and verifies the license key inkeyFile, validates its license content and installs it as the current license key.protected static byte[]loadLicenseKey(java.io.File keyFile)Loads and returns the first megabyte of content fromkeyFileas license key in a newly created byte array.protected static java.util.Datemidnight()Returns midnight local time today.protected voidsetCertificate(GenericCertificate certificate)Sets the given license certificate as installed or verified.protected voidsetLicenseKey(byte[] key)Installs the given license key as the current license key.voidsetLicenseParam(LicenseParam param)Sets the license configuration parameters.voidstore(LicenseContent content, java.io.File keyFile)Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and stores it to the given file as a license key.protected voidstore(LicenseContent content, LicenseNotary notary, java.io.File keyFile)Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and stores it to the given file as a license key.protected static voidstoreLicenseKey(byte[] key, java.io.File keyFile)Stores the given license key to the given file.voiduninstall()Uninstalls the current license key.protected voidvalidate(LicenseContent content)Validates the license content.LicenseContentverify()Decrypts, decompresses, decodes and verifies the current license key, validates its license content and returns it.LicenseContentverify(byte[] key)Decrypts, decompresses, decodes and verifies the given license key, validates its license content and returns it.protected LicenseContentverify(byte[] key, LicenseNotary notary)Decrypts, decompresses, decodes and verifies the given license key, validates its license content and returns it.protected LicenseContentverify(LicenseNotary notary)Decrypts, decompresses, decodes and verifies the current license key, validates its license content and returns it.
-
-
-
Constructor Detail
-
LicenseManager
protected LicenseManager()
Constructs a License Manager.Warning: The manager created by this constructor is not valid and cannot be used unless
setLicenseParam(LicenseParam)is called!
-
LicenseManager
public LicenseManager(LicenseParam param)
Constructs a License Manager.- Parameters:
param- the license configuration parameters - may not benull.- Throws:
java.lang.NullPointerException- If the given parameter object does not obey the contract of its interface due to anullpointer.IllegalPasswordException- If any password in the parameter object does not comply to the current policy.
-
-
Method Detail
-
midnight
protected static java.util.Date midnight()
Returns midnight local time today.
-
getLicenseParam
public LicenseParam getLicenseParam()
Returns the license configuration parameters.
-
setLicenseParam
public void setLicenseParam(LicenseParam param)
Sets the license configuration parameters. Calling this method resets the manager as if it had been newly created. Some plausibility checks are applied to the given parameter object to ensure that it adheres to the contract of the parameter interfaces.- Parameters:
param- the license configuration parameters - may not benull.- Throws:
java.lang.NullPointerException- If the given parameter object does not obey the contract of its interface due to anullpointer.IllegalPasswordException- If any password in the parameter object does not comply to the current policy.
-
store
public final void store(LicenseContent content, java.io.File keyFile) throws java.lang.Exception
Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and stores it to the given file as a license key.As a side effect, the given license
contentis initialized with some reasonable defaults unless the respective properties have already been set.- Parameters:
content- the license content - may not benull.keyFile- the file to save the license key to - may not benull. This should have aLICENSE_SUFFIX.- Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
store(LicenseContent, LicenseNotary, File),initialize(LicenseContent),validate(LicenseContent)
-
store
protected void store(LicenseContent content, LicenseNotary notary, java.io.File keyFile) throws java.lang.Exception
Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and stores it to the given file as a license key.As a side effect, the given license
contentis initialized with some reasonable defaults unless the respective properties have already been set.- Parameters:
content- the license content - may not benull.notary- the license notary used to sign the license key - may not benull.keyFile- the file to save the license key to - may not benull. This should have aLICENSE_SUFFIX.- Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
initialize(LicenseContent),validate(LicenseContent)
-
create
public final byte[] create(LicenseContent content) throws java.lang.Exception
Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and returns it as a license key.As a side effect, the given license
contentis initialized with some reasonable defaults unless the respective properties have already been set.- Specified by:
createin interfaceLicenseCreator- Parameters:
content- the license content - may not benull.- Returns:
- The license key
-
nullis never returned. - Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
create(LicenseContent, LicenseNotary),initialize(LicenseContent),validate(LicenseContent)
-
create
protected byte[] create(LicenseContent content, LicenseNotary notary) throws java.lang.Exception
Initializes and validates the license content, creates a new signed license certificate for it and compresses, encrypts and returns it as a license key.As a side effect, the given license
contentis initialized with some reasonable defaults unless the respective properties have already been set.- Parameters:
content- the license content - may not benull.notary- the license notary used to sign the license key - may not benull.- Returns:
- The license key
-
nullis never returned. - Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
initialize(LicenseContent),validate(LicenseContent)
-
install
public final LicenseContent install(java.io.File keyFile) throws java.lang.Exception
Loads, decrypts, decompresses, decodes and verifies the license key inkeyFile, validates its license content and installs it as the current license key.- Parameters:
keyFile- the file to load the license key from - may not benull.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
install(File, LicenseNotary),validate(LicenseContent)
-
install
protected LicenseContent install(java.io.File keyFile, LicenseNotary notary) throws java.lang.Exception
Loads, decrypts, decompresses, decodes and verifies the license key inkeyFile, validates its license content and installs it as the current license key.- Parameters:
keyFile- The file to load the license key from - may not benull.notary- The license notary used to verify the license key - may not benull.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
validate(LicenseContent)
-
install
protected LicenseContent install(byte[] key, LicenseNotary notary) throws java.lang.Exception
Decrypts, decompresses, decodes and verifies the license key inkey, validates its license content and installs it as the current license key.- Parameters:
key- the license key - may not benull.notary- the license notary used to verify the license key - may not benull.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
validate(LicenseContent)
-
verify
public final LicenseContent verify() throws java.lang.Exception
Decrypts, decompresses, decodes and verifies the current license key, validates its license content and returns it.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
NoLicenseInstalledException- if no license key is installed.java.lang.Exception- for any other reason. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
validate(LicenseContent)
-
verify
protected LicenseContent verify(LicenseNotary notary) throws java.lang.Exception
Decrypts, decompresses, decodes and verifies the current license key, validates its license content and returns it.- Parameters:
notary- the license notary used to verify the current license key - may not benull.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
NoLicenseInstalledException- if no license key is installed.java.lang.Exception- for any other reason. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
validate(LicenseContent)
-
verify
public final LicenseContent verify(byte[] key) throws java.lang.Exception
Decrypts, decompresses, decodes and verifies the given license key, validates its license content and returns it.- Specified by:
verifyin interfaceLicenseVerifier- Parameters:
key- the license key - may not benull.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
java.lang.Exception- an instance of a subclass of this class for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
validate(LicenseContent)
-
verify
protected LicenseContent verify(byte[] key, LicenseNotary notary) throws java.lang.Exception
Decrypts, decompresses, decodes and verifies the given license key, validates its license content and returns it.- Parameters:
key- the license key - may not benull.notary- the license notary used to verify the license key - may not benull.- Returns:
- A clone of the verified and validated content of the license key
-
nullis never returned. - Throws:
java.lang.Exception- for various reasons. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
validate(LicenseContent)
-
uninstall
public void uninstall() throws java.lang.ExceptionUninstalls the current license key.- Throws:
java.lang.Exception- An instance of a subclass of this class for various reasons.
-
initialize
protected void initialize(LicenseContent content)
Initializes the given licensecontentwith some reasonable defaults unless the respective properties have already been set.- See Also:
validate(LicenseContent)
-
validate
protected void validate(LicenseContent content) throws LicenseContentException
Validates the license content. This method is called whenever a license certificate is created, installed or verified.Validation consists of the following plausability checks for the properties of this class:
- 'subject' must match the subject required by the application
via the
LicenseParaminterface. - 'holder', 'issuer' and 'issued' must be provided (i.e. not
null). - If 'notBefore' or 'notAfter' are provided, the current date and time must match their restrictions.
- 'consumerType' must be provided and 'consumerAmount' must be
positive. If a user preference node is provided in the license
parameters, 'consumerType' must also match
"User"(whereby case is ignored) and 'consumerAmount' must equal 1.
If you need more or less rigid restrictions, you should override this method in a subclass.
- Parameters:
content- the license content - may not benull.- Throws:
java.lang.NullPointerException- ifcontentisnull.LicenseContentException- if any validation test fails. Note that you should always useThrowable.getLocalizedMessage()to get a (possibly localized) meaningful detail message.- See Also:
initialize(LicenseContent)
- 'subject' must match the subject required by the application
via the
-
getCertificate
protected GenericCertificate getCertificate()
Returns the license certificate cached from the last installation/verification of a license key ornullif there wasn't an installation/verification or a timeout has occured.
-
setCertificate
protected void setCertificate(GenericCertificate certificate)
Sets the given license certificate as installed or verified.- Parameters:
certificate- the license certificate - may benullto clear.
-
getLicenseKey
protected byte[] getLicenseKey()
Returns the current license key.
-
setLicenseKey
protected void setLicenseKey(byte[] key)
Installs the given license key as the current license key. Ifkeyisnull, the current license key gets uninstalled (but the cached license certificate is not cleared).
-
storeLicenseKey
protected static void storeLicenseKey(byte[] key, java.io.File keyFile) throws java.io.IOExceptionStores the given license key to the given file.- Parameters:
key- the license key - may not benull.keyFile- the file to save the license key to - may not benull. This should have aLICENSE_SUFFIX.- Throws:
java.io.IOException
-
loadLicenseKey
protected static byte[] loadLicenseKey(java.io.File keyFile) throws java.io.IOExceptionLoads and returns the first megabyte of content fromkeyFileas license key in a newly created byte array.- Parameters:
keyFile- the file holding the license key - may not benull.- Throws:
java.io.IOException
-
getLicenseNotary
protected LicenseNotary getLicenseNotary()
Returns a license notary configured to use the keystore parameters contained in the current license parameters -nullis never returned.
-
getPrivacyGuard
protected PrivacyGuard getPrivacyGuard()
Returns a privacy guard configured to use the cipher parameters contained in the current license parameters -nullis never returned.
-
getFileFilter
public javax.swing.filechooser.FileFilter getFileFilter()
Returns a suitable file filter for the subject of this license manager. On Windows systems, the case of the suffix is ignored when browsing directories.- Returns:
- A valid
FileFilter.
-
-