public class SecureTokenManager
extends java.lang.Object
To initialize the manager to decode master tokens, you must supply at least one key to registerMasterPublicKey(). To generate master tokens, you must use initMaster() to provide a master private key capable of signing tokens. To process domain tokens, initDomain() must be called with a domain key.
It is possible to call initDomain() to rekey the server. Old keys will still be available for validating tokens, but new tokens will only be created with the new key. There is not currently any mechanism to expire old domain keys while a server is running.
To generate a token, create a SecureTokenSpec object and pass it to generateToken().
To import a token, pass the data to importToken(), then check the valid flag to ensure it is a valid token.
Modifier and Type | Class and Description |
---|---|
protected class |
SecureTokenManager.IssuerHistory |
Modifier and Type | Field and Description |
---|---|
protected long |
domainKeyId |
protected java.util.Map<java.lang.Long,javax.crypto.SecretKey> |
domainKeys |
protected static SecureTokenManager |
instance |
protected java.util.Map<java.lang.String,SecureTokenManager.IssuerHistory> |
issuerHistories |
protected long |
lastTokenId |
protected long |
masterKeyId |
protected java.security.PrivateKey |
masterPrivateKey |
protected java.util.Map<java.lang.Long,java.security.PublicKey> |
masterPublicKeys |
Modifier | Constructor and Description |
---|---|
protected |
SecureTokenManager() |
Modifier and Type | Method and Description |
---|---|
protected byte[] |
generateDomainAuthenticator(javax.crypto.SecretKey key,
byte[] data) |
protected byte[] |
generateMasterAuthenticator(java.security.PrivateKey key,
byte[] data) |
byte[] |
generateToken(SecureTokenSpec spec)
Generate and encode a new token from the supplied spec.
|
byte[] |
getEncodedDomainKey() |
static SecureTokenManager |
getInstance() |
boolean |
hasDomainKey() |
SecureToken |
importToken(AOByteBuffer tokenBuf) |
SecureToken |
importToken(byte[] encodedToken)
import a serialized token, decoding it into a SecureToken
object and checking it for validity.
|
void |
initDomain(byte[] domainKey)
Initialize domain key to generate and validate domain
tokens.
|
void |
initMaster(byte[] encodedPrivKey)
Initialize master private key to generate master tokens, used
only by the master server.
|
protected void |
issuerAddToken(java.lang.String issuerId,
long tokenId,
long expiry) |
protected boolean |
issuerAlreadyUsed(java.lang.String issuerId,
long tokenId) |
protected void |
issuerCleanup(java.lang.String issuerId,
long time) |
static void |
main(java.lang.String[] args) |
protected long |
nextTokenId() |
void |
registerMasterPublicKey(byte[] encodedPubKey)
Register a master public key, for use in validating master
tokens.
|
protected boolean |
validateDomainAuthenticator(javax.crypto.SecretKey key,
byte[] data,
byte[] authenticator) |
protected boolean |
validateMasterAuthenticator(java.security.PublicKey key,
byte[] data,
byte[] authenticator) |
protected static SecureTokenManager instance
protected long lastTokenId
protected long domainKeyId
protected java.util.Map<java.lang.Long,javax.crypto.SecretKey> domainKeys
protected java.util.Map<java.lang.Long,java.security.PublicKey> masterPublicKeys
protected java.security.PrivateKey masterPrivateKey
protected long masterKeyId
protected java.util.Map<java.lang.String,SecureTokenManager.IssuerHistory> issuerHistories
public static SecureTokenManager getInstance()
public SecureToken importToken(byte[] encodedToken)
The caller must check the valid flag on the generated token before doing anything with it.
A token may only be imported once. Attempting to import the same encodedToken again will return a SecureToken object with the valid flag set to false.
public SecureToken importToken(AOByteBuffer tokenBuf)
public byte[] generateToken(SecureTokenSpec spec)
protected byte[] generateDomainAuthenticator(javax.crypto.SecretKey key, byte[] data)
protected boolean validateDomainAuthenticator(javax.crypto.SecretKey key, byte[] data, byte[] authenticator)
protected byte[] generateMasterAuthenticator(java.security.PrivateKey key, byte[] data)
protected boolean validateMasterAuthenticator(java.security.PublicKey key, byte[] data, byte[] authenticator)
public void registerMasterPublicKey(byte[] encodedPubKey)
public void initMaster(byte[] encodedPrivKey)
public void initDomain(byte[] domainKey)
protected long nextTokenId()
public byte[] getEncodedDomainKey()
public boolean hasDomainKey()
protected boolean issuerAlreadyUsed(java.lang.String issuerId, long tokenId)
protected void issuerAddToken(java.lang.String issuerId, long tokenId, long expiry)
protected void issuerCleanup(java.lang.String issuerId, long time)
public static void main(java.lang.String[] args)