parent
2356749cc3
commit
fff64db0e2
|
@ -83,8 +83,10 @@ public interface ClaimAccessor {
|
|||
return null;
|
||||
}
|
||||
Object claimValue = this.getClaims().get(claim);
|
||||
if (Long.class.isAssignableFrom(claimValue.getClass())) {
|
||||
return Instant.ofEpochSecond((Long) claimValue);
|
||||
if (Long.class.isAssignableFrom(claimValue.getClass()) ||
|
||||
Integer.class.isAssignableFrom(claimValue.getClass()) ||
|
||||
Double.class.isAssignableFrom(claimValue.getClass())) {
|
||||
return Instant.ofEpochSecond(((Number) claimValue).longValue());
|
||||
}
|
||||
if (Date.class.isAssignableFrom(claimValue.getClass())) {
|
||||
return ((Date) claimValue).toInstant();
|
||||
|
|
|
@ -70,4 +70,26 @@ public class ClaimAccessorTests {
|
|||
assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween(
|
||||
expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1));
|
||||
}
|
||||
|
||||
// gh-5250
|
||||
@Test
|
||||
public void getClaimAsInstantWhenIntegerTypeSecondsThenReturnInstant() {
|
||||
Instant expectedClaimValue = Instant.now();
|
||||
String claimName = "integerSeconds";
|
||||
this.claims.put(claimName, Long.valueOf(expectedClaimValue.getEpochSecond()).intValue());
|
||||
|
||||
assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween(
|
||||
expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1));
|
||||
}
|
||||
|
||||
// gh-5250
|
||||
@Test
|
||||
public void getClaimAsInstantWhenDoubleTypeSecondsThenReturnInstant() {
|
||||
Instant expectedClaimValue = Instant.now();
|
||||
String claimName = "doubleSeconds";
|
||||
this.claims.put(claimName, Long.valueOf(expectedClaimValue.getEpochSecond()).doubleValue());
|
||||
|
||||
assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween(
|
||||
expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue