diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java index 983905588..48fdf97cf 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCAuthenticationProviderService.java @@ -108,7 +108,7 @@ public class JDBCAuthenticationProviderService implements AuthenticationProvider // Update password if password is expired UserModel userModel = user.getModel(); - if (userModel.isExpired() || passwordPolicyService.isPasswordExpired(userModel)) + if (userModel.isExpired() || passwordPolicyService.isPasswordExpired(user)) userService.resetExpiredPassword(user, authenticatedUser.getCredentials()); // Link to user context diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/security/PasswordPolicyService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/security/PasswordPolicyService.java index 23fc367ba..a47c03894 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/security/PasswordPolicyService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/security/PasswordPolicyService.java @@ -25,7 +25,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.auth.jdbc.JDBCEnvironment; -import org.apache.guacamole.auth.jdbc.user.UserModel; +import org.apache.guacamole.auth.jdbc.user.ModeledUser; /** * Service which verifies compliance with the password policy configured via @@ -159,11 +159,11 @@ public class PasswordPolicyService { * @return * The age of the given user's password, in days. */ - private long getPasswordAge(UserModel user) { + private long getPasswordAge(ModeledUser user) { // Pull both current time and the time the password was last reset long currentTime = System.currentTimeMillis(); - long lastResetTime = user.getPasswordDate().getTime(); + long lastResetTime = user.getPreviousPasswordDate().getTime(); // Calculate the number of days elapsed since the password was last reset return TimeUnit.DAYS.convert(currentTime - lastResetTime, TimeUnit.MILLISECONDS); @@ -183,7 +183,7 @@ public class PasswordPolicyService { * policy, or of the password policy cannot be parsed from * guacamole.properties. */ - public void verifyPasswordAge(UserModel user) throws GuacamoleException { + public void verifyPasswordAge(ModeledUser user) throws GuacamoleException { // Retrieve password policy from environment PasswordPolicy policy = environment.getPasswordPolicy(); @@ -213,7 +213,7 @@ public class PasswordPolicyService { * @throws GuacamoleException * If the password policy cannot be parsed. */ - public boolean isPasswordExpired(UserModel user) + public boolean isPasswordExpired(ModeledUser user) throws GuacamoleException { // Retrieve password policy from environment diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java index 1353415e8..2f1e58382 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java @@ -22,6 +22,7 @@ package org.apache.guacamole.auth.jdbc.user; import com.google.inject.Inject; import java.sql.Date; import java.sql.Time; +import java.sql.Timestamp; import java.text.ParseException; import java.util.Arrays; import java.util.Calendar; @@ -186,6 +187,12 @@ public class ModeledUser extends ModeledDirectoryObject implements Us * user was retrieved from the database, this will be null. */ private String password = null; + + /** + * The time and date that this user's password was previously set (prior to + * being queried). If the user is new, this will be null. + */ + private Timestamp previousPasswordDate = null; /** * Creates a new, empty ModeledUser. @@ -193,6 +200,12 @@ public class ModeledUser extends ModeledDirectoryObject implements Us public ModeledUser() { } + @Override + public void setModel(UserModel model) { + super.setModel(model); + this.previousPasswordDate = model.getPasswordDate(); + } + @Override public String getPassword() { return password; @@ -222,6 +235,24 @@ public class ModeledUser extends ModeledDirectoryObject implements Us userModel.setPasswordHash(hash); } + userModel.setPasswordDate(new Timestamp(System.currentTimeMillis())); + + } + + /** + * Returns the time and date that this user's password was previously set. + * If the user is new, this will be null. Unlike getPasswordDate() of + * UserModel (which is updated automatically along with the password salt + * and hash whenever setPassword() is invoked), this value is unaffected by + * calls to setPassword(), and will always be the value stored in the + * database at the time this user was queried. + * + * @return + * The time and date that this user's password was previously set, or + * null if the user is new. + */ + public Timestamp getPreviousPasswordDate() { + return previousPasswordDate; } /** diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java index 25dfa327f..5bfd665ad 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java @@ -21,7 +21,6 @@ package org.apache.guacamole.auth.jdbc.user; import com.google.inject.Inject; import com.google.inject.Provider; -import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -211,9 +210,6 @@ public class UserService extends ModeledDirectoryObjectService