File tree Expand file tree Collapse file tree
main/java/org/springframework/security/oauth2/core
test/java/org/springframework/security/oauth2/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,8 +83,10 @@ default Instant getClaimAsInstant(String claim) {
8383 return null ;
8484 }
8585 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 ());
8890 }
8991 if (Date .class .isAssignableFrom (claimValue .getClass ())) {
9092 return ((Date ) claimValue ).toInstant ();
Original file line number Diff line number Diff line change @@ -70,4 +70,26 @@ public void getClaimAsInstantWhenInstantTypeThenReturnInstant() {
7070 assertThat (this .claimAccessor .getClaimAsInstant (claimName )).isBetween (
7171 expectedClaimValue .minusSeconds (1 ), expectedClaimValue .plusSeconds (1 ));
7272 }
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+ }
7395}
You can’t perform that action at this time.
0 commit comments