File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
main/java/org/springframework/security/oauth2/core
test/java/org/springframework/security/oauth2/core Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -53,13 +53,17 @@ default Boolean containsClaim(String claim) {
53
53
}
54
54
55
55
/**
56
- * Returns the claim value as a {@code String} or {@code null} if it does not exist.
56
+ * Returns the claim value as a {@code String} or {@code null} if it does not exist or is equal to {@code null} .
57
57
*
58
58
* @param claim the name of the claim
59
- * @return the claim value or {@code null} if it does not exist
59
+ * @return the claim value or {@code null} if it does not exist or is equal to {@code null}
60
60
*/
61
61
default String getClaimAsString (String claim ) {
62
- return (this .containsClaim (claim ) ? this .getClaims ().get (claim ).toString () : null );
62
+ if (!this .containsClaim (claim )) {
63
+ return null ;
64
+ }
65
+ Object claimValue = this .getClaims ().get (claim );
66
+ return (claimValue != null ? claimValue .toString () : null );
63
67
}
64
68
65
69
/**
Original file line number Diff line number Diff line change @@ -70,4 +70,13 @@ public void getClaimAsInstantWhenInstantTypeThenReturnInstant() {
70
70
assertThat (this .claimAccessor .getClaimAsInstant (claimName )).isBetween (
71
71
expectedClaimValue .minusSeconds (1 ), expectedClaimValue .plusSeconds (1 ));
72
72
}
73
+
74
+ // gh-5608
75
+ @ Test
76
+ public void getClaimAsStringWhenValueIsNullThenReturnNull () {
77
+ String claimName = "claim-with-null-value" ;
78
+ this .claims .put (claimName , null );
79
+
80
+ assertThat (this .claimAccessor .getClaimAsString (claimName )).isEqualTo (null );
81
+ }
73
82
}
You can’t perform that action at this time.
0 commit comments