Skip to content

Commit 2566abe

Browse files
committed
Add Type Parameter
Closes gh-8412
1 parent 54d3839 commit 2566abe

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoders.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ private JwtDecoders() {
5858
* @return a {@link JwtDecoder} that was initialized by the OpenID Provider
5959
* Configuration.
6060
*/
61-
public static JwtDecoder fromOidcIssuerLocation(String oidcIssuerLocation) {
61+
@SuppressWarnings("unchecked")
62+
public static <T extends JwtDecoder> T fromOidcIssuerLocation(String oidcIssuerLocation) {
6263
Assert.hasText(oidcIssuerLocation, "oidcIssuerLocation cannot be empty");
6364
Map<String, Object> configuration = JwtDecoderProviderConfigurationUtils
6465
.getConfigurationForOidcIssuerLocation(oidcIssuerLocation);
65-
return withProviderConfiguration(configuration, oidcIssuerLocation);
66+
return (T) withProviderConfiguration(configuration, oidcIssuerLocation);
6667
}
6768

6869
/**
@@ -93,11 +94,12 @@ public static JwtDecoder fromOidcIssuerLocation(String oidcIssuerLocation) {
9394
* "https://openid.net/specs/openid-connect-core-1_0.html#IssuerIdentifier">Issuer</a>
9495
* @return a {@link JwtDecoder} that was initialized by one of the described endpoints
9596
*/
96-
public static JwtDecoder fromIssuerLocation(String issuer) {
97+
@SuppressWarnings("unchecked")
98+
public static <T extends JwtDecoder> T fromIssuerLocation(String issuer) {
9799
Assert.hasText(issuer, "issuer cannot be empty");
98100
Map<String, Object> configuration = JwtDecoderProviderConfigurationUtils
99101
.getConfigurationForIssuerLocation(issuer);
100-
return withProviderConfiguration(configuration, issuer);
102+
return (T) withProviderConfiguration(configuration, issuer);
101103
}
102104

103105
/**

oauth2/oauth2-jose/src/test/java/org/springframework/security/oauth2/jwt/JwtDecodersTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,26 @@ public void issuerWhenOAuth2ResponseIsTypicalThenReturnedDecoderValidatesIssuer(
141141
public void issuerWhenContainsTrailingSlashThenSuccess() {
142142
this.issuer += "/";
143143
prepareConfigurationResponse();
144-
assertThat(JwtDecoders.fromOidcIssuerLocation(this.issuer)).isNotNull();
144+
JwtDecoder jwtDecoder = JwtDecoders.fromOidcIssuerLocation(this.issuer);
145+
assertThat(jwtDecoder).isNotNull();
145146
assertThat(this.issuer).endsWith("/");
146147
}
147148

148149
@Test
149150
public void issuerWhenOidcFallbackContainsTrailingSlashThenSuccess() {
150151
this.issuer += "/";
151152
prepareConfigurationResponseOidc();
152-
assertThat(JwtDecoders.fromIssuerLocation(this.issuer)).isNotNull();
153+
JwtDecoder jwtDecoder = JwtDecoders.fromIssuerLocation(this.issuer);
154+
assertThat(jwtDecoder).isNotNull();
153155
assertThat(this.issuer).endsWith("/");
154156
}
155157

156158
@Test
157159
public void issuerWhenOAuth2ContainsTrailingSlashThenSuccess() {
158160
this.issuer += "/";
159161
prepareConfigurationResponseOAuth2();
160-
assertThat(JwtDecoders.fromIssuerLocation(this.issuer)).isNotNull();
162+
JwtDecoder jwtDecoder = JwtDecoders.fromIssuerLocation(this.issuer);
163+
assertThat(jwtDecoder).isNotNull();
161164
assertThat(this.issuer).endsWith("/");
162165
}
163166

0 commit comments

Comments
 (0)