There are multiple ways to inject values from a JWT. From the latest MP JWT Spec, the following injection combinations must be supported (using Long as an example):
@Inject
@Claim("long")
private long longClaim;
@Inject
@Claim("long")
private Long longClaimWrapper;
@Inject
@Claim("long")
private ClaimValue<Long> longClaimValue;
@Inject
@Claim("long")
private Optional<Long> longOptional;
@Inject
@Claim("long")
private ClaimValue<Optional<Long>> longClaimValueOptional;
@Inject
@Claim("long")
private JsonNumber longJson;
@Inject
@Claim("long")
private Optional<JsonNumber> longOptionalJson;
@Inject
@Claim("long")
private ClaimValue<JsonNumber> longClaimValueJson;
@Inject
@Claim("long")
private ClaimValue<Optional<JsonNumber>> longClaimValueOptionalJson;
There is also valid for other types like Boolean, String and corresponding JsonValue types. In #218, we realized that SmallRye JWT is not covering all cases and should be more consistent in how injection is done for the multiple combinations. The current implementation is able to handle the following injection combinations:
| Injection Type |
Result |
long |
OK |
Long |
OK |
ClaimValue<Long> |
Fails |
Optional<Long> |
Fails |
ClaimValue<Optional<Long>> |
Fails |
JsonNumber |
OK |
Optional<JsonNumber> |
OK |
ClaimValue<JsonNumber> |
OK |
ClaimValue<Optional<JsonNumber>> |
OK |
The main reason for injection to fail is a ClassCastException because values in the claimSet are usually stored as a JsonValue (except if it is a known claim and the type is set in the Claims enum).
So we need to determine the right type at injection point and then provide a conversion if required so the types match and injection work.
There are multiple ways to inject values from a
JWT. From the latest MP JWT Spec, the following injection combinations must be supported (usingLongas an example):There is also valid for other types like
Boolean,Stringand correspondingJsonValuetypes. In #218, we realized that SmallRye JWT is not covering all cases and should be more consistent in how injection is done for the multiple combinations. The current implementation is able to handle the following injection combinations:longLongClaimValue<Long>Optional<Long>ClaimValue<Optional<Long>>JsonNumberOptional<JsonNumber>ClaimValue<JsonNumber>ClaimValue<Optional<JsonNumber>>The main reason for injection to fail is a
ClassCastExceptionbecause values in theclaimSetare usually stored as aJsonValue(except if it is a known claim and the type is set in theClaimsenum).So we need to determine the right type at injection point and then provide a conversion if required so the types match and injection work.