Skip to content

Commit

Permalink
EFRS-1286: Set the zone offset to UTC for the token expiration date b…
Browse files Browse the repository at this point in the history
…efore saving it to the database
  • Loading branch information
VolodymyrBushko committed Nov 7, 2022
1 parent d2623fd commit e7407ee
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.exadel.frs.system.security;

import static java.time.ZoneOffset.UTC;
import java.sql.Types;
import java.time.LocalDateTime;
import javax.sql.DataSource;
Expand Down Expand Up @@ -50,7 +51,8 @@ public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authe
new SqlLobValue(serializeAccessToken(token)), this.authenticationKeyGenerator.extractKey(authentication),
authentication.isClientOnly() ? null : authentication.getName(),
authentication.getOAuth2Request().getClientId(),
new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken), token.getExpiration()},
new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken),
token.getExpiration().toInstant().atOffset(UTC).toLocalDateTime()},
new int[]{Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.TIMESTAMP}
);
}
Expand All @@ -62,15 +64,15 @@ public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authenticat
extractTokenKey(refreshToken.getValue()),
new SqlLobValue(serializeRefreshToken(refreshToken)),
new SqlLobValue(serializeAuthentication(authentication)),
oAuth2RefreshToken.getExpiration()},
oAuth2RefreshToken.getExpiration().toInstant().atOffset(UTC).toLocalDateTime()},
new int[]{Types.VARCHAR, Types.BLOB, Types.BLOB, Types.TIMESTAMP}
);
}

@Transactional
@Scheduled(cron = "@weekly")
@Scheduled(cron = "@weekly", zone = "UTC")
public void removeExpiredTokens() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime now = LocalDateTime.now(UTC);
int accessTokenCount = this.jdbcTemplate.update(
REMOVE_EXPIRED_ACCESS_TOKENS_SQL,
now
Expand Down

0 comments on commit e7407ee

Please sign in to comment.