Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaFilipozzi committed Apr 10, 2024
1 parent 5875133 commit 384df19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ private void disableUsers(KeycloakSession session) {

PasswordPolicy passwordPolicy = realm.getPasswordPolicy();
if (passwordPolicy == null
|| !passwordPolicy.getPolicies().contains("disable-users-password-policy")) {
|| !passwordPolicy.getPolicies().contains("disable-users-password-policy")
|| !passwordPolicy.getPolicies().contains(PasswordPolicy.FORCE_EXPIRED_ID)
|| passwordPolicy.getDaysToExpirePassword() < 0) {
LOG.debugf(
"realm='%s' does not have 'Disable Users' password policy set",
"realm='%s' does not have 'Disable Users' and/or 'Expire Password' password policies set",
realm.getName());
return;
}
Expand All @@ -102,6 +104,8 @@ private void disableUsers(KeycloakSession session) {

long gracePeriodMillis = gracePeriodDays * DAYS_TO_MILLIS;

long expirePasswordMillis = passwordPolicy.getDaysToExpirePassword() * DAYS_TO_MILLIS;

LOG.infof(
"checking realm='%s' for expired passwords or inactive accounts exceeding %d day(s)",
realm.getName(), gracePeriodDays);
Expand All @@ -112,7 +116,7 @@ private void disableUsers(KeycloakSession session) {
passwordCredentialProvider.getPassword(realm, user);
if (credential != null
&& ((currentTimeMillis - credential.getCreatedDate())
> gracePeriodMillis)) {
> (gracePeriodMillis + expirePasswordMillis))) {
LOG.warnf(
"disabled realm='%s' user='%s' userId='%s' for expired password",
realm.getName(), user.getUsername(), user.getId());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</scm>

<properties>
<revision>1.8.0</revision>
<revision>1.8.1</revision>
<github.account>LucaFilipozzi</github.account>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<keycloak.version>18.0.2</keycloak.version>
Expand Down

0 comments on commit 384df19

Please sign in to comment.