Package org.forgerock.openig.filter
Class JwtBuilderFilter
- java.lang.Object
-
- org.forgerock.openig.filter.JwtBuilderFilter
-
- All Implemented Interfaces:
Filter
public class JwtBuilderFilter extends Object implements Filter
The JwtBuilderFilter collects data from template and puts the name-value pairs into a JWT structure. Then the JWT structure is placed in a context JwtBuilderContext for downstream use.This filter can produce:
- unsecured (unsigned JWT are deprecated as not secure)
- signed JWT
- signed then encrypted JWT
- encrypted JWT
{ "type": "JwtBuilderFilter", "config": { "template" : map/expression [REQUIRED] "secretsProvider": : Secrets Provider [OPTIONAL - resolve signing/encryption keys.] "signature" : { object [OPTIONAL but if set, inner attributes MAY BE REQUIRED] "secretId" : expression [REQUIRED - secret ID of the key used for signing] "algorithm" : expression [OPTIONAL - default to RS256 (1)] "encryption" : { object [OPTIONAL but if set, inner attributes are REQUIRED] "secretId" : expression [REQUIRED - secret ID of the key used for encryption] "algorithm" : expression [REQUIRED - The encryption algorithm (1)] "method" : expression [REQUIRED - The encryption method (2)] } } "encryption" : { object [OPTIONAL but if set, inner attributes are REQUIRED] "secretId" : expression [REQUIRED - secret ID of the key used for encryption] "algorithm" : expression [REQUIRED - The encryption algorithm (1)] "method" : expression [REQUIRED - The encryption method (2)] } } }
(1) List of JWS Algorithms (2) List of JWE Algorithms (3) List of Encryption Methods
Example of use - unsecured(unsigned) JWT (deprecated):{ "type": "JwtBuilderFilter", "config": { "template": { "mail": "${contexts.userProfile.rawInfo.mail[0]}", "employeeNumber": "${contexts.userProfile.rawInfo.employeeNumber[0]}" } } }
{ "type": "JwtBuilderFilter", "config": { "template": "${attributes.userProfile}", "signature": { "secretId": "my.signature.key", "algorithm": "HS384" } } }
{ "type": "JwtBuilderFilter", "config": { "template": { "mail": "${contexts.userProfile.rawInfo.mail[0]}", "employeeNumber": "${contexts.userProfile.rawInfo.employeeNumber[0]}" }, "signature": { "secretId": "my.signature.key", "algorithm": "HS256", "encryption": { "secretId": "my.encryption.key", "algorithm": "dir", "method": "A128CBC-HS256" } } } }
{ "name": "JwtBuilderFilter-1", "type": "JwtBuilderFilter", "config": { "template": "${attributes.userProfile}", "secretsProvider": "SystemAndEnvSecretStore-1" "encryption": { "secretId": "my.encryption.key", "algorithm": "dir", "method": "A128GCM" } } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JwtBuilderFilter.Heaplet
Creates and initializes an JwtBuilderFilter in a heap environment.
-
Constructor Summary
Constructors Constructor Description JwtBuilderFilter(JsonValue template, JwtFactory jwtFactory)
Creates a newJwtBuilderFilter
which will create a JWT based on the given JSON template and place it into the context JwtBuilderContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Promise<Response,NeverThrowsException>
filter(Context context, Request request, Handler next)
Filters the request and/or response of an exchange.
-
-
-
Constructor Detail
-
JwtBuilderFilter
public JwtBuilderFilter(JsonValue template, JwtFactory jwtFactory) throws ExpressionException
Creates a newJwtBuilderFilter
which will create a JWT based on the given JSON template and place it into the context JwtBuilderContext.- Parameters:
template
- The template representing the name-value pairs, notnull
, asJsonValue
. It must be a Map or a String, ie: "template" : { "value": "pair"} or "template" : "${attributes.template}.jwtFactory
- TheJwtFactory
used to create the JWT, notnull
.- Throws:
ExpressionException
- When the template contains invalid expressions
-
-
Method Detail
-
filter
public Promise<Response,NeverThrowsException> filter(Context context, Request request, Handler next)
Description copied from interface:Filter
Filters the request and/or response of an exchange. To pass the request to the next filter or handler in the chain, the filter callsnext.handle(context, request)
.This method may elect not to pass the request to the next filter or handler, and instead handle the request itself. It can achieve this by merely avoiding a call to
next.handle(context, request)
and creating its own response object. The filter is also at liberty to replace a response with another of its own by intercepting the response returned by the next handler.
-
-