public class DefaultJWTProcessor<C extends SecurityContext> extends Object implements ConfigurableJWTProcessor<C>
unsecured
(plain),
signed
and
encrypted
JSON Web Tokens (JWTs).
Must be configured with the following:
header
or the
header and claims set
to
determine the key candidate(s) for the signature verification. The key
selection procedure is application-specific and may involve key ID
lookup, a certificate check and / or some
context
.header
to determine the key candidate(s) for
decryption. The key selection procedure is application-specific and may
involve key ID lookup, a certificate check and / or some
context
.An optional context parameter is available to facilitate passing of additional data between the caller and the underlying selector of key candidates (in both directions).
See sections 6 of RFC 7515 (JWS) and RFC 7516 (JWE) for guidelines on key selection.
This processor comes with the default JWS verifier factory
and the default JWE decrypter factory
; they can construct verifiers / decrypters for all
standard JOSE algorithms implemented by the library.
Note that for security reasons this processor is hardwired to reject
unsecured (plain) JWTs. Override the process(PlainJWT, SecurityContext)
if you need to handle plain JWTs as well.
A default JWT claims verifier
is
provided, to perform a minimal check of the claims after a successful JWS
verification / JWE decryption. It checks the token expiration (exp) and
not-before (nbf) timestamps if these are present. The default JWT claims
verifier may be extended to perform additional checks, such as issuer and
subject acceptance.
To process generic JOSE objects (with arbitrary payloads) use the
DefaultJOSEProcessor
class.
Constructor and Description |
---|
DefaultJWTProcessor() |
Modifier and Type | Method and Description |
---|---|
JWEDecrypterFactory |
getJWEDecrypterFactory()
Gets the factory for creating JWE decrypter instances.
|
JWEKeySelector<C> |
getJWEKeySelector()
Gets the JWE key selector.
|
JWSKeySelector<C> |
getJWSKeySelector()
Gets the JWS key selector.
|
JWSVerifierFactory |
getJWSVerifierFactory()
Gets the factory for creating JWS verifier instances.
|
JWTClaimsSetAwareJWSKeySelector<C> |
getJWTClaimsSetAwareJWSKeySelector()
Gets the JWT claims set aware JWS key selector.
|
JWTClaimsSetVerifier<C> |
getJWTClaimsSetVerifier()
Gets the optional JWT claims set verifier.
|
JWTClaimsVerifier |
getJWTClaimsVerifier()
Deprecated.
|
JWTClaimsSet |
process(EncryptedJWT encryptedJWT,
C context)
Processes the specified encrypted JWT by decrypting it.
|
JWTClaimsSet |
process(JWT jwt,
C context)
Processes the specified JWT (unsecured, signed or encrypted).
|
JWTClaimsSet |
process(PlainJWT plainJWT,
C context)
Processes the specified unsecured (plain) JWT, typically by checking
its context.
|
JWTClaimsSet |
process(SignedJWT signedJWT,
C context)
Processes the specified signed JWT by verifying its signature.
|
JWTClaimsSet |
process(String jwtString,
C context)
Parses and processes the specified JWT (unsecured, signed or
encrypted).
|
void |
setJWEDecrypterFactory(JWEDecrypterFactory factory)
Sets the factory for creating JWE decrypter instances.
|
void |
setJWEKeySelector(JWEKeySelector<C> jweKeySelector)
Sets the JWE key selector.
|
void |
setJWSKeySelector(JWSKeySelector<C> jwsKeySelector)
Sets the JWS key selector.
|
void |
setJWSVerifierFactory(JWSVerifierFactory factory)
Sets the factory for creating JWS verifier instances.
|
void |
setJWTClaimsSetAwareJWSKeySelector(JWTClaimsSetAwareJWSKeySelector<C> jwsKeySelector)
Sets the JWT claims set aware JWS key selector.
|
void |
setJWTClaimsSetVerifier(JWTClaimsSetVerifier<C> claimsVerifier)
Sets the optional JWT claims set verifier.
|
void |
setJWTClaimsVerifier(JWTClaimsVerifier claimsVerifier)
Deprecated.
|
public DefaultJWTProcessor()
public JWSKeySelector<C> getJWSKeySelector()
JOSEProcessorConfiguration
getJWSKeySelector
in interface JOSEProcessorConfiguration<C extends SecurityContext>
null
if not specified.public void setJWSKeySelector(JWSKeySelector<C> jwsKeySelector)
JOSEProcessorConfiguration
setJWSKeySelector
in interface JOSEProcessorConfiguration<C extends SecurityContext>
jwsKeySelector
- The JWS key selector, null
if not
specified.public JWTClaimsSetAwareJWSKeySelector<C> getJWTClaimsSetAwareJWSKeySelector()
JWTProcessorConfiguration
getJWTClaimsSetAwareJWSKeySelector
in interface JWTProcessorConfiguration<C extends SecurityContext>
null
if
not specified.public void setJWTClaimsSetAwareJWSKeySelector(JWTClaimsSetAwareJWSKeySelector<C> jwsKeySelector)
JWTProcessorConfiguration
setJWTClaimsSetAwareJWSKeySelector
in interface JWTProcessorConfiguration<C extends SecurityContext>
jwsKeySelector
- The JWT claims set aware JWS key selector,
null
if not specified.public JWEKeySelector<C> getJWEKeySelector()
JOSEProcessorConfiguration
getJWEKeySelector
in interface JOSEProcessorConfiguration<C extends SecurityContext>
null
if not specified.public void setJWEKeySelector(JWEKeySelector<C> jweKeySelector)
JOSEProcessorConfiguration
setJWEKeySelector
in interface JOSEProcessorConfiguration<C extends SecurityContext>
jweKeySelector
- The JWE key selector, null
if not
specified.public JWSVerifierFactory getJWSVerifierFactory()
JOSEProcessorConfiguration
getJWSVerifierFactory
in interface JOSEProcessorConfiguration<C extends SecurityContext>
null
if not specified.public void setJWSVerifierFactory(JWSVerifierFactory factory)
JOSEProcessorConfiguration
setJWSVerifierFactory
in interface JOSEProcessorConfiguration<C extends SecurityContext>
factory
- The JWS verifier factory, null
if not
specified.public JWEDecrypterFactory getJWEDecrypterFactory()
JOSEProcessorConfiguration
getJWEDecrypterFactory
in interface JOSEProcessorConfiguration<C extends SecurityContext>
null
if not specified.public void setJWEDecrypterFactory(JWEDecrypterFactory factory)
JOSEProcessorConfiguration
setJWEDecrypterFactory
in interface JOSEProcessorConfiguration<C extends SecurityContext>
factory
- The JWE decrypter factory, null
if not
specified.public JWTClaimsSetVerifier<C> getJWTClaimsSetVerifier()
JWTProcessorConfiguration
getJWTClaimsSetVerifier
in interface JWTProcessorConfiguration<C extends SecurityContext>
null
if not specified.public void setJWTClaimsSetVerifier(JWTClaimsSetVerifier<C> claimsVerifier)
JWTProcessorConfiguration
setJWTClaimsSetVerifier
in interface JWTProcessorConfiguration<C extends SecurityContext>
claimsVerifier
- The JWT claims set verifier, null
if
not specified.@Deprecated public JWTClaimsVerifier getJWTClaimsVerifier()
JWTProcessorConfiguration
JWTProcessorConfiguration.getJWTClaimsVerifier()
instead.getJWTClaimsVerifier
in interface JWTProcessorConfiguration<C extends SecurityContext>
null
if not specified.@Deprecated public void setJWTClaimsVerifier(JWTClaimsVerifier claimsVerifier)
JWTProcessorConfiguration
JWTProcessorConfiguration.setJWTClaimsSetVerifier(com.nimbusds.jwt.proc.JWTClaimsSetVerifier<C>)
instead.setJWTClaimsVerifier
in interface JWTProcessorConfiguration<C extends SecurityContext>
claimsVerifier
- The JWT claims set verifier, null
if
not specified.public JWTClaimsSet process(String jwtString, C context) throws ParseException, BadJOSEException, JOSEException
JWTProcessor
process
in interface JWTProcessor<C extends SecurityContext>
jwtString
- The JWT, compact-encoded to a URL-safe string. Must
not be null
.context
- Optional context, null
if not required.ParseException
- If the string couldn't be parsed to a valid
JWT.BadJOSEException
- If the JWT is rejected.JOSEException
- If an internal processing exception is
encountered.public JWTClaimsSet process(JWT jwt, C context) throws BadJOSEException, JOSEException
JWTProcessor
process
in interface JWTProcessor<C extends SecurityContext>
jwt
- The JWT. Must not be null
.context
- Optional context, null
if not required.BadJOSEException
- If the JWT is rejected.JOSEException
- If an internal processing exception is
encountered.public JWTClaimsSet process(PlainJWT plainJWT, C context) throws BadJOSEException, JOSEException
JWTProcessor
process
in interface JWTProcessor<C extends SecurityContext>
plainJWT
- The unsecured (plain) JWT. Not null
.context
- Optional context, null
if not required.BadJOSEException
- If the unsecured (plain) JWT is rejected,
after examining the context or due to the
payload not being a JSON object.JOSEException
- If an internal processing exception is
encountered.public JWTClaimsSet process(SignedJWT signedJWT, C context) throws BadJOSEException, JOSEException
JWTProcessor
process
in interface JWTProcessor<C extends SecurityContext>
signedJWT
- The signed JWT. Not null
.context
- Optional context, null
if not required.BadJOSEException
- If the signed JWT is rejected, typically
due to a bad signature or the payload not
being a JSON object.JOSEException
- If an internal processing exception is
encountered.public JWTClaimsSet process(EncryptedJWT encryptedJWT, C context) throws BadJOSEException, JOSEException
JWTProcessor
process
in interface JWTProcessor<C extends SecurityContext>
encryptedJWT
- The encrypted JWT. Not null
.context
- Optional context, null
if not required.BadJOSEException
- If the encrypted JWT is rejected, typically
due to failed decryption or the payload not
being a JSON object.JOSEException
- If an internal processing exception is
encountered.Copyright © 2019 Connect2id Ltd.. All rights reserved.