public class TokenUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
TokenUtils.InvalidClaims
Enums to indicate which claims should be set to invalid values for testing failure modes
|
Modifier and Type | Method and Description |
---|---|
static int |
currentTimeInSecs() |
static ECPrivateKey |
decodeECPrivateKey(String pemEncoded)
Decode a PEM encoded private key string to an EC PrivateKey
|
static ECPublicKey |
decodeECPublicKey(String pemEncoded)
Decode a PEM encoded public key string to an EC PublicKey
|
static RSAPrivateKey |
decodePrivateKey(String pemEncoded)
Decode a PEM encoded private key string to an RSA PrivateKey
|
static RSAPublicKey |
decodePublicKey(String pemEncoded)
Decode a PEM encoded public key string to an RSA PublicKey
|
static String |
encryptClaims(PublicKey pk,
KeyManagementAlgorithm keyAlgorithm,
String kid,
String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the public key, possibly
with invalid fields.
|
static String |
encryptClaims(PublicKey pk,
String jsonResName)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the public key.
|
static String |
encryptClaims(PublicKey pk,
String kid,
String jsonResName)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the public key.
|
static String |
encryptClaims(PublicKey pk,
String kid,
String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the public key, possibly
with invalid fields.
|
static String |
encryptClaims(String jsonResName)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the publicKey.pem test
resource key.
|
static String |
encryptClaims(String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the publicKey.pem test
resource key, possibly with invalid fields.
|
static String |
encryptClaims(String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Utility method to generate a JWT string from a JSON resource file that is encrypted by the publicKey.pem test
resource key, possibly with invalid fields.
|
static KeyPair |
generateKeyPair(int keySize)
Generate a new RSA keypair.
|
static String |
generateTokenString(PrivateKey pk,
String kid,
String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Deprecated.
|
static String |
generateTokenString(String jsonResName)
Deprecated.
|
static String |
generateTokenString(String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims)
Deprecated.
|
static String |
generateTokenString(String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Deprecated.
|
static ECPrivateKey |
readECPrivateKey(String pemResName)
Read a PEM encoded EC private key from the classpath
|
static ECPublicKey |
readECPublicKey(String pemResName)
Read a PEM encoded EC public key from the classpath
|
static PrivateKey |
readJwkPrivateKey(String jwkResName)
Read a private key in JWK format from the classpath
|
static PublicKey |
readJwkPublicKey(String jwkResName)
Read a public key in JWK format from the classpath
|
static RSAPrivateKey |
readPrivateKey(String pemResName)
Read a PEM encoded RSA private key from the classpath
|
static RSAPublicKey |
readPublicKey(String pemResName)
Read a PEM encoded RSA public key from the classpath
|
static String |
readResource(String resName)
Read a classpath resource into a string and return it.
|
static String |
signClaims(PrivateKey pk,
String kid,
String jsonResName)
Utility method to generate a JWT string from a JSON resource file that is signed by the private key using either
RS256 or ES256 algorithm.
|
static String |
signClaims(PrivateKey pk,
String kid,
String jsonResName,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Utility method to generate a JWT string from a JSON resource file that is signed by the private key using either
RS256 or ES256 algorithm, possibly with invalid fields.
|
static String |
signClaims(String jsonResName)
Utility method to generate a JWT string from a JSON resource file that is signed by the privateKey.pem test
resource key using RS256 algorithm.
|
static String |
signClaims(String jsonResName,
SignatureAlgorithm algorithm)
Utility method to generate a JWT string from a JSON resource file that is signed by the privateKey.pem test
resource key using either RS256 or ES256 algorithm.
|
static String |
signClaims(String jsonResName,
SignatureAlgorithm algorithm,
Set<TokenUtils.InvalidClaims> invalidClaims)
Utility method to generate a JWT string from a JSON resource file that is signed by the privateKey.pem test
resource key using either RS256 or ES256 algorithm, possibly with invalid fields.
|
static String |
signClaims(String jsonResName,
SignatureAlgorithm algorithm,
Set<TokenUtils.InvalidClaims> invalidClaims,
Map<String,Long> timeClaims)
Utility method to generate a JWT string from a JSON resource file that is signed by either the privateKey.pem
test resource using RS256 algorithm or the ecPrivateKey.pem test resource using ES256 algorithm, possibly with
invalid fields and custom time claims.
|
static String |
signEncryptClaims(PrivateKey signingKey,
PublicKey encryptionKey,
String jsonResName)
Utility method to generate a JWT string from a JSON resource file by signing it first with the private key using
RS256 algorithm and encrypting next with the public key.
|
static String |
signEncryptClaims(PrivateKey signingKey,
String signingKid,
PublicKey encryptionKey,
KeyManagementAlgorithm keyAlgorithm,
String encryptionKid,
String jsonResName,
boolean setContentType)
Utility method to generate a JWT string from a JSON resource file by signing it first with the private key using
RS256 algorithm and encrypting next with the public key with an option to skip setting a content-type 'cty'
parameter.
|
static String |
signEncryptClaims(PrivateKey signingKey,
String signingKid,
PublicKey encryptionKey,
String encryptionKid,
String jsonResName)
Utility method to generate a JWT string from a JSON resource file by signing it first with the private key using
RS256 algorithm and and encrypting next with the public key.
|
static String |
signEncryptClaims(PrivateKey signingKey,
String signingKid,
PublicKey encryptionKey,
String encryptionKid,
String jsonResName,
boolean setContentType)
Utility method to generate a JWT string from a JSON resource file by signing it first with the private key using
RS256 algorithm and encrypting next with the public key with an option to skip setting a content-type 'cty'
parameter.
|
static String |
signEncryptClaims(String jsonResName)
Utility method to generate a JWT string from a JSON resource file by signing it first with the privateKey.pem
test resource using RS256 algorithm and encrypting next with the publicKey.pem test resource.
|
static String |
signEncryptClaims(String jsonResName,
SignatureAlgorithm signatureAlgorithm)
Utility method to generate a JWT string from a JSON resource file by signing it first by either the
privateKey.pem test resource using RS256 algorithm or the ecPrivateKey.pem test resource using ES256 algorithm
and encrypting it next with the publicKey.pem test resource.
|
@Deprecated public static String generateTokenString(String jsonResName) throws Exception
jsonResName
- - name of test resources fileException
- on parse failurepublic static String signClaims(String jsonResName) throws Exception
jsonResName
- - name of test resources fileException
- on parse failurepublic static String signClaims(String jsonResName, SignatureAlgorithm algorithm) throws Exception
jsonResName
- - name of test resources filealgorithm
- - signature algorithmException
- on parse failure@Deprecated public static String generateTokenString(String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims) throws Exception
jsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modesException
- on parse failurepublic static String signClaims(String jsonResName, SignatureAlgorithm algorithm, Set<TokenUtils.InvalidClaims> invalidClaims) throws Exception
jsonResName
- - name of test resources filealgorithm
- - signature algorithminvalidClaims
- - the set of claims that should be added with invalid values to test failure modesException
- on parse failure@Deprecated public static String generateTokenString(String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
jsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failurepublic static String signClaims(String jsonResName, SignatureAlgorithm algorithm, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
jsonResName
- - name of test resources filealgorithm
- - signature algorithminvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failure@Deprecated public static String generateTokenString(PrivateKey pk, String kid, String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
pk
- - the private key to sign the token withkid
- - the kid header to assign to the tokenjsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failurepublic static String signClaims(PrivateKey pk, String kid, String jsonResName) throws Exception
pk
- - the private key to sign the token withkid
- - the kid claim to assign to the tokenjsonResName
- - name of test resources fileException
- on parse failurepublic static String signClaims(PrivateKey pk, String kid, String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
pk
- - the private key to sign the token withkid
- - the kid claim to assign to the tokenjsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failurepublic static String encryptClaims(String jsonResName) throws Exception
jsonResName
- - name of test resources fileException
- on parse failurepublic static String encryptClaims(String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims) throws Exception
jsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modesException
- on parse failurepublic static String encryptClaims(String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
jsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failurepublic static String encryptClaims(PublicKey pk, String jsonResName) throws Exception
pk
- - the public key to encrypt the token withjsonResName
- - name of test resources fileException
- on parse failurepublic static String encryptClaims(PublicKey pk, String kid, String jsonResName) throws Exception
pk
- - the public key to encrypt the token withkid
- - the kid header to assign to the tokenjsonResName
- - name of test resources fileException
- on parse failurepublic static String encryptClaims(PublicKey pk, String kid, String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
pk
- - the public key to encrypt the token withkid
- - the kid header to assign to the tokenjsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failurepublic static String encryptClaims(PublicKey pk, KeyManagementAlgorithm keyAlgorithm, String kid, String jsonResName, Set<TokenUtils.InvalidClaims> invalidClaims, Map<String,Long> timeClaims) throws Exception
pk
- - the public key to encrypt the token withkeyAlgorithm
- - the key encryption algorithmkid
- - the kid header to assign to the tokenjsonResName
- - name of test resources fileinvalidClaims
- - the set of claims that should be added with invalid values to test failure modestimeClaims
- - used to return the exp, iat, auth_time claimsException
- on parse failurepublic static String signEncryptClaims(String jsonResName) throws Exception
jsonResName
- - name of test resources fileException
- on parse failurepublic static String signEncryptClaims(String jsonResName, SignatureAlgorithm signatureAlgorithm) throws Exception
jsonResName
- - name of test resources filesignatureAlgorithm
- - signature algorithmException
- on parse failurepublic static String signEncryptClaims(PrivateKey signingKey, PublicKey encryptionKey, String jsonResName) throws Exception
signingKey
- - the private key to sign the token withencryptionKey
- - the public key to encrypt the token withjsonResName
- - name of test resources fileException
- on parse failurepublic static String signEncryptClaims(PrivateKey signingKey, String signingKid, PublicKey encryptionKey, String encryptionKid, String jsonResName) throws Exception
signingKey
- - the private key to sign the token withsigningKid
- - the signing key identifierencryptionKey
- - the public key to encrypt the token withencryptionKid
- - the encryption key identifierjsonResName
- - name of test resources fileException
- on parse failurepublic static String signEncryptClaims(PrivateKey signingKey, String signingKid, PublicKey encryptionKey, String encryptionKid, String jsonResName, boolean setContentType) throws Exception
signingKey
- - the private key to sign the token withsigningKid
- - the signing key identifierencryptionKey
- - the public key to encrypt the token withencryptionKid
- - the encryption key identifierjsonResName
- - name of test resources filesetContentType
- - set a content-type 'cty' parameter if trueException
- on parse failurepublic static String signEncryptClaims(PrivateKey signingKey, String signingKid, PublicKey encryptionKey, KeyManagementAlgorithm keyAlgorithm, String encryptionKid, String jsonResName, boolean setContentType) throws Exception
signingKey
- - the private key to sign the token withsigningKid
- - the signing key identifierencryptionKey
- - the public key to encrypt the token withkeyEncryptionAlgorithm
- - the key encryption algorithmencryptionKid
- - the encryption key identifierjsonResName
- - name of test resources filesetContentType
- - set a content-type 'cty' parameter if trueException
- on parse failurepublic static String readResource(String resName) throws IOException
resName
- - classpath resource nameIOException
- - on failurepublic static RSAPrivateKey readPrivateKey(String pemResName) throws Exception
pemResName
- - key file resource nameException
- on decode failurepublic static ECPrivateKey readECPrivateKey(String pemResName) throws Exception
pemResName
- - key file resource nameException
- on decode failurepublic static RSAPublicKey readPublicKey(String pemResName) throws Exception
pemResName
- - key file resource nameException
- on decode failurepublic static ECPublicKey readECPublicKey(String pemResName) throws Exception
pemResName
- - key file resource nameException
- on decode failurepublic static PublicKey readJwkPublicKey(String jwkResName) throws Exception
jwkResName
- - key file resource nameException
- on decode failurepublic static PrivateKey readJwkPrivateKey(String jwkResName) throws Exception
jwkResName
- - key file resource nameException
- on decode failurepublic static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException
keySize
- - the size of the keyNoSuchAlgorithmException
- on failure to load RSA key generatorpublic static RSAPrivateKey decodePrivateKey(String pemEncoded) throws Exception
pemEncoded
- - PEM string for private keyException
- on decode failurepublic static ECPrivateKey decodeECPrivateKey(String pemEncoded) throws Exception
pemEncoded
- - PEM string for private keyException
- on decode failurepublic static RSAPublicKey decodePublicKey(String pemEncoded) throws Exception
pemEncoded
- - PEM string for private keyException
- on decode failurepublic static ECPublicKey decodeECPublicKey(String pemEncoded) throws Exception
pemEncoded
- - PEM string for private keyException
- on decode failurepublic static int currentTimeInSecs()
Copyright © 2017 – 2022 Eclipse Foundation. All rights reserved.
Use is subject to license terms.