diff --git a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoders.java b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoders.java index 7bd183dbaa..481c887d97 100644 --- a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoders.java +++ b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoders.java @@ -58,11 +58,12 @@ public final class JwtDecoders { * @return a {@link JwtDecoder} that was initialized by the OpenID Provider * Configuration. */ - public static JwtDecoder fromOidcIssuerLocation(String oidcIssuerLocation) { + @SuppressWarnings("unchecked") + public static T fromOidcIssuerLocation(String oidcIssuerLocation) { Assert.hasText(oidcIssuerLocation, "oidcIssuerLocation cannot be empty"); Map configuration = JwtDecoderProviderConfigurationUtils .getConfigurationForOidcIssuerLocation(oidcIssuerLocation); - return withProviderConfiguration(configuration, oidcIssuerLocation); + return (T) withProviderConfiguration(configuration, oidcIssuerLocation); } /** @@ -93,11 +94,12 @@ public final class JwtDecoders { * "https://openid.net/specs/openid-connect-core-1_0.html#IssuerIdentifier">Issuer * @return a {@link JwtDecoder} that was initialized by one of the described endpoints */ - public static JwtDecoder fromIssuerLocation(String issuer) { + @SuppressWarnings("unchecked") + public static T fromIssuerLocation(String issuer) { Assert.hasText(issuer, "issuer cannot be empty"); Map configuration = JwtDecoderProviderConfigurationUtils .getConfigurationForIssuerLocation(issuer); - return withProviderConfiguration(configuration, issuer); + return (T) withProviderConfiguration(configuration, issuer); } /** diff --git a/oauth2/oauth2-jose/src/test/java/org/springframework/security/oauth2/jwt/JwtDecodersTests.java b/oauth2/oauth2-jose/src/test/java/org/springframework/security/oauth2/jwt/JwtDecodersTests.java index 92a1966699..d3d1f8323f 100644 --- a/oauth2/oauth2-jose/src/test/java/org/springframework/security/oauth2/jwt/JwtDecodersTests.java +++ b/oauth2/oauth2-jose/src/test/java/org/springframework/security/oauth2/jwt/JwtDecodersTests.java @@ -141,7 +141,8 @@ public class JwtDecodersTests { public void issuerWhenContainsTrailingSlashThenSuccess() { this.issuer += "/"; prepareConfigurationResponse(); - assertThat(JwtDecoders.fromOidcIssuerLocation(this.issuer)).isNotNull(); + JwtDecoder jwtDecoder = JwtDecoders.fromOidcIssuerLocation(this.issuer); + assertThat(jwtDecoder).isNotNull(); assertThat(this.issuer).endsWith("/"); } @@ -149,7 +150,8 @@ public class JwtDecodersTests { public void issuerWhenOidcFallbackContainsTrailingSlashThenSuccess() { this.issuer += "/"; prepareConfigurationResponseOidc(); - assertThat(JwtDecoders.fromIssuerLocation(this.issuer)).isNotNull(); + JwtDecoder jwtDecoder = JwtDecoders.fromIssuerLocation(this.issuer); + assertThat(jwtDecoder).isNotNull(); assertThat(this.issuer).endsWith("/"); } @@ -157,7 +159,8 @@ public class JwtDecodersTests { public void issuerWhenOAuth2ContainsTrailingSlashThenSuccess() { this.issuer += "/"; prepareConfigurationResponseOAuth2(); - assertThat(JwtDecoders.fromIssuerLocation(this.issuer)).isNotNull(); + JwtDecoder jwtDecoder = JwtDecoders.fromIssuerLocation(this.issuer); + assertThat(jwtDecoder).isNotNull(); assertThat(this.issuer).endsWith("/"); }