Class TestTokenHelper
- java.lang.Object
-
- net.shibboleth.idp.plugin.authn.oidc.rp.test.TestTokenHelper
-
public final class TestTokenHelper extends Object
A helper class for generating tokens for testing.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateTestTokenHelper()Private constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static StringbuildTemplateAccessTokenJSONResponse(String serializedJWT)Build a simple OAuth2.0/OIDC Access Token JSON response using the serialized JWT.static StringcreateAccessTokenResponseJSON(Map<String,Object> overrideClaims, com.nimbusds.jose.JWSAlgorithm sigAlg, com.nimbusds.jose.JWEAlgorithm jweAlg, com.nimbusds.jose.EncryptionMethod enc, Credential sigKey, Credential encKey)Create an access token response JSON object and build a suitable id_token to include in the response.static com.nimbusds.jwt.JWTClaimsSetcreateBasicClaims(Map<String,Object> overrideClaims)Build a basicJWTClaimsSetfrom the supplied parameters.static com.nimbusds.jwt.JWTClaimsSetcreateBasicUserInfoClaims(Map<String,Object> overrideClaims)Build a basicJWTClaimsSetfrom the supplied parameters to mock a UserInfo response.static com.nimbusds.jwt.JWTcreateJWT(com.nimbusds.jwt.JWTClaimsSet payload, com.nimbusds.jose.JWSAlgorithm sigAlg, com.nimbusds.jose.JWEAlgorithm jweAlg, com.nimbusds.jose.EncryptionMethod enc, Credential sigKey, Credential encKey)Create a JWT from the given payload.static com.nimbusds.jwt.JWTcreateJWTUserInfoResponse(Map<String,Object> overrideClaims, com.nimbusds.jose.JWSAlgorithm sigAlg, com.nimbusds.jose.JWEAlgorithm jweAlg, com.nimbusds.jose.EncryptionMethod enc, Credential sigKey, Credential encKey)Create a JWT UserInfo response.static com.nimbusds.jwt.PlainJWTcreatePlainJWTUserInfoResponseJSON(Map<String,Object> overrideClaims)Create a Plain UserInfo response JWT.static StringcreatePlainUserInfoResponseString(Map<String,Object> overrideClaims)Create a plain JSON object based UserInfo response.private static <T> TgetClaimValue(Map<String,Object> overrideClaims, String claimName, Object defaultValue, Class<T> type)Extract any override from the overrides map, or return the default value if there is none.
-
-
-
Method Detail
-
createBasicClaims
public static com.nimbusds.jwt.JWTClaimsSet createBasicClaims(Map<String,Object> overrideClaims)
Build a basicJWTClaimsSetfrom the supplied parameters.- Parameters:
overrideClaims- claims to override- Returns:
- the JWT claims set.
-
createBasicUserInfoClaims
public static com.nimbusds.jwt.JWTClaimsSet createBasicUserInfoClaims(Map<String,Object> overrideClaims)
Build a basicJWTClaimsSetfrom the supplied parameters to mock a UserInfo response.- Parameters:
overrideClaims- claims to override- Returns:
- the JWT claims set.
-
getClaimValue
private static <T> T getClaimValue(Map<String,Object> overrideClaims, String claimName, Object defaultValue, Class<T> type)
Extract any override from the overrides map, or return the default value if there is none.- Type Parameters:
T- the type to look for and return- Parameters:
overrideClaims- the overrides mapclaimName- the claim namedefaultValue- the default value if no override is foundtype- the type to return- Returns:
- the override or the default value.
-
createJWT
public static com.nimbusds.jwt.JWT createJWT(@Nonnull com.nimbusds.jwt.JWTClaimsSet payload, @Nullable com.nimbusds.jose.JWSAlgorithm sigAlg, @Nullable com.nimbusds.jose.JWEAlgorithm jweAlg, @Nullable com.nimbusds.jose.EncryptionMethod enc, @Nullable Credential sigKey, @Nullable Credential encKey) throws com.nimbusds.jose.JOSEException, ParseExceptionCreate a JWT from the given payload. The JWT can either be plain, or signed and encrypted. If encrypted, it must be signed.- Parameters:
payload- the payload to create the JWT fromsigAlg- the signature alg to use.Nullif the JWT is not going to be signed and/or encrypted.jweAlg- the encryption alg to use.Nullif the JWT is not going to be encrypted. Note, if encrypted the signature algorithm must also be supplied, otherwise a plain JWT will be returned.enc- the content encryption algorithm to use.sigKey- the key to use for signingencKey- the key to use for encryption- Returns:
- and plain JWT, JWS, or JWE.
- Throws:
com.nimbusds.jose.JOSEException- on error.ParseException- on error.
-
createJWTUserInfoResponse
public static com.nimbusds.jwt.JWT createJWTUserInfoResponse(Map<String,Object> overrideClaims, @Nullable com.nimbusds.jose.JWSAlgorithm sigAlg, @Nullable com.nimbusds.jose.JWEAlgorithm jweAlg, @Nullable com.nimbusds.jose.EncryptionMethod enc, @Nullable Credential sigKey, @Nullable Credential encKey) throws com.nimbusds.jose.JOSEException, ParseException
Create a JWT UserInfo response. Can be a JWS or JWE depending on the input values.- Parameters:
overrideClaims- claims to overridesigAlg- the signature algorithmjweAlg- the encryption algorithmenc- the content encryption algorithmsigKey- the signing keyencKey- the encryption key- Returns:
- the created JWT
- Throws:
com.nimbusds.jose.JOSEException- on errorParseException- on error
-
createAccessTokenResponseJSON
public static String createAccessTokenResponseJSON(Map<String,Object> overrideClaims, @Nullable com.nimbusds.jose.JWSAlgorithm sigAlg, @Nullable com.nimbusds.jose.JWEAlgorithm jweAlg, @Nullable com.nimbusds.jose.EncryptionMethod enc, @Nullable Credential sigKey, @Nullable Credential encKey) throws Exception
Create an access token response JSON object and build a suitable id_token to include in the response. Any claim contained in the overrides list overrides the default value built by the basic claims method.- Parameters:
overrideClaims- claims to override in the id_tokensigAlg- the signature algorithmjweAlg- the encryption algorithmenc- the content encryption algorithmsigKey- the signing keyencKey- the encryption key- Returns:
- an access token response JSON object
- Throws:
Exception- on error.
-
createPlainUserInfoResponseString
public static String createPlainUserInfoResponseString(Map<String,Object> overrideClaims) throws com.fasterxml.jackson.core.JsonProcessingException
Create a plain JSON object based UserInfo response.- Parameters:
overrideClaims- claims to override- Returns:
- a plain JSON object representing the UserInfo response
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- on error
-
createPlainJWTUserInfoResponseJSON
public static com.nimbusds.jwt.PlainJWT createPlainJWTUserInfoResponseJSON(Map<String,Object> overrideClaims) throws com.nimbusds.jose.JOSEException
Create a Plain UserInfo response JWT.- Parameters:
overrideClaims- claims to override- Returns:
- the signed JWT
- Throws:
com.nimbusds.jose.JOSEException- on error
-
-