Skip to content

Commit ac79bcd

Browse files
EFRS-1286: Changed an expiration date format from Date to Timestamp
1 parent 25e30cd commit ac79bcd

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

java/common/src/main/java/com/exadel/frs/commonservice/system/liquibase/customchange/SetOAuthTokenExpirationCustomChange.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.exadel.frs.commonservice.system.liquibase.customchange;
22

33
import static java.time.ZoneOffset.UTC;
4-
import static java.util.Date.from;
5-
import java.sql.Date;
64
import java.sql.PreparedStatement;
75
import java.sql.SQLException;
8-
import java.time.Instant;
6+
import java.sql.Timestamp;
7+
import java.time.LocalDateTime;
98
import liquibase.change.custom.CustomTaskChange;
109
import liquibase.database.Database;
1110
import liquibase.database.jvm.JdbcConnection;
@@ -29,9 +28,9 @@ public class SetOAuthTokenExpirationCustomChange implements CustomTaskChange {
2928
private static final String SET_REFRESH_TOKEN_EXPIRATION_SQL = "UPDATE oauth_refresh_token SET expiration = ? WHERE token_id IN (SELECT refresh_token FROM oauth_access_token WHERE client_id = ?)";
3029

3130
private String clientId;
31+
private Integer accessTokenValidity;
32+
private Integer refreshTokenValidity;
3233
private String authorizedGrantTypes;
33-
private int accessTokenValidity;
34-
private int refreshTokenValidity;
3534

3635
@Override
3736
public void execute(final Database database) throws CustomChangeException {
@@ -78,18 +77,13 @@ private void setRefreshTokenExpiration(final JdbcConnection connection)
7877
private int setTokenExpiration(final JdbcConnection connection, final String sql, final int tokenValidity)
7978
throws DatabaseException, SQLException {
8079
try (PreparedStatement statement = connection.prepareStatement(sql)) {
81-
Date expiration = getExpiration(tokenValidity);
82-
statement.setDate(1, expiration);
80+
Timestamp expiration = Timestamp.valueOf(LocalDateTime.now(UTC).plusSeconds(tokenValidity));
81+
statement.setTimestamp(1, expiration);
8382
statement.setString(2, clientId);
8483
return statement.executeUpdate();
8584
}
8685
}
8786

88-
private Date getExpiration(final int validity) {
89-
Instant expiration = Instant.now().plusSeconds(validity).atOffset(UTC).toInstant();
90-
return new Date(from(expiration).getTime());
91-
}
92-
9387
@Override
9488
public String getConfirmationMessage() {
9589
return null;

0 commit comments

Comments
 (0)