Browse Source

Add Type Parameter

Closes gh-8412
Josh Cummings 4 years ago
parent
commit
2566abec31

+ 6 - 4
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 extends JwtDecoder> T fromOidcIssuerLocation(String oidcIssuerLocation) {
 		Assert.hasText(oidcIssuerLocation, "oidcIssuerLocation cannot be empty");
 		Map<String, Object> 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</a>
 	 * @return a {@link JwtDecoder} that was initialized by one of the described endpoints
 	 */
-	public static JwtDecoder fromIssuerLocation(String issuer) {
+	@SuppressWarnings("unchecked")
+	public static <T extends JwtDecoder> T fromIssuerLocation(String issuer) {
 		Assert.hasText(issuer, "issuer cannot be empty");
 		Map<String, Object> configuration = JwtDecoderProviderConfigurationUtils
 				.getConfigurationForIssuerLocation(issuer);
-		return withProviderConfiguration(configuration, issuer);
+		return (T) withProviderConfiguration(configuration, issuer);
 	}
 
 	/**

+ 6 - 3
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("/");
 	}