GUACAMOLE-36: Clarify function naming regarding a user's current (at time of query) password record.

This commit is contained in:
Michael Jumper
2017-01-05 13:36:58 -08:00
parent 4a1ae7f292
commit 52dda6b55f
3 changed files with 19 additions and 18 deletions

View File

@@ -227,13 +227,13 @@ public class PasswordPolicyService {
private long getPasswordAge(ModeledUser user) {
// If no password was set, then no time has elapsed
PasswordRecordModel previousPassword = user.getPreviousPassword();
if (previousPassword == null)
PasswordRecordModel passwordRecord = user.getPasswordRecord();
if (passwordRecord == null)
return 0;
// Pull both current time and the time the password was last reset
long currentTime = System.currentTimeMillis();
long lastResetTime = previousPassword.getPasswordDate().getTime();
long lastResetTime = passwordRecord.getPasswordDate().getTime();
// Calculate the number of days elapsed since the password was last reset
return TimeUnit.DAYS.convert(currentTime - lastResetTime, TimeUnit.MILLISECONDS);
@@ -306,12 +306,13 @@ public class PasswordPolicyService {
* user is limited by the password policy.
*
* @param user
* The user whose previous password should be recorded.
* The user whose password should be recorded within the password
* history.
*
* @throws GuacamoleException
* If the password policy cannot be parsed.
*/
public void recordPreviousPassword(ModeledUser user)
public void recordPassword(ModeledUser user)
throws GuacamoleException {
// Retrieve password policy from environment
@@ -323,7 +324,7 @@ public class PasswordPolicyService {
return;
// Store previous password in history
passwordRecordMapper.insert(user.getPreviousPassword(), historySize);
passwordRecordMapper.insert(user.getPasswordRecord(), historySize);
}

View File

@@ -192,7 +192,7 @@ public class ModeledUser extends ModeledDirectoryObject<UserModel> implements Us
* The data associated with this user's password at the time this user was
* queried. If the user is new, this will be null.
*/
private PasswordRecordModel previousPassword = null;
private PasswordRecordModel passwordRecord = null;
/**
* Creates a new, empty ModeledUser.
@@ -207,7 +207,7 @@ public class ModeledUser extends ModeledDirectoryObject<UserModel> implements Us
// Store previous password, if any
if (model.getPasswordHash() != null)
this.previousPassword = new PasswordRecordModel(model);
this.passwordRecord = new PasswordRecordModel(model);
}
@@ -245,19 +245,19 @@ public class ModeledUser extends ModeledDirectoryObject<UserModel> implements Us
}
/**
* Returns the data associated with this user's previous password as a
* password record. If the user is new, this will be null. Unlike the other
* password-related functions of UserModel, this data returned by this
* function is historical and is unaffected by calls to setPassword(). It
* will always return the values stored in the database at the time this
* user was queried.
* Returns the this user's current password record. If the user is new, this
* will be null. Note that this may represent a different password than what
* is returned by getPassword(): unlike the other password-related functions
* of ModeledUser, the data returned by this function is historical and is
* unaffected by calls to setPassword(). It will always return the values
* stored in the database at the time this user was queried.
*
* @return
* The data associated with this user's previous password, or null if
* The historical data associated with this user's password, or null if
* the user is new.
*/
public PasswordRecordModel getPreviousPassword() {
return previousPassword;
public PasswordRecordModel getPasswordRecord() {
return passwordRecord;
}
/**

View File

@@ -243,7 +243,7 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
passwordPolicyService.verifyPassword(object.getIdentifier(), object.getPassword());
// Store previous password in history
passwordPolicyService.recordPreviousPassword(object);
passwordPolicyService.recordPassword(object);
}