Class License

java.lang.Object
io.confluent.license.License
Direct Known Subclasses:
CSFLELicense

public class License extends Object
this class provides utility functions and a cli for creating/verifying licenses

a license is a jwt (https://jwt.io/introduction/) that is

  • issued by "Confluent"
  • has an expiration time
  • has a subject

a jwt license may make a claim about support for "monitoring" (either true or false)

  • Constructor Details

    • License

      public License(org.jose4j.jwt.JwtClaims claims, org.apache.kafka.common.utils.Time clock, String serialized)
      Create a license with the supplied JWT Claims.
      Parameters:
      claims - the JWT claims
      clock - the clock that can be used to compute the expirationDate(); may not be null
      serialized - the serialized form of the license; may not be null
    • License

      public License(org.jose4j.jwt.JwtClaims claims, org.apache.kafka.common.utils.Time clock, String serialized, String platformId)
      Create a license with the supplied JWT Claims and cluster id.
      Parameters:
      claims - the JWT claims
      clock - the clock that can be used to compute the expirationDate(); may not be null
      serialized - the serialized form of the license; may not be null
      platformId - the id for the license cluster
  • Method Details

    • baseClaims

      public static org.jose4j.jwt.JwtClaims baseClaims(String audience, long expiration, boolean monitoring)
    • sign

      public static String sign(PrivateKey key, String audience, long expiration, boolean monitoring) throws org.jose4j.lang.JoseException
      Throws:
      org.jose4j.lang.JoseException
    • verify

      public static org.jose4j.jwt.JwtClaims verify(PublicKey key, String license) throws org.jose4j.jwt.consumer.InvalidJwtException
      Throws:
      org.jose4j.jwt.consumer.InvalidJwtException
    • verifyStored

      public static org.jose4j.jwt.JwtClaims verifyStored(PublicKey key, String license) throws org.jose4j.jwt.consumer.InvalidJwtException
      Throws:
      org.jose4j.jwt.consumer.InvalidJwtException
    • getExpiration

      public static long getExpiration(org.jose4j.jwt.JwtClaims claims) throws Throwable
      Throws:
      Throwable
    • getAudience

      public static List<String> getAudience(org.jose4j.jwt.JwtClaims claims)
    • verifyMonitoring

      public static boolean verifyMonitoring(org.jose4j.jwt.JwtClaims claims)
    • loadPrivateKey

    • loadPublicKey

    • loadPublicKey

    • generateTrialLicense

      public static String generateTrialLicense(org.jose4j.jwt.JwtClaims trialClaims) throws InvalidLicenseException
      Throws:
      InvalidLicenseException
    • platformId

      public String platformId()
      The platform id for the licensing server. Currently, this is set to the cluster id but can change in the future.
      Returns:
      License platform id
    • licenseId

      public String licenseId()
      The license id. This is the JWT token id aka 'jti' that is unique to each license
      Returns:
      License id
    • isInvalidLicense

      public boolean isInvalidLicense()
    • subject

      public String subject()
      Get the subject of the license.
      Returns:
      the subject, may be null or empty if the license is malformed
    • isTrial

      public boolean isTrial()
      Determine whether the license represents a trial, such that the audience is simply "trial".
      Returns:
      true if the license is know to be a trial, or false otherwise
    • isFreeTier

      public boolean isFreeTier()
      Determine whether the license represents a free tier license that allows for single-node clusters only.
      Returns:
      true if the license represents the free tier, or false otherwise
    • isEnterprise

      public boolean isEnterprise()
      Determine whether the license represents a Enterprise license.
      Returns:
      true if the license represents the Enterprise, or false otherwise
    • type

      public License.Type type()
      Get the type of license.
      Returns:
      the license type; never null
      See Also:
    • deploymentScope

      public License.DeploymentScope deploymentScope()
    • getLicenseSubType

      public License.LicenseSubType getLicenseSubType()
      Get the license subtype from the JWT claims.
      Returns:
      the license subtype; returns NONE if no subtype claim exists or if an error occurs reading the claim
    • expirationDate

      public Date expirationDate()
      Get the license's expiration date.
      Returns:
      the expiration date; never null
    • expirationDateString

      public String expirationDateString()
      Get the license's expiration date as a formatted string of the form "yyyy-MM-dd".
      Returns:
      the string representation of the expirationDate(); never null
    • isExpired

      public boolean isExpired()
      Determine whether this license has expired.
      Returns:
      true if the license is expired, or false otherwise
    • isValid

      public boolean isValid()
      Determine whether this license is currently valid.
      Returns:
      true if the license is valid, or false otherwise
    • isEquivalentTo

      public boolean isEquivalentTo(License other)
      Determine if this license is equivalent to the specified license, using the audience, expiration time, issuer, subject, and monitoring claim. This method does not consider the issued timestamp, not before, and JWT ID claims.
      Parameters:
      other - the other license
      Returns:
      true if this license and other are equivalent, or false otherwise
    • isRenewalOf

      public boolean isRenewalOf(License other)
      Determine if this license is a strict renewal of the specified license. This is essentially the same logic as isEquivalentTo(License) except the expiration time of this license must be later than the specified license.
      Parameters:
      other - the other license
      Returns:
      true if other is a renewal of the previous license
    • timeRemaining

      public long timeRemaining(TimeUnit unit)
      Get the amount of time in the specified units that remains before the license expires.
      Parameters:
      unit - the unit for the returned time; may not be null
      Returns:
      the time remaining before the license expires; may be negative if the license is already expired
    • audience

      public List<String> audience()
      Get the audience for the license. This corresponds to the customer information, or "trial" if the license is a trial.
      Returns:
      the audience string(s); may be empty if the license has no valid audience
    • audienceString

      public String audienceString()
      Get a string with comma-separated audience literals for the license. This corresponds to the customer information, or "trial" if the license is a trial.
      Returns:
      the string containing the comma-separated audience literals; may be empty if the license has no valid audience
    • expiresBefore

      public boolean expiresBefore(License other)
      Determine if this license expires before the specified license.
      Parameters:
      other - the other license; may be null
      Returns:
      true if the other license is null or this license expires before the other license
    • isUpdatedWithSameExpiry

      public boolean isUpdatedWithSameExpiry(License other)
      Determine if this license is an updated version of the specified license with the same expiration date. This method checks if the current license has an `updatedAt` timestamp that is later than the specified license.
      Parameters:
      other - the other license to compare against
      Returns:
      true if the current license is an updated version with the same expiration date, false otherwise
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • serializedForm

      public String serializedForm()
      Get the serialized form of this license.
      Returns:
      the serialized form; never null