mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-19 02:20:47 +08:00
dbeaver/pro#9482 add last auth date for users (#4389)
This commit is contained in:
@@ -114,4 +114,9 @@ public class WebUser {
|
||||
public String getDisableReason() {
|
||||
return user.getDisableReason();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Instant getLastLoginTime() {
|
||||
return user.getLastLoginTime();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ type AdminUserInfo {
|
||||
disabledBy: String @since(version: "25.0.2")
|
||||
"Reason why the user was disabled"
|
||||
disableReason: String @since(version: "25.0.2")
|
||||
"Date of the user's last successful login"
|
||||
lastLoginTime: DateTime @since(version: "26.1.1")
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -142,4 +142,9 @@ public class AdminUserInfo {
|
||||
public String getDisableReason() {
|
||||
return user.getDisableReason();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLastLoginTime() {
|
||||
return user.getLastLoginTime() == null ? null : CBModelConstants.ISO_DATE_FORMAT.format(user.getLastLoginTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ CREATE TABLE {table_prefix}CB_USER
|
||||
CHANGE_DATE TIMESTAMP NULL,
|
||||
DISABLED_BY VARCHAR(128) NULL,
|
||||
DISABLE_REASON VARCHAR(128) NULL,
|
||||
LAST_LOGIN_TIME TIMESTAMP NULL,
|
||||
|
||||
PRIMARY KEY (USER_ID),
|
||||
FOREIGN KEY (USER_ID) REFERENCES {table_prefix}CB_AUTH_SUBJECT (SUBJECT_ID) ON DELETE CASCADE,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE {table_prefix}CB_USER ADD LAST_LOGIN_TIME TIMESTAMP NULL;
|
||||
+20
-3
@@ -709,7 +709,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
|
||||
SMUser user;
|
||||
try (PreparedStatement dbStat = dbCon.prepareStatement(
|
||||
"""
|
||||
SELECT U.USER_ID,U.IS_ACTIVE,U.DEFAULT_AUTH_ROLE,S.IS_SECRET_STORAGE,U.CHANGE_DATE,U.DISABLED_BY,U.DISABLE_REASON
|
||||
SELECT U.USER_ID,U.IS_ACTIVE,U.DEFAULT_AUTH_ROLE,S.IS_SECRET_STORAGE,U.CHANGE_DATE,U.DISABLED_BY,U.DISABLE_REASON,U.LAST_LOGIN_TIME
|
||||
FROM {table_prefix}CB_USER U, {table_prefix}CB_AUTH_SUBJECT S
|
||||
WHERE U.USER_ID=? AND U.USER_ID=S.SUBJECT_ID""")
|
||||
) {
|
||||
@@ -783,7 +783,7 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
|
||||
// Read users
|
||||
try (PreparedStatement dbStat = dbCon.prepareStatement(
|
||||
"SELECT USER_ID,IS_ACTIVE,DEFAULT_AUTH_ROLE,CHANGE_DATE,DISABLED_BY,"
|
||||
+ "DISABLE_REASON FROM {table_prefix}CB_USER"
|
||||
+ "DISABLE_REASON,LAST_LOGIN_TIME FROM {table_prefix}CB_USER"
|
||||
+ buildUsersFilter(filter) + "\nORDER BY USER_ID " + getOffsetLimitPart(filter))) {
|
||||
setUsersFilterValues(dbStat, filter, 1);
|
||||
|
||||
@@ -1484,11 +1484,23 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
|
||||
);
|
||||
}
|
||||
|
||||
private void updateUserLastLoginTime(@NotNull Connection dbCon, @NotNull String userId) throws SQLException {
|
||||
try (PreparedStatement dbStat = dbCon.prepareStatement(
|
||||
"UPDATE {table_prefix}CB_USER SET LAST_LOGIN_TIME=? WHERE USER_ID=?"
|
||||
)) {
|
||||
dbStat.setTimestamp(1, Timestamp.from(Instant.now()));
|
||||
dbStat.setString(2, userId);
|
||||
dbStat.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SMUser fetchUser(ResultSet dbResult, boolean checkSecretStorage) throws SQLException {
|
||||
Timestamp timestamp = dbResult.getTimestamp("CHANGE_DATE");
|
||||
Instant disableDate = timestamp != null ? timestamp.toInstant() : null;
|
||||
return new SMUser(
|
||||
Timestamp lastLoginTimestamp = dbResult.getTimestamp("LAST_LOGIN_TIME");
|
||||
Instant lastLoginTime = lastLoginTimestamp != null ? lastLoginTimestamp.toInstant() : null;
|
||||
SMUser user = new SMUser(
|
||||
dbResult.getString("USER_ID"),
|
||||
stringToBoolean(dbResult.getString("IS_ACTIVE")),
|
||||
dbResult.getString("DEFAULT_AUTH_ROLE"),
|
||||
@@ -1497,6 +1509,8 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
|
||||
dbResult.getString("DISABLED_BY"),
|
||||
dbResult.getString("DISABLE_REASON")
|
||||
);
|
||||
user.setLastLoginTime(lastLoginTime);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2643,6 +2657,9 @@ public class CBEmbeddedSecurityController<T extends ServletAuthApplication>
|
||||
permissions = new SMAuthPermissions(
|
||||
activeUserId, smSessionId, getUserPermissions(activeUserId, tokenAuthRole)
|
||||
);
|
||||
if (CommonUtils.isNotEmpty(activeUserId)) {
|
||||
updateUserLastLoginTime(dbCon, activeUserId);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ import javax.sql.DataSource;
|
||||
public class CBDatabase extends InternalDB<WebDatabaseConfig> {
|
||||
private static final Log log = Log.getLog(CBDatabase.class);
|
||||
|
||||
private static final int CURRENT_SCHEMA_VERSION = 28;
|
||||
private static final int CURRENT_SCHEMA_VERSION = 29;
|
||||
private static final String SCHEMA_ID = "CB_CE";
|
||||
|
||||
private static final SQLSchemaConfig SCHEMA_CREATE_CONFIG = new SQLSchemaConfig(
|
||||
|
||||
Reference in New Issue
Block a user