File tree 2 files changed +26
-2
lines changed
main/java/org/springframework/security/oauth2/core
test/java/org/springframework/security/oauth2/core
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,10 @@ default Instant getClaimAsInstant(String claim) {
83
83
return null ;
84
84
}
85
85
Object claimValue = this .getClaims ().get (claim );
86
- if (Long .class .isAssignableFrom (claimValue .getClass ())) {
87
- return Instant .ofEpochSecond ((Long ) claimValue );
86
+ if (Long .class .isAssignableFrom (claimValue .getClass ()) ||
87
+ Integer .class .isAssignableFrom (claimValue .getClass ()) ||
88
+ Double .class .isAssignableFrom (claimValue .getClass ())) {
89
+ return Instant .ofEpochSecond (((Number ) claimValue ).longValue ());
88
90
}
89
91
if (Date .class .isAssignableFrom (claimValue .getClass ())) {
90
92
return ((Date ) claimValue ).toInstant ();
Original file line number Diff line number Diff line change @@ -70,4 +70,26 @@ public void getClaimAsInstantWhenInstantTypeThenReturnInstant() {
70
70
assertThat (this .claimAccessor .getClaimAsInstant (claimName )).isBetween (
71
71
expectedClaimValue .minusSeconds (1 ), expectedClaimValue .plusSeconds (1 ));
72
72
}
73
+
74
+ // gh-5250
75
+ @ Test
76
+ public void getClaimAsInstantWhenIntegerTypeSecondsThenReturnInstant () {
77
+ Instant expectedClaimValue = Instant .now ();
78
+ String claimName = "integerSeconds" ;
79
+ this .claims .put (claimName , Long .valueOf (expectedClaimValue .getEpochSecond ()).intValue ());
80
+
81
+ assertThat (this .claimAccessor .getClaimAsInstant (claimName )).isBetween (
82
+ expectedClaimValue .minusSeconds (1 ), expectedClaimValue .plusSeconds (1 ));
83
+ }
84
+
85
+ // gh-5250
86
+ @ Test
87
+ public void getClaimAsInstantWhenDoubleTypeSecondsThenReturnInstant () {
88
+ Instant expectedClaimValue = Instant .now ();
89
+ String claimName = "doubleSeconds" ;
90
+ this .claims .put (claimName , Long .valueOf (expectedClaimValue .getEpochSecond ()).doubleValue ());
91
+
92
+ assertThat (this .claimAccessor .getClaimAsInstant (claimName )).isBetween (
93
+ expectedClaimValue .minusSeconds (1 ), expectedClaimValue .plusSeconds (1 ));
94
+ }
73
95
}
You can’t perform that action at this time.
0 commit comments