Comments (2)
This is expected behavior.
.parseSignedClaims
will still throw an exception before returning, it's just that your Locator
is being called before it has the ability to throw the exception.
Per the parseSignedClaims
JavaDoc:
This is a convenience method logically equivalent to the following:
parse(jws).accept(Jws.CLAIMS);
So it is fully parsed/verified first (via the .parse(jws)
call) and then asserted that is the expected type (via the .accept(Jws.CLAIMS)
call. Verification (during .parse
) requires calling the key Locator
if available, so that's why it is invoked before the type assertion occurs.
The JwtParserBuilder
's .keyLocator
method JavaDoc shows in the code example that the base .locate
method implementation doesn't know what type of Header
instance will be passed, and uses instanceof
to determine the type:
jjwt/api/src/main/java/io/jsonwebtoken/JwtParserBuilder.java
Lines 460 to 471 in d4a0827
Even so, if you only ever need to support JWSs, you can simply subclass the LocatorAdapter
class as showin in the https://github.com/jwtk/jjwt#key-locator documentation:
public class MyKeyLocator extends LocatorAdapter<Key> {
@Override
public Key locate(ProtectedHeader<?> header) { // a JwsHeader or JweHeader
// implement me
}
}
But instead of overriding locate(ProtectedHeader)
, override locate(JwsHeader)
instead:
public class MyKeyLocator extends LocatorAdapter<Key> {
@Override
public Key locate(JwsHeader header) { // only ever called for JWSs
// implement me
}
}
The locator will still be called when parsing a JWE, but it will always return null
to indicate no key is found for such a header instance and will not be decrypted (i.e. it's a 'no op'), and an exception thrown.
Based on this, there doesn't appear to be a need to change JJWT's code, so I'm closing the issue, but feel free to continue to discuss if you need any clarification.
from jjwt.
Ok, thanks for the hint. It is a little more suitable to extend from LocatorAdapter
since we only need to support JWS :)
from jjwt.
Related Issues (20)
- Disable Jackson ObjectMapper FAIL_ON_UNKNOWN_PROPERTIES Deserialization Feature HOT 1
- Unable to extract claims when cty specified in JWS header (>0.12.0) HOT 19
- Question: How far is version 1.0 (due to breaking changes in 0.12)?
- NIST Elliptic Curve JWK field element octet string padding HOT 1
- Allow parsing signed JWTs without the key HOT 1
- Impossible to build a JWK with `alg: HS512` and a `k` that is larger than 64 bytes HOT 2
- Make JacksonDeserializer constructor public
- Unable to access jcaName from Jwts.SIG HOT 2
- Jwts.builder - audience cannot be add without calling add() HOT 5
- Consider a convenience method to obtain a `Jwk` from a `JwkSet` by Key ID HOT 4
- Deprecation of support for unsecured JWT token parsing with algo != 'none' HOT 3
- NoSuchMethodError when using libraries built against older jjwt version HOT 2
- Unable to verify Elliptic Curve signature using configured ECPublicKey. Invalid encoding for signature HOT 2
- CVE reported against 0.11.5 HOT 5
- CVE-2024-31033 (v0.12.5) HOT 2
- java.lang.IllegalArgumentException: Invalid Map 'iv' (Initialization Vector) value: 1230868678. Values must be either String or [B instances. Value type found: java.math.BigInteger. HOT 4
- JWE arbitrary content compression/decompression error
- X5C header does not accept a chain of certificates longer than 1 HOT 6
- Algorithm Request/Result Builders
- AUD as only array breaks legacy/existing implementations HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jjwt.