com.jp.protection.pub
Class LicenseReader

java.lang.Object
  extended by com.jp.protection.pub.LicenseReader
Direct Known Subclasses:
BasicLauncherConfigStorage.EntryLicenseReader, BasicLicenseStorage.EntryLicenseReader, ProductLicenseReader

public class LicenseReader
extends java.lang.Object

This class is intended to read a license, decode it, hold the already read license and notify interested listeners about reading process and its results.

See Also:
LicenseReaderListener

Field Summary
protected  java.lang.Class fClassForLoadLicenseResource
           
protected  byte[] fDecryptKeyBytes
           
protected  License fLicense
           
protected  java.lang.String fLicenseFileName
           
protected  java.lang.String fLicenseFolder
           
protected  boolean fLicenseRead
           
protected  LicenseReaderIssueResolver fLicenseReaderIssueResolver
           
protected  java.lang.String fLicenseResourceFolder
           
protected  boolean fSearchLicenseInFile
           
protected  java.lang.String fSecurityAlgorithm
           
protected  SecurityProvider fSecurityProvider
           
protected  boolean fSkipEncryption
           
protected  boolean fUserHomeRelative
           
protected  boolean fVerbose
           
 
Constructor Summary
LicenseReader()
           
 
Method Summary
 void addLicenseReaderListener(LicenseReaderListener l)
          Adds license reader listener
protected  byte[] decodeLicense(byte[] aLicenseBytes)
           
protected  void error(java.lang.String aMessage)
           
protected  void error(java.lang.Throwable ex)
           
protected  void fireLicenseAboutToRead(LicenseReader e, java.lang.String aProductID)
           
protected  void fireLicenseAvailable(LicenseReader e, java.lang.String aLicenseLocation)
           
protected  void fireLicenseCorrupted(LicenseReader e, java.lang.String aLicenseLocation)
           
protected  void fireLicenseMissing(LicenseReader e, java.lang.String aLicenseLocation)
           
 java.lang.Class getClassForLoadLicenseResource()
          Returns class used for loading license from the application resource.
 byte[] getDecryptKeyBytes()
          Returns bytes array that specifies key used to decrypt the license.
 LicenseReaderIssueResolver getIssueResolver()
          Returns issue resolver used to fix issues occured during license locating and reading.
 License getLicense()
          Returns already read license.
 License getLicense(boolean aForceRead)
          Returns already read license.
 byte[] getLicenseBytes()
          Reads a license file and returns it as an array of bytes
protected  byte[] getLicenseBytes(java.io.InputStream aLicenseInputStream)
           
 java.io.File getLicenseFile()
          Constructs and returns file of the license according to the licenseFileName, licenseFolder and licenseReader attributes.
 java.io.InputStream getLicenseFileInputStream()
          Returns input stream to read license from file
 java.lang.String getLicenseFileLocation()
          Returns path of license file
 java.lang.String getLicenseFileName()
          Returns the license file name, which should be read by the reader.
 java.lang.String getLicenseFolder()
          Returns path to the folder outside of application archive, which contains the license to be read.
 java.io.InputStream getLicenseInputStream()
          Returns input stream to read license from
 java.io.OutputStream getLicenseOutputStream()
          Returns output stream to write license to.
 java.lang.String getLicenseProduct(java.io.InputStream aLicenseInputStream)
          Reads and returns license product from the specified stream.
 java.lang.String getLicenseResourceFolder()
          Returns the path to the folder within application archive, which contains the license file.
 java.io.InputStream getLicenseResourceInputStream()
          Returns input stream to read license from the application resource
 java.lang.String getLicenseResourceLocation()
          Constructs and returns location of the license resource within the application archive
 byte[] getPrivateKeyBytes()
          Deprecated. use getDecryptKeyBytes() instead
 java.lang.String getSecurityAlgorithm()
          Returns identifier of security algorithm used to decode licenses.
protected  SecurityProvider getSecurityProvider()
           
 boolean isLicenseRead()
          Checks whether license is already read.
 boolean isSearchLicenseInFile()
          Returns whether license should be searched in file first
 boolean isSkipEncryption()
          Checks whether license encryption should be skipped.
 boolean isUserHomeRelative()
          Checks whether the reader should treat license folder as relative to the user home.
 boolean isVerbose()
          Checks whether reader runs in verbose mode.
protected  void readLicense()
           
protected  void readLicense(byte[] aLicenseBytes)
           
 void readLicense(java.io.InputStream aLicenseInputStream, java.lang.String aLicenseLocation)
          Reads the license from the specified stream.
 void removeLicenseReaderListener(LicenseReaderListener l)
          Removes license reader listener.
 void setClassForLoadLicenseResource(java.lang.Class aClassForLoadLicenseResource)
          Specifies class should be used for loading license from the application resource.
 void setDecryptKeyBytes(byte[] aDecryptKeyBytes)
          Specifies bytes array representing key required to decrypt the license.
 void setDecryptKeyBytes(java.lang.String aDecryptKeyBytes)
          Specifies bytes array used to restore the key required to decode the license.
 void setIssueResolver(LicenseReaderIssueResolver aLicenseReaderIssueResolver)
          Specifies issue resolver should be used to fix issues occured during license locating and reading.
 void setLicenseFileName(java.lang.String aLicenseFileName)
          Specifies the name of the license file
 void setLicenseFolder(java.lang.String aLicenseFolder)
          Specifies path to the folder, which contains the license to be read.
 void setLicenseResourceFolder(java.lang.String aLicenseResourceFolder)
          Specifies the path to the resource folder, which contains the license file.
 void setPrivateKeyBytes(byte[] aPrivateKeyBytes)
          Deprecated. use setDecryptKeyBytes() instead
 void setPrivateKeyBytes(java.lang.String aPrivateKeyBytes)
          Deprecated. use setDecryptKeyBytes() instead
 void setSearchLicenseInFile(boolean aSearchLicenseInFile)
          Specifies that license should be searched in file first.
 void setSecurityAlgorithm(java.lang.String aSecurityAlgorithm)
          Specifies identifier of security algorithm should be used to decode licenses.
 void setSkipEncryption(boolean aSkipEncryption)
          Specifies that license encryption should be skipped.
 void setUserHomeRelative(boolean aUserHomeRelative)
          Specifies that the reader should treat license folder as relative to the user home.
 void setVerbose(boolean aVerbose)
          Specifies that reader should be run in verbose mode.
protected  byte[] smartDecodeLicense(byte[] aLicenseBytes)
           
protected  byte[] smartGetLicenseBytes(java.io.InputStream aLicenseInputStream)
           
protected  void smartReadLicense(byte[] aLicenseBytes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fLicense

protected License fLicense

fLicenseFileName

protected java.lang.String fLicenseFileName

fUserHomeRelative

protected boolean fUserHomeRelative

fLicenseFolder

protected java.lang.String fLicenseFolder

fLicenseResourceFolder

protected java.lang.String fLicenseResourceFolder

fLicenseRead

protected boolean fLicenseRead

fVerbose

protected boolean fVerbose

fSkipEncryption

protected boolean fSkipEncryption

fDecryptKeyBytes

protected byte[] fDecryptKeyBytes

fLicenseReaderIssueResolver

protected LicenseReaderIssueResolver fLicenseReaderIssueResolver

fSearchLicenseInFile

protected boolean fSearchLicenseInFile

fSecurityProvider

protected SecurityProvider fSecurityProvider

fSecurityAlgorithm

protected java.lang.String fSecurityAlgorithm

fClassForLoadLicenseResource

protected java.lang.Class fClassForLoadLicenseResource
Constructor Detail

LicenseReader

public LicenseReader()
Method Detail

getLicenseResourceFolder

public java.lang.String getLicenseResourceFolder()
Returns the path to the folder within application archive, which contains the license file. If this path is null and therefore is not specified the reader will not try to find the license in the application resources.

Returns:
path to the resource folder.

setLicenseResourceFolder

public void setLicenseResourceFolder(java.lang.String aLicenseResourceFolder)
Specifies the path to the resource folder, which contains the license file.

Parameters:
aLicenseResourceFolder - path to the resource folder

getDecryptKeyBytes

public byte[] getDecryptKeyBytes()
Returns bytes array that specifies key used to decrypt the license.

Returns:
decryption key bytes

setDecryptKeyBytes

public void setDecryptKeyBytes(byte[] aDecryptKeyBytes)
Specifies bytes array representing key required to decrypt the license.

Parameters:
aDecryptKeyBytes - decryption key bytes

setDecryptKeyBytes

public void setDecryptKeyBytes(java.lang.String aDecryptKeyBytes)
Specifies bytes array used to restore the key required to decode the license.

Parameters:
aDecryptKeyBytes - private key bytes as String e.g. "1, 23, 45, 23, -1"

getPrivateKeyBytes

public byte[] getPrivateKeyBytes()
Deprecated. use getDecryptKeyBytes() instead

Returns bytes array that specifies private key used to decode the license.

Returns:
private key bytes

setPrivateKeyBytes

public void setPrivateKeyBytes(byte[] aPrivateKeyBytes)
Deprecated. use setDecryptKeyBytes() instead

Specifies bytes array used to restore the private key required to decode the license.

Parameters:
aPrivateKeyBytes - private key bytes

setPrivateKeyBytes

public void setPrivateKeyBytes(java.lang.String aPrivateKeyBytes)
Deprecated. use setDecryptKeyBytes() instead

Specifies bytes array used to restore the private key required to decode the license.

Parameters:
aPrivateKeyBytes - private key bytes as String e.g. "1, 23, 45, 23, -1"

isLicenseRead

public boolean isLicenseRead()
Checks whether license is already read.

Returns:
true if license is already read, false otherwise.

isSkipEncryption

public boolean isSkipEncryption()
Checks whether license encryption should be skipped.

Returns:
true license encryption should be skipped, false otherwise.

setSkipEncryption

public void setSkipEncryption(boolean aSkipEncryption)
Specifies that license encryption should be skipped. Note: skipping can be useful for debugging purposes only.

Parameters:
aSkipEncryption - true if license encryption should be skipped, false otherwise.

isVerbose

public boolean isVerbose()
Checks whether reader runs in verbose mode.

Returns:
true if reader runs in verbose mode, false otherwise.

setVerbose

public void setVerbose(boolean aVerbose)
Specifies that reader should be run in verbose mode. If reader run in verbose mode all exceptions stack traces and error messages, if any, will be printed to stderr. Otherwise there is no output in order to prevent the code flow analysis.

Parameters:
aVerbose - true if reader should run in verbose mode, false otherwise.

error

protected void error(java.lang.String aMessage)

error

protected void error(java.lang.Throwable ex)

isUserHomeRelative

public boolean isUserHomeRelative()
Checks whether the reader should treat license folder as relative to the user home.

Returns:
true if reader should treat license folder as relative to the user home, false otherwise.

setUserHomeRelative

public void setUserHomeRelative(boolean aUserHomeRelative)
Specifies that the reader should treat license folder as relative to the user home.

Parameters:
aUserHomeRelative - true if reader should treat license folder as relative to the user home, false otherwise.

getLicenseFileName

public java.lang.String getLicenseFileName()
Returns the license file name, which should be read by the reader.

Returns:
name of license file.

setLicenseFileName

public void setLicenseFileName(java.lang.String aLicenseFileName)
Specifies the name of the license file

Parameters:
aLicenseFileName - name of the license file

getLicenseFolder

public java.lang.String getLicenseFolder()
Returns path to the folder outside of application archive, which contains the license to be read.

Returns:
path to the folder.

setLicenseFolder

public void setLicenseFolder(java.lang.String aLicenseFolder)
Specifies path to the folder, which contains the license to be read.

Parameters:
aLicenseFolder - path to the folder

getLicense

public License getLicense()
Returns already read license. If license is not yet read, reads it first and then returns a license.

Returns:
instance of the License, null if license can't be read.

getLicense

public License getLicense(boolean aForceRead)
Returns already read license. If license is not yet read, reads it first and then returns a license.

Parameters:
aForceRead - specifies whether license should be re-read if it is already read.
Returns:
instance of the License, null if license can not be read.

readLicense

protected void readLicense()

isSearchLicenseInFile

public boolean isSearchLicenseInFile()
Returns whether license should be searched in file first

Returns:
true if license should be searched in file first

setSearchLicenseInFile

public void setSearchLicenseInFile(boolean aSearchLicenseInFile)
Specifies that license should be searched in file first.

Parameters:
aSearchLicenseInFile - true if license should be searched in file first

getLicenseInputStream

public java.io.InputStream getLicenseInputStream()
Returns input stream to read license from

Returns:
input stream to read license from

getLicenseOutputStream

public java.io.OutputStream getLicenseOutputStream()
Returns output stream to write license to.

Returns:
output stream to write license to.

readLicense

public void readLicense(java.io.InputStream aLicenseInputStream,
                        java.lang.String aLicenseLocation)
                 throws java.io.IOException
Reads the license from the specified stream.

Parameters:
aLicenseInputStream - stream to read license from
aLicenseLocation - optional license location information that will be passed to License Reader events.
Throws:
java.io.IOException - for any errors occured during license reading.

smartDecodeLicense

protected byte[] smartDecodeLicense(byte[] aLicenseBytes)

decodeLicense

protected byte[] decodeLicense(byte[] aLicenseBytes)

getSecurityAlgorithm

public java.lang.String getSecurityAlgorithm()
Returns identifier of security algorithm used to decode licenses.

Returns:
identifier of security algorithm used to decode licenses.

setSecurityAlgorithm

public void setSecurityAlgorithm(java.lang.String aSecurityAlgorithm)
Specifies identifier of security algorithm should be used to decode licenses.

Parameters:
aSecurityAlgorithm - identifier of security algorithm.

getSecurityProvider

protected SecurityProvider getSecurityProvider()

smartReadLicense

protected void smartReadLicense(byte[] aLicenseBytes)

readLicense

protected void readLicense(byte[] aLicenseBytes)

getLicenseProduct

public java.lang.String getLicenseProduct(java.io.InputStream aLicenseInputStream)
Reads and returns license product from the specified stream.

Parameters:
aLicenseInputStream - stream to read license product from.
Returns:
license product

smartGetLicenseBytes

protected byte[] smartGetLicenseBytes(java.io.InputStream aLicenseInputStream)

getLicenseBytes

protected byte[] getLicenseBytes(java.io.InputStream aLicenseInputStream)

getLicenseFileLocation

public java.lang.String getLicenseFileLocation()
Returns path of license file

Returns:
path of license file

getLicenseResourceLocation

public java.lang.String getLicenseResourceLocation()
Constructs and returns location of the license resource within the application archive

Returns:
location of license resource

getLicenseFileInputStream

public java.io.InputStream getLicenseFileInputStream()
Returns input stream to read license from file

Returns:
input stream to read license from file

getLicenseResourceInputStream

public java.io.InputStream getLicenseResourceInputStream()
Returns input stream to read license from the application resource

Returns:
input stream to read license from the application resource

getClassForLoadLicenseResource

public java.lang.Class getClassForLoadLicenseResource()
Returns class used for loading license from the application resource.

Returns:
class used for loading license from the application resource.

setClassForLoadLicenseResource

public void setClassForLoadLicenseResource(java.lang.Class aClassForLoadLicenseResource)
Specifies class should be used for loading license from the application resource. If explicit value is not specified the LicenseReader class is used.

Parameters:
aClassForLoadLicenseResource - class should be used for loading license from the application resource.

getLicenseFile

public java.io.File getLicenseFile()
Constructs and returns file of the license according to the licenseFileName, licenseFolder and licenseReader attributes.

Returns:
file of the license

addLicenseReaderListener

public void addLicenseReaderListener(LicenseReaderListener l)
Adds license reader listener

Parameters:
l - license listener instance.

removeLicenseReaderListener

public void removeLicenseReaderListener(LicenseReaderListener l)
Removes license reader listener.

Parameters:
l - license listener instance.

fireLicenseMissing

protected void fireLicenseMissing(LicenseReader e,
                                  java.lang.String aLicenseLocation)

fireLicenseCorrupted

protected void fireLicenseCorrupted(LicenseReader e,
                                    java.lang.String aLicenseLocation)

fireLicenseAvailable

protected void fireLicenseAvailable(LicenseReader e,
                                    java.lang.String aLicenseLocation)

fireLicenseAboutToRead

protected void fireLicenseAboutToRead(LicenseReader e,
                                      java.lang.String aProductID)

getIssueResolver

public LicenseReaderIssueResolver getIssueResolver()
Returns issue resolver used to fix issues occured during license locating and reading.

Returns:
issue resolver.

setIssueResolver

public void setIssueResolver(LicenseReaderIssueResolver aLicenseReaderIssueResolver)
Specifies issue resolver should be used to fix issues occured during license locating and reading.

Parameters:
aLicenseReaderIssueResolver - issue resolver

getLicenseBytes

public byte[] getLicenseBytes()
Reads a license file and returns it as an array of bytes

Returns:
array of bytes represents license file