From 4b406c5b5c38fbcee3a013f32d8abe1022e78934 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Fri, 25 Aug 2023 11:41:14 -0700 Subject: [PATCH] Change the null check right after the jwtparserbuilder Signed-off-by: Ryan Liang --- .../auth/http/jwt/HTTPJwtAuthenticator.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java b/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java index 27981ff1b9..03e385d5c0 100644 --- a/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java +++ b/src/main/java/com/amazon/dlic/auth/http/jwt/HTTPJwtAuthenticator.java @@ -58,9 +58,6 @@ public HTTPJwtAuthenticator(final Settings settings, final Path configPath) { super(); String signingKey = settings.get("signing_key"); - - JwtParserBuilder jwtParserBuilder = KeyUtils.createJwtParserBuilderFromSigningKey(signingKey, log); - jwtUrlParameter = settings.get("jwt_url_parameter"); jwtHeaderName = settings.get("jwt_header", HttpHeaders.AUTHORIZATION); isDefaultAuthHeader = HttpHeaders.AUTHORIZATION.equalsIgnoreCase(jwtHeaderName); @@ -69,18 +66,19 @@ public HTTPJwtAuthenticator(final Settings settings, final Path configPath) { requireAudience = settings.get("required_audience"); requireIssuer = settings.get("required_issuer"); - if (requireAudience != null) { - jwtParserBuilder = jwtParserBuilder.require("aud", requireAudience); - } + JwtParserBuilder jwtParserBuilder = KeyUtils.createJwtParserBuilderFromSigningKey(signingKey, log); + if (jwtParserBuilder == null) { + jwtParser = null; + } else { + if (requireAudience != null) { + jwtParserBuilder = jwtParserBuilder.require("aud", requireAudience); + } - if (requireIssuer != null) { - jwtParserBuilder = jwtParserBuilder.require("iss", requireIssuer); - } + if (requireIssuer != null) { + jwtParserBuilder = jwtParserBuilder.require("iss", requireIssuer); + } - if (jwtParserBuilder != null) { jwtParser = jwtParserBuilder.build(); - } else { - jwtParser = null; } }