invalidate existing sessions on password change

This commit is contained in:
Athou
2026-11-02 09:43:37 +01:00
parent ca4642f7c9
commit 0c280c4dc4
16 changed files with 370 additions and 26 deletions

View File

@@ -42,6 +42,9 @@ public class User extends AbstractModel {
@Column(nullable = false)
private boolean disabled;
@Column(nullable = false)
private int sessionVersion;
@Column private Instant lastLogin;
@Column private Instant created;

View File

@@ -155,6 +155,17 @@ public class UserService {
userDAO.delete(user);
}
public void changePassword(User user, String password) {
user.setPassword(encryptionService.getEncryptedPassword(password, user.getSalt()));
userDAO.merge(user);
invalidateSessions(user);
}
public void invalidateSessions(User user) {
user.setSessionVersion(user.getSessionVersion() + 1);
}
public String generateApiKey(User user) {
byte[] key =
encryptionService.getEncryptedPassword(