mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-36: Record and maintain password history.
This commit is contained in:
@@ -72,6 +72,20 @@ public interface PasswordPolicy {
|
||||
*/
|
||||
int getMaximumAge() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns the number of previous passwords remembered for each user. If
|
||||
* greater than zero, users will be prohibited from reusing their past
|
||||
* passwords.
|
||||
*
|
||||
* @return
|
||||
* The number of previous passwords remembered for each user.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the password history size cannot be parsed from
|
||||
* guacamole.properties.
|
||||
*/
|
||||
int getHistorySize() throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns whether both uppercase and lowercase characters must be present
|
||||
* in new passwords. If true, passwords which do not have at least one
|
||||
|
@@ -26,6 +26,7 @@ import java.util.regex.Pattern;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.auth.jdbc.JDBCEnvironment;
|
||||
import org.apache.guacamole.auth.jdbc.user.ModeledUser;
|
||||
import org.apache.guacamole.auth.jdbc.user.PasswordRecordMapper;
|
||||
import org.apache.guacamole.auth.jdbc.user.PasswordRecordModel;
|
||||
|
||||
/**
|
||||
@@ -42,6 +43,12 @@ public class PasswordPolicyService {
|
||||
@Inject
|
||||
private JDBCEnvironment environment;
|
||||
|
||||
/**
|
||||
* Mapper for creating/retrieving previously-set passwords.
|
||||
*/
|
||||
@Inject
|
||||
private PasswordRecordMapper passwordRecordMapper;
|
||||
|
||||
/**
|
||||
* Regular expression which matches only if the string contains at least one
|
||||
* lowercase character.
|
||||
@@ -235,4 +242,32 @@ public class PasswordPolicyService {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the password that was associated with the given user at the time
|
||||
* the user was queried, such that future attempts to set that same password
|
||||
* for that user will be denied. The number of passwords remembered for each
|
||||
* user is limited by the password policy.
|
||||
*
|
||||
* @param user
|
||||
* The user whose previous password should be recorded.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the password policy cannot be parsed.
|
||||
*/
|
||||
public void recordPreviousPassword(ModeledUser user)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Retrieve password policy from environment
|
||||
PasswordPolicy policy = environment.getPasswordPolicy();
|
||||
|
||||
// Nothing to do if history is not being recorded
|
||||
int historySize = policy.getHistorySize();
|
||||
if (historySize <= 0)
|
||||
return;
|
||||
|
||||
// Store previous password in history
|
||||
passwordRecordMapper.insert(user.getPreviousPassword(), historySize);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -242,6 +242,9 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
||||
// Always verify password complexity
|
||||
passwordPolicyService.verifyPassword(object.getIdentifier(), object.getPassword());
|
||||
|
||||
// Store previous password in history
|
||||
passwordPolicyService.recordPreviousPassword(object);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user