File tree 2 files changed +25
-2
lines changed
main/java/org/springframework/security/oauth2/jwt
test/java/org/springframework/security/oauth2/jwt
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .security .oauth2 .jwt ;
18
18
19
+ import java .util .function .Predicate ;
20
+
19
21
import org .springframework .security .oauth2 .core .OAuth2TokenValidator ;
20
22
import org .springframework .security .oauth2 .core .OAuth2TokenValidatorResult ;
21
23
import org .springframework .util .Assert ;
28
30
*/
29
31
public final class JwtIssuerValidator implements OAuth2TokenValidator <Jwt > {
30
32
31
- private final JwtClaimValidator <String > validator ;
33
+ private final JwtClaimValidator <Object > validator ;
32
34
33
35
/**
34
36
* Constructs a {@link JwtIssuerValidator} using the provided parameters
35
37
* @param issuer - The issuer that each {@link Jwt} should have.
36
38
*/
37
39
public JwtIssuerValidator (String issuer ) {
38
40
Assert .notNull (issuer , "issuer cannot be null" );
39
- this .validator = new JwtClaimValidator (JwtClaimNames .ISS , issuer ::equals );
41
+
42
+ Predicate <Object > testClaimValue = (claimValue ) -> (claimValue != null ) && issuer .equals (claimValue .toString ());
43
+ this .validator = new JwtClaimValidator <>(JwtClaimNames .ISS , testClaimValue );
40
44
}
41
45
42
46
@ Override
Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .security .oauth2 .jwt ;
18
18
19
+ import java .net .MalformedURLException ;
20
+ import java .net .URL ;
21
+
19
22
import org .junit .Test ;
20
23
21
24
import org .springframework .security .oauth2 .core .OAuth2TokenValidatorResult ;
@@ -42,13 +45,29 @@ public void validateWhenIssuerMatchesThenReturnsSuccess() {
42
45
// @formatter:on
43
46
}
44
47
48
+ @ Test
49
+ public void validateWhenIssuerUrlMatchesThenReturnsSuccess () throws MalformedURLException {
50
+ Jwt jwt = TestJwts .jwt ().claim ("iss" , new URL (ISSUER )).build ();
51
+
52
+ assertThat (this .validator .validate (jwt )).isEqualTo (OAuth2TokenValidatorResult .success ());
53
+ }
54
+
45
55
@ Test
46
56
public void validateWhenIssuerMismatchesThenReturnsError () {
47
57
Jwt jwt = TestJwts .jwt ().claim (JwtClaimNames .ISS , "https://other" ).build ();
48
58
OAuth2TokenValidatorResult result = this .validator .validate (jwt );
49
59
assertThat (result .getErrors ()).isNotEmpty ();
50
60
}
51
61
62
+ @ Test
63
+ public void validateWhenIssuerUrlMismatchesThenReturnsError () throws MalformedURLException {
64
+ Jwt jwt = TestJwts .jwt ().claim (JwtClaimNames .ISS , new URL ("https://other" )).build ();
65
+
66
+ OAuth2TokenValidatorResult result = this .validator .validate (jwt );
67
+
68
+ assertThat (result .getErrors ()).isNotEmpty ();
69
+ }
70
+
52
71
@ Test
53
72
public void validateWhenJwtHasNoIssuerThenReturnsError () {
54
73
Jwt jwt = TestJwts .jwt ().claim (JwtClaimNames .AUD , "https://aud" ).build ();
You can’t perform that action at this time.
0 commit comments