public final class License
extends java.lang.Object
a license is a jwt (https://jwt.io/introduction/) that is
a jwt license may make a claim about support for "monitoring" (either true or false)
Modifier and Type | Class and Description |
---|---|
static class |
License.Type
The type of license.
|
Constructor and Description |
---|
License(org.jose4j.jwt.JwtClaims claims,
org.apache.kafka.common.utils.Time clock,
java.lang.String serialized)
Create a license with the supplied
JWT Claims . |
Modifier and Type | Method and Description |
---|---|
java.util.List<java.lang.String> |
audience()
Get the audience for the license.
|
java.lang.String |
audienceString()
Get a string with comma-separated
audience literals for the license. |
static org.jose4j.jwt.JwtClaims |
baseClaims(java.lang.String audience,
long expiration,
boolean monitoring) |
boolean |
equals(java.lang.Object obj) |
protected static long |
expiration(org.jose4j.jwt.JwtClaims claims) |
java.util.Date |
expirationDate()
Get the license's expiration date.
|
java.lang.String |
expirationDateString()
Get the license's expiration date as a formatted string of the form .
|
protected long |
expirationMillis() |
boolean |
expiresBefore(License other)
Determine if this license expires before the specified license.
|
static java.lang.String |
generateTrialLicense(org.jose4j.jwt.JwtClaims trialClaims) |
static java.util.List<java.lang.String> |
getAudience(org.jose4j.jwt.JwtClaims claims) |
static long |
getExpiration(org.jose4j.jwt.JwtClaims claims) |
int |
hashCode() |
protected boolean |
hasLicenseType(java.lang.String expected) |
protected boolean |
hasMatchingClaims(License other,
java.lang.String... excludeClaims)
Determine if this license matches all of the
relevant claims
in the supplied license, except for any excluded claims. |
boolean |
isEquivalentTo(License other)
Determine if this license is equivalent to the specified license, using the
audience ,
expiration time ,
issuer ,
subject ,
and monitoring claim. |
boolean |
isExpired()
Determine whether this license has expired.
|
boolean |
isFreeTier()
Determine whether the license represents a free tier license that allows for
single-node clusters only.
|
boolean |
isRenewalOf(License other)
Determine if this license is a strict renewal of the specified license.
|
boolean |
isTrial()
Determine whether the license represents a trial, such that the
audience is simply "trial". |
boolean |
isValid()
Determine whether this license is currently valid.
|
static java.security.PrivateKey |
loadPrivateKey(java.io.InputStream is) |
static java.security.PublicKey |
loadPublicKey() |
static java.security.PublicKey |
loadPublicKey(java.io.InputStream is) |
java.lang.String |
serializedForm()
Get the serialized form of this license.
|
static java.lang.String |
sign(java.security.PrivateKey key,
java.lang.String audience,
long expiration,
boolean monitoring) |
java.lang.String |
subject()
Get the subject of the license.
|
long |
timeRemaining(java.util.concurrent.TimeUnit unit)
Get the amount of time in the specified units that remains before the license expires.
|
java.lang.String |
toString() |
License.Type |
type()
Get the type of license.
|
static org.jose4j.jwt.JwtClaims |
verify(java.security.PublicKey key,
java.lang.String license) |
static boolean |
verifyMonitoring(org.jose4j.jwt.JwtClaims claims) |
static org.jose4j.jwt.JwtClaims |
verifyStored(java.security.PublicKey key,
java.lang.String license) |
public License(org.jose4j.jwt.JwtClaims claims, org.apache.kafka.common.utils.Time clock, java.lang.String serialized)
JWT Claims
.claims
- the JWT claimsclock
- the clock that can be used to compute the expirationDate()
;
may not be nullserialized
- the serialized form of the license; may not be nullpublic static org.jose4j.jwt.JwtClaims baseClaims(java.lang.String audience, long expiration, boolean monitoring)
public static java.lang.String sign(java.security.PrivateKey key, java.lang.String audience, long expiration, boolean monitoring) throws org.jose4j.lang.JoseException
org.jose4j.lang.JoseException
public static org.jose4j.jwt.JwtClaims verify(java.security.PublicKey key, java.lang.String license) throws org.jose4j.jwt.consumer.InvalidJwtException
org.jose4j.jwt.consumer.InvalidJwtException
public static org.jose4j.jwt.JwtClaims verifyStored(java.security.PublicKey key, java.lang.String license) throws org.jose4j.jwt.consumer.InvalidJwtException
org.jose4j.jwt.consumer.InvalidJwtException
public static long getExpiration(org.jose4j.jwt.JwtClaims claims) throws java.lang.Throwable
java.lang.Throwable
protected static long expiration(org.jose4j.jwt.JwtClaims claims) throws java.lang.Throwable
java.lang.Throwable
public static java.util.List<java.lang.String> getAudience(org.jose4j.jwt.JwtClaims claims)
public static boolean verifyMonitoring(org.jose4j.jwt.JwtClaims claims)
public static java.security.PrivateKey loadPrivateKey(java.io.InputStream is) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException
public static java.security.PublicKey loadPublicKey() throws java.security.NoSuchAlgorithmException, java.io.IOException, java.security.spec.InvalidKeySpecException
java.security.NoSuchAlgorithmException
java.io.IOException
java.security.spec.InvalidKeySpecException
public static java.security.PublicKey loadPublicKey(java.io.InputStream is) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException
public static java.lang.String generateTrialLicense(org.jose4j.jwt.JwtClaims trialClaims) throws InvalidLicenseException
InvalidLicenseException
public java.lang.String subject()
public boolean isTrial()
audience
is simply "trial".public boolean isFreeTier()
public License.Type type()
isFreeTier()
,
isTrial()
public java.util.Date expirationDate()
public java.lang.String expirationDateString()
expirationDate()
; never nullpublic boolean isExpired()
public boolean isValid()
public boolean isEquivalentTo(License other)
audience
,
expiration time
,
issuer
,
subject
,
and monitoring claim.
This method does not consider the issued timestamp
,
not before
, and JWT ID
claims.other
- the other licenseother
are equivalent, or false otherwisepublic boolean isRenewalOf(License other)
isEquivalentTo(License)
except the
expiration time
of this license must be later than
the specified license.other
- the other licenseother
is a renewal of the previous
licensepublic long timeRemaining(java.util.concurrent.TimeUnit unit)
unit
- the unit for the returned time; may not be nullpublic java.util.List<java.lang.String> audience()
public java.lang.String audienceString()
audience literals
for the license.
This corresponds to the customer information, or "trial" if the license is a trial.public boolean expiresBefore(License other)
other
- the other license; may be nullpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String serializedForm()
protected long expirationMillis()
protected boolean hasLicenseType(java.lang.String expected)
protected boolean hasMatchingClaims(License other, java.lang.String... excludeClaims)
relevant claims
in the supplied license, except for any excluded claims.other
- the other licenseexcludeClaims
- the names of claims that should be excluded from the check; may be emptyother
has claims that match this license, or false otherwise or if
other
is null