Skip to content

Consistent Injection combinations of Claims #222

@radcortez

Description

@radcortez

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions