Skip to content

Commit e7407ee

Browse files
EFRS-1286: Set the zone offset to UTC for the token expiration date before saving it to the database
1 parent d2623fd commit e7407ee

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

java/admin/src/main/java/com/exadel/frs/system/security/CustomJdbcTokenStore.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.exadel.frs.system.security;
22

3+
import static java.time.ZoneOffset.UTC;
34
import java.sql.Types;
45
import java.time.LocalDateTime;
56
import javax.sql.DataSource;
@@ -50,7 +51,8 @@ public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authe
5051
new SqlLobValue(serializeAccessToken(token)), this.authenticationKeyGenerator.extractKey(authentication),
5152
authentication.isClientOnly() ? null : authentication.getName(),
5253
authentication.getOAuth2Request().getClientId(),
53-
new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken), token.getExpiration()},
54+
new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken),
55+
token.getExpiration().toInstant().atOffset(UTC).toLocalDateTime()},
5456
new int[]{Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.TIMESTAMP}
5557
);
5658
}
@@ -62,15 +64,15 @@ public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authenticat
6264
extractTokenKey(refreshToken.getValue()),
6365
new SqlLobValue(serializeRefreshToken(refreshToken)),
6466
new SqlLobValue(serializeAuthentication(authentication)),
65-
oAuth2RefreshToken.getExpiration()},
67+
oAuth2RefreshToken.getExpiration().toInstant().atOffset(UTC).toLocalDateTime()},
6668
new int[]{Types.VARCHAR, Types.BLOB, Types.BLOB, Types.TIMESTAMP}
6769
);
6870
}
6971

7072
@Transactional
71-
@Scheduled(cron = "@weekly")
73+
@Scheduled(cron = "@weekly", zone = "UTC")
7274
public void removeExpiredTokens() {
73-
LocalDateTime now = LocalDateTime.now();
75+
LocalDateTime now = LocalDateTime.now(UTC);
7476
int accessTokenCount = this.jdbcTemplate.update(
7577
REMOVE_EXPIRED_ACCESS_TOKENS_SQL,
7678
now

0 commit comments

Comments
 (0)