Skip to content

Commit 40b8e75

Browse files
Revert "NIFI-15211 Replaced deprecated setSigningKeyResolver in JwtParserBuilder for NiFi Registry (#10521)"
This reverts commit 06edc1f. Signed-off-by: David Handermann <[email protected]>
1 parent ebed4fa commit 40b8e75

File tree

1 file changed

+11
-7
lines changed
  • nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/jwt

1 file changed

+11
-7
lines changed

nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/jwt/JwtService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.jsonwebtoken.JwtException;
2424
import io.jsonwebtoken.Jwts;
2525
import io.jsonwebtoken.MalformedJwtException;
26+
import io.jsonwebtoken.SigningKeyResolverAdapter;
2627
import io.jsonwebtoken.UnsupportedJwtException;
2728
import io.jsonwebtoken.security.Keys;
2829
import io.jsonwebtoken.security.MacAlgorithm;
@@ -100,18 +101,21 @@ public Set<String> getUserGroupsFromToken(final Jws<Claims> jws) throws JwtExcep
100101

101102
private Jws<Claims> parseTokenFromBase64EncodedString(final String base64EncodedToken) throws JwtException {
102103
try {
103-
return Jwts.parser().keyLocator(header -> {
104-
if (header instanceof JwsHeader) {
105-
final String keyId = (String) header.get(KEY_ID_CLAIM);
104+
return Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() {
105+
@Override
106+
public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) {
107+
final String identity = claims.getSubject();
108+
109+
// Get the key based on the key id in the claims
110+
final String keyId = claims.get(KEY_ID_CLAIM, String.class);
106111
final Key key = keyService.getKey(keyId);
107112

108113
// Ensure we were able to find a key that was previously issued by this key service for this user
109114
if (key == null || key.getKey() == null) {
110-
throw new UnsupportedJwtException("Unable to determine signing key for kid: " + keyId);
115+
throw new UnsupportedJwtException("Unable to determine signing key for " + identity + " [kid: " + keyId + "]");
111116
}
112-
return Keys.hmacShaKeyFor(key.getKey().getBytes(StandardCharsets.UTF_8));
113-
} else {
114-
throw new UnsupportedJwtException("JWE is not currently supported");
117+
118+
return key.getKey().getBytes(StandardCharsets.UTF_8);
115119
}
116120
}).build().parseSignedClaims(base64EncodedToken);
117121
} catch (final MalformedJwtException | UnsupportedJwtException | SignatureException | ExpiredJwtException | IllegalArgumentException e) {

0 commit comments

Comments
 (0)