Skip to content

Commit

Permalink
fix: request is not resumed on JWT failure (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: Aliaksandr Stsiapanay <[email protected]>
  • Loading branch information
astsiapanay and astsiapanay authored Nov 24, 2023
1 parent 779063c commit fda238d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
14 changes: 2 additions & 12 deletions src/main/java/com/epam/aidial/core/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,8 @@ private void handleRequest(HttpServerRequest request) throws Exception {
}

request.pause();
Future<ExtractedClaims> extractedClaims;
if (authorization != null) {
try {
final boolean isJwtMustBeValidated = key.getUserAuth() != UserAuth.DISABLED;
extractedClaims = identityProvider.extractClaims(authorization, isJwtMustBeValidated);
} catch (Throwable e) {
onExtractClaimsFailure(e, config, request, key);
return;
}
} else {
extractedClaims = Future.succeededFuture();
}
final boolean isJwtMustBeValidated = key.getUserAuth() != UserAuth.DISABLED;
Future<ExtractedClaims> extractedClaims = identityProvider.extractClaims(authorization, isJwtMustBeValidated);

extractedClaims.onComplete(result -> {
try {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/epam/aidial/core/security/IdentityProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ private Future<DecodedJWT> decodeAndVerifyJwtToken(String encodedToken) {
DecodedJWT jwt = decodeJwtToken(encodedToken);
String kid = jwt.getKeyId();
Future<JwkResult> future = getJwk(kid);
JwkResult result = future.result();
if (result != null) {
return Future.succeededFuture(verifyJwt(encodedToken, result));
}
return future.map(jwkResult -> verifyJwt(encodedToken, jwkResult));
}

Expand Down Expand Up @@ -169,13 +165,17 @@ private String extractUserHash(DecodedJWT decodedJwt) {
}

public Future<ExtractedClaims> extractClaims(String authHeader, boolean isJwtMustBeVerified) {
if (authHeader == null) {
return Future.succeededFuture();
try {
if (authHeader == null) {
return Future.succeededFuture();
}
// Take the 1st authorization parameter from the header value:
// Authorization: <auth-scheme> <authorization-parameters>
String encodedToken = authHeader.split(" ")[1];
return extractClaimsFromEncodedToken(encodedToken, isJwtMustBeVerified);
} catch (Throwable e) {
return Future.failedFuture(e);
}
// Take the 1st authorization parameter from the header value:
// Authorization: <auth-scheme> <authorization-parameters>
String encodedToken = authHeader.split(" ")[1];
return extractClaimsFromEncodedToken(encodedToken, isJwtMustBeVerified);
}

public Future<ExtractedClaims> extractClaimsFromEncodedToken(String encodedToken, boolean isJwtMustBeVerified) {
Expand Down

0 comments on commit fda238d

Please sign in to comment.