dbeaver/pro#5214 set timestamp with utc calendar fix (#3404)

Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
This commit is contained in:
Ainur
2025-05-06 10:04:00 +02:00
committed by GitHub
co-authored by Daria Marutkina
parent 16fcc21346
commit 0095cc8d37
@@ -163,7 +163,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
) {
dbStat.setString(1, userId);
dbStat.setString(2, enabled ? CHAR_BOOL_TRUE : CHAR_BOOL_FALSE);
dbStat.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 3, new Timestamp(System.currentTimeMillis()));
if (CommonUtils.isEmpty(defaultAuthRole)) {
dbStat.setNull(4, Types.VARCHAR);
} else {
@@ -333,7 +333,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
}
dbStat.setString(1, userId);
dbStat.setString(2, teamId);
dbStat.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 3, new Timestamp(System.currentTimeMillis()));
dbStat.setString(4, grantorId);
dbStat.execute();
}
@@ -379,7 +379,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
resultTeamIds.add(teamId);
dbStat.setString(1, userId);
dbStat.setString(2, teamId);
dbStat.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 3, new Timestamp(System.currentTimeMillis()));
dbStat.setString(4, grantorId);
dbStat.execute();
}
@@ -798,7 +798,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
try (PreparedStatement dbStat = dbCon.prepareStatement(
"UPDATE {table_prefix}CB_USER SET IS_ACTIVE=?, CHANGE_DATE=?, DISABLED_BY=?, DISABLE_REASON=? WHERE USER_ID=?")) {
dbStat.setString(1, enabled ? CHAR_BOOL_TRUE : CHAR_BOOL_FALSE);
dbStat.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 2, new Timestamp(System.currentTimeMillis()));
JDBCUtils.setStringOrNull(dbStat, 3, enabled ? null : disabledBy);
JDBCUtils.setStringOrNull(dbStat, 4, enabled ? null : disableReason);
dbStat.setString(5, userId);
@@ -1276,7 +1276,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
dbStat.setString(1, teamId);
dbStat.setString(2, CommonUtils.notEmpty(name));
dbStat.setString(3, CommonUtils.notEmpty(description));
dbStat.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 4, new Timestamp(System.currentTimeMillis()));
dbStat.execute();
}
@@ -1416,7 +1416,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
for (String permission : permissionIds) {
dbStat.setString(1, subjectId);
dbStat.setString(2, permission);
dbStat.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 3, new Timestamp(System.currentTimeMillis()));
dbStat.setString(4, grantorId);
dbStat.execute();
}
@@ -1519,8 +1519,8 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
JDBCUtils.setStringOrNull(dbStat, 3, userId);
Timestamp currentTS = new Timestamp(System.currentTimeMillis());
dbStat.setTimestamp(4, currentTS);
dbStat.setTimestamp(5, currentTS);
setTimestamp(dbStat, 4, currentTS);
setTimestamp(dbStat, 5, currentTS);
JDBCUtils.setStringOrNull(dbStat, 6, CommonUtils.truncateString(CommonUtils.toString(
parameters.get(SMConstants.SESSION_PARAM_LAST_REMOTE_ADDRESS), null), 128));
JDBCUtils.setStringOrNull(dbStat, 7, CommonUtils.truncateString(CommonUtils.toString(
@@ -1782,8 +1782,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
)) {
dbStat.setString(1, authProviderId);
dbStat.setString(2, inputLogin);
dbStat.setTimestamp(3,
Timestamp.valueOf(LocalDateTime.now().minusSeconds(smConfig.getBlockLoginPeriod())));
setTimestamp(dbStat, 3, Timestamp.from(Instant.now().minusSeconds(smConfig.getBlockLoginPeriod())));
try (ResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
UserLoginRecord loginDto = new UserLoginRecord(
@@ -2595,12 +2594,12 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
JDBCUtils.setStringOrNull(dbStat, 3, userId);
JDBCUtils.setStringOrNull(dbStat, 4, authRole);
var accessTokenExpirationTime = Timestamp.valueOf(LocalDateTime.now().plusMinutes(smConfig.getAccessTokenTtl()));
dbStat.setTimestamp(5, accessTokenExpirationTime);
setTimestamp(dbStat, 5, accessTokenExpirationTime);
String smRefreshToken = SecurityUtils.generatePassword(32);
dbStat.setString(6, smRefreshToken);
var refreshTokenExpirationTime = Timestamp.valueOf(LocalDateTime.now().plusMinutes(smConfig.getRefreshTokenTtl()));
dbStat.setTimestamp(7, refreshTokenExpirationTime);
setTimestamp(dbStat, 7, refreshTokenExpirationTime);
dbStat.setString(8, booleanToString(isServiceToken));
dbStat.execute();
@@ -2645,7 +2644,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
dbStat.setString(1, userId);
//count only tokens actually used by users
dbStat.setString(2, SMAuthStatus.EXPIRED.name());
dbStat.setTimestamp(3, Timestamp.valueOf(currentTime));
setTimestamp(dbStat, 3, Timestamp.valueOf(currentTime));
dbStat.setString(4, booleanToString(isService));
try (ResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
@@ -2762,7 +2761,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
SET USER_ID=?,LAST_ACCESS_TIME=?,LAST_ACCESS_REMOTE_ADDRESS=?,LAST_ACCESS_USER_AGENT=?,LAST_ACCESS_INSTANCE_ID=? \
WHERE SESSION_ID=?""")) {
JDBCUtils.setStringOrNull(dbStat, 1, userId);
dbStat.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 2, new Timestamp(System.currentTimeMillis()));
JDBCUtils.setStringOrNull(dbStat, 3, CommonUtils.truncateString(CommonUtils.toString(
parameters.get(SMConstants.SESSION_PARAM_LAST_REMOTE_ADDRESS), null), 128));
JDBCUtils.setStringOrNull(dbStat, 4, CommonUtils.truncateString(CommonUtils.toString(
@@ -2816,7 +2815,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
for (String objectId : objectIds) {
dbStat.setString(1, objectId);
dbStat.setString(2, objectType.name());
dbStat.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 3, new Timestamp(System.currentTimeMillis()));
dbStat.setString(4, grantor);
for (String subjectId : subjectIds) {
if (!filteredSubjects.contains(subjectId)) {
@@ -2864,7 +2863,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
for (String objectId : objectIds) {
dbStat.setString(1, objectId);
dbStat.setString(2, objectType.name());
dbStat.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
setTimestamp(dbStat, 3, new Timestamp(System.currentTimeMillis()));
dbStat.setString(4, grantor);
for (String subjectId : subjectIds) {
if (!filteredSubjects.contains(subjectId)) {
@@ -3381,4 +3380,8 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
public DBPConnectionInformation getInternalDatabaseInformation() {
return database.getMetaDataInfo();
}
private static void setTimestamp(@NotNull PreparedStatement dbStat, int i, @NotNull Timestamp timestamp) throws SQLException {
dbStat.setTimestamp(i, timestamp, Calendar.getInstance(TimeZone.getTimeZone("UTC")));
}
}