Class InvitationToken
An invitation token is generated by an admin node via InvitationService
and presented by a new node during onboarding. The token contains:
- The requested node ID
- An expiry timestamp (epoch seconds)
- An ECDSA signature over the
nodeId || expirypayload, signed by the admin's private key
Once the token is accepted and the signature verified, the node ID is added
to the allowlist and assigned a default role by the InvitationService.
Immutability
All fields are immutable and final. Once created, a token cannot be modified.Usage
InvitationToken token = InvitationToken.create(nodeId, expiryEpoch, signature);
String encoded = token.getEncodedToken(); // Base64 for transmission
// ...
InvitationToken parsed = InvitationToken.parseEncodedToken(encoded);
if (parsed.isExpired()) {
reject();
}
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic InvitationTokenCreates a new invitation token with the given parameters.booleanEncodes this token as a Base64 string suitable for transmission or storage.longReturns the token expiry time as Unix epoch seconds.Returns the expiry time as anInstant.Returns the invited node ID.byte[]Returns the ECDSA signature bytes (DER-encoded).inthashCode()booleanChecks whether this token has expired.static InvitationTokenparseEncodedToken(String encodedToken) Parses an encoded invitation token (Base64-formatted) back into its components.toString()
-
Method Details
-
create
Creates a new invitation token with the given parameters.This factory is normally called by
InvitationServiceafter signing the payload.- Parameters:
nodeId- the node ID being invited (non-null, non-blank)expiryEpochSeconds- the expiry time in Unix epoch seconds (must be positive)signature- the ECDSA signature bytes (non-null, non-empty)- Returns:
- a new
InvitationToken - Throws:
NullPointerException- if any parameter is nullIllegalArgumentException- if nodeId is blank, expiryEpochSeconds is non-positive, or signature is empty
-
parseEncodedToken
Parses an encoded invitation token (Base64-formatted) back into its components.The token is expected to be in the format produced by
getEncodedToken(). This is a convenience method for deserialization; the actual signature verification is performed byInvitationService.verifyToken(InvitationToken).- Parameters:
encodedToken- the Base64-encoded token string (non-null, non-blank)- Returns:
- a parsed
InvitationToken - Throws:
NullPointerException- if encodedToken is nullIllegalArgumentException- if encodedToken is blank or malformed
-
getNodeId
Returns the invited node ID.- Returns:
- the node ID that will be added to the allowlist upon token acceptance
-
getExpiryEpochSeconds
public long getExpiryEpochSeconds()Returns the token expiry time as Unix epoch seconds.- Returns:
- epoch seconds timestamp
-
getExpiryInstant
Returns the expiry time as anInstant.- Returns:
- expiry as an instant
-
getSignature
public byte[] getSignature()Returns the ECDSA signature bytes (DER-encoded).The returned array is a copy; modifications do not affect the token.
- Returns:
- the signature bytes
-
getEncodedToken
Encodes this token as a Base64 string suitable for transmission or storage.The encoded format is:
[nodeId length (4 bytes)] + [nodeId (UTF-8)] + [expiryEpochSeconds (8 bytes)] + [signature bytes], then Base64-encoded.- Returns:
- Base64-encoded token string
-
isExpired
public boolean isExpired()Checks whether this token has expired.- Returns:
trueif the current time is past the token's expiry time
-
equals
-
hashCode
public int hashCode() -
toString
-