Add Type Parameter

Closes gh-8412
This commit is contained in:
Josh Cummings 2020-12-11 09:22:04 -07:00
parent 54d3839f63
commit 2566abec31
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
2 changed files with 12 additions and 7 deletions

View File

@ -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);
}
/**

View File

@ -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("/");
}