| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | |
| | | /** The string representation of the user's DN. */ |
| | | private final String userDNString; |
| | | |
| | |
| | | private long warnedTime = Long.MIN_VALUE; |
| | | |
| | | /** The set of modifications that should be applied to the user's entry. */ |
| | | private LinkedList<Modification> modifications = new LinkedList<>(); |
| | | |
| | | |
| | | private final LinkedList<Modification> modifications = new LinkedList<>(); |
| | | |
| | | /** |
| | | * Creates a new password policy state object with the provided information. |
| | |
| | | this.passwordPolicy = policy; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the value of the specified attribute as a string. |
| | | * |
| | |
| | | { |
| | | Attribute attr = getFirstAttributeNotEmpty(attributeType); |
| | | String stringValue = attr != null ? attr.iterator().next().toString() : null; |
| | | if (stringValue == null) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | if (stringValue != null) |
| | | { |
| | | logger.trace("Returning value %s for user %s", stringValue, userDNString); |
| | | } |
| | | else |
| | | { |
| | | logger.trace("Returning null because attribute %s does not exist in user entry %s", |
| | | attributeType.getNameOrOID(), userDNString); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Returning value %s for user %s", stringValue, userDNString); |
| | | } |
| | | } |
| | | |
| | | return stringValue; |
| | | } |
| | |
| | | return timeValues; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get the password storage scheme used by a given password value. |
| | | * |
| | |
| | | return passwordPolicy; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the time that the password was last changed. |
| | | * |
| | |
| | | return passwordChangedTime; |
| | | } |
| | | |
| | | |
| | | private long getGeneralizedTime0(Entry userEntry, String attrName) throws DirectoryException |
| | | { |
| | | return getGeneralizedTime(userEntry, DirectoryServer.getAttributeType(attrName)); |
| | |
| | | return currentTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the unmodifiable set of values for the password attribute from the user entry. |
| | | * |
| | |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets a new value for the password changed time equal to the current time. |
| | | */ |
| | | /** Sets a new value for the password changed time equal to the current time. */ |
| | | public void setPasswordChangedTime() |
| | | { |
| | | setPasswordChangedTime(currentTime); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sets a new value for the password changed time equal to the specified time. |
| | | * This method should generally only be used for testing purposes, since the variant that uses |
| | |
| | | if (getPasswordChangedTime() != passwordChangedTime) |
| | | { |
| | | this.passwordChangedTime = passwordChangedTime; |
| | | |
| | | String timeValue = GeneralizedTimeSyntax.format(passwordChangedTime); |
| | | Attribute a = Attributes.create(OP_ATTR_PWPOLICY_CHANGED_TIME, timeValue); |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(OP_ATTR_PWPOLICY_CHANGED_TIME, GeneralizedTimeSyntax.format(passwordChangedTime)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Removes the password changed time value from the user's entry. This should only be used for testing |
| | | * purposes, as it can really mess things up if you don't know what you're doing. |
| | | */ |
| | | public void clearPasswordChangedTime() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing password changed time for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing password changed time for user %s", userDNString); |
| | | |
| | | Attribute a = Attributes.empty(OP_ATTR_PWPOLICY_CHANGED_TIME_LC); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | |
| | | clearAttribute(OP_ATTR_PWPOLICY_CHANGED_TIME_LC); |
| | | |
| | | // Fall back to using the entry creation time as the password changed time, if it's defined. |
| | | // Otherwise, use a value of zero. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to indicate whether user account has been administratively disabled. |
| | | * |
| | |
| | | logger.trace("Updating user %s to set the disabled flag to %b", userDNString, isDisabled); |
| | | } |
| | | |
| | | |
| | | if (isDisabled == isDisabled()) |
| | | { |
| | | return; // requested state matches current state |
| | | } |
| | | |
| | | this.isDisabled = ConditionResult.not(this.isDisabled); |
| | | |
| | | if (isDisabled) |
| | | { |
| | | Attribute a = Attributes.create(OP_ATTR_ACCOUNT_DISABLED, String.valueOf(true)); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | } |
| | | else |
| | | { |
| | | // erase |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(OP_ATTR_ACCOUNT_DISABLED), true)); |
| | | } |
| | | replaceAttribute(OP_ATTR_ACCOUNT_DISABLED, isDisabled); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the user's account is currently expired. |
| | | * |
| | |
| | | return isAccountExpired == ConditionResult.TRUE; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the time at which the user's account will expire. |
| | | * |
| | |
| | | return accountExpirationTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets the user's account expiration time to the specified value. |
| | | * |
| | |
| | | else |
| | | { |
| | | String timeStr = GeneralizedTimeSyntax.format(accountExpirationTime); |
| | | |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Setting account expiration time for user %s to %s", userDNString, timeStr); |
| | | } |
| | | logger.trace("Setting account expiration time for user %s to %s", userDNString, timeStr); |
| | | |
| | | this.accountExpirationTime = accountExpirationTime; |
| | | |
| | | Attribute a = Attributes.create(OP_ATTR_ACCOUNT_EXPIRATION_TIME, timeStr); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(OP_ATTR_ACCOUNT_EXPIRATION_TIME, timeStr); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Clears the user's account expiration time. |
| | | */ |
| | | /** Clears the user's account expiration time. */ |
| | | public void clearAccountExpirationTime() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing account expiration time for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing account expiration time for user %s", userDNString); |
| | | |
| | | accountExpirationTime = -1; |
| | | |
| | | String attrName = OP_ATTR_ACCOUNT_EXPIRATION_TIME; |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(attrName), true)); |
| | | clearAttribute(OP_ATTR_ACCOUNT_EXPIRATION_TIME); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of times of failed authentication attempts for the user. If authentication failure |
| | | * time expiration is enabled, and there are expired times in the entry, these times are removed |
| | |
| | | logger.traceException(e, "Error while processing auth failure times for user %s", userDNString); |
| | | |
| | | authFailureTimes = new ArrayList<>(); |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(type), true)); |
| | | clearAttribute(type); |
| | | return authFailureTimes; |
| | | } |
| | | |
| | |
| | | return authFailureTimes; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Updates the set of authentication failure times to include the current time. |
| | | * If the number of failures reaches the policy configuration limit, lock the account. |
| | |
| | | logger.trace("Updating authentication failure times for user %s", userDNString); |
| | | } |
| | | |
| | | |
| | | List<Long> failureTimes = getAuthFailureTimes(); |
| | | long highestFailureTime = computeHighestTime(failureTimes); |
| | | // Update the current policy state |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Explicitly specifies the auth failure times for the associated user. This should generally only be used |
| | | * for testing purposes. Note that it will also set or clear the locked time as appropriate. |
| | |
| | | highestFailureTime = Math.max(l, highestFailureTime); |
| | | builder.add(GeneralizedTimeSyntax.format(l)); |
| | | } |
| | | Attribute a = builder.toAttribute(); |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(builder.toAttribute()); |
| | | |
| | | // Now check to see if there have been sufficient failures to lock the account. |
| | | int lockoutCount = passwordPolicy.getLockoutFailureCount(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to remove any record of previous authentication failure times. |
| | | */ |
| | | /** Updates the user entry to remove any record of previous authentication failure times. */ |
| | | private void clearAuthFailureTimes() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing authentication failure times for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing authentication failure times for user %s", userDNString); |
| | | |
| | | List<Long> failureTimes = getAuthFailureTimes(); |
| | | if (failureTimes.isEmpty()) |
| | | if (!failureTimes.isEmpty()) |
| | | { |
| | | return; |
| | | failureTimes.clear(); // Note: failureTimes != this.authFailureTimes |
| | | clearAttribute(OP_ATTR_PWPOLICY_FAILURE_TIME); |
| | | } |
| | | |
| | | failureTimes.clear(); // Note: failureTimes != this.authFailureTimes |
| | | |
| | | AttributeType type = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_FAILURE_TIME); |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(type), true)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Retrieves the time of an authentication failure lockout for the user. |
| | | * |
| | |
| | | return failureLockedTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | Sets the failure lockout attribute in the entry to the requested time. |
| | | |
| | |
| | | */ |
| | | private void setFailureLockedTime(final long time) |
| | | { |
| | | if (time == getFailureLockedTime()) |
| | | if (time != getFailureLockedTime()) |
| | | { |
| | | return; |
| | | failureLockedTime = time; |
| | | replaceAttribute(OP_ATTR_PWPOLICY_LOCKED_TIME, GeneralizedTimeSyntax.format(failureLockedTime)); |
| | | } |
| | | |
| | | failureLockedTime = time; |
| | | |
| | | AttributeType type = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_LOCKED_TIME); |
| | | Attribute a = Attributes.create(type, GeneralizedTimeSyntax.format(failureLockedTime)); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to remove any record of previous authentication failure lockout. |
| | | */ |
| | | /** Updates the user entry to remove any record of previous authentication failure lockout. */ |
| | | private void clearFailureLockedTime() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | logger.trace("Clearing failure lockout time for user %s.", userDNString); |
| | | |
| | | if (-1L != getFailureLockedTime()) |
| | | { |
| | | logger.trace("Clearing failure lockout time for user %s.", userDNString); |
| | | failureLockedTime = -1L; |
| | | clearAttribute(OP_ATTR_PWPOLICY_LOCKED_TIME); |
| | | } |
| | | |
| | | if (-1L == getFailureLockedTime()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | failureLockedTime = -1L; |
| | | |
| | | AttributeType type = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_LOCKED_TIME); |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(type), true)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the associated user should be considered locked out as a result of too many |
| | | * authentication failures. In the case of an expired lock-out, this routine produces the update |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the length of time in seconds until the user's account is automatically unlocked. |
| | | * This should only be called after calling <CODE>lockedDueToFailures</CODE>. |
| | |
| | | return secondsUntilUnlock < 0 ? -1 : secondsUntilUnlock; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user account to remove any record of a previous lockout due to failed authentications. |
| | | */ |
| | |
| | | clearFailureLockedTime(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the time that the user last authenticated to the Directory Server. |
| | | * |
| | |
| | | return dateFormat.parse(time).getTime(); |
| | | } |
| | | |
| | | /** |
| | | * Updates the user entry to set the current time as the last login time. |
| | | */ |
| | | /** Updates the user entry to set the current time as the last login time. */ |
| | | public void setLastLoginTime() |
| | | { |
| | | setLastLoginTime(currentTime); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to use the specified last login time. This should be used primarily for testing purposes, |
| | | * as the variant that uses the current time should be used most of the time. |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | String existingTimestamp = getValue(type); |
| | | if (existingTimestamp != null && timestamp.equals(existingTimestamp)) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | Attribute a = Attributes.create(type, timestamp); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(Attributes.create(type, timestamp)); |
| | | |
| | | logger.trace("Updated the last login time for user %s to %s", userDNString, timestamp); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Clears the last login time from the user's entry. This should generally be used only for testing purposes. |
| | | */ |
| | | public void clearLastLoginTime() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing last login time for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing last login time for user %s", userDNString); |
| | | |
| | | lastLoginTime = -1; |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(OP_ATTR_LAST_LOGIN_TIME), true)); |
| | | clearAttribute(OP_ATTR_LAST_LOGIN_TIME); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the user's account is currently locked because it has been idle for too long. |
| | | * |
| | |
| | | return isIdleLocked == ConditionResult.TRUE; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the user's password must be changed before any other operation can be performed. |
| | | * |
| | |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e, "Returning true for user %s because an error occurred", userDNString); |
| | | |
| | | mustChangePassword = ConditionResult.TRUE; |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | mustChangePassword = ConditionResult.FALSE; |
| | | logger.trace("Returning %b for user since the attribute \"%s\" is not present in the entry.", |
| | | false, userDNString, OP_ATTR_PWPOLICY_RESET_REQUIRED); |
| | | |
| | | return false; |
| | | } |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to indicate whether the user's password must be changed. |
| | | * |
| | |
| | | return; // requested state matches current state |
| | | } |
| | | |
| | | AttributeType type = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_RESET_REQUIRED); |
| | | this.mustChangePassword = ConditionResult.not(this.mustChangePassword); |
| | | if (mustChangePassword) |
| | | replaceAttribute(OP_ATTR_PWPOLICY_RESET_REQUIRED, mustChangePassword); |
| | | } |
| | | |
| | | private void replaceAttribute(String attrName, boolean newValue) |
| | | { |
| | | if (newValue) |
| | | { |
| | | Attribute a = Attributes.create(type, String.valueOf(true)); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(attrName, String.valueOf(true)); |
| | | } |
| | | else |
| | | { |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(type), true)); |
| | | clearAttribute(attrName); |
| | | } |
| | | } |
| | | |
| | | private void clearAttribute(String attrName) |
| | | { |
| | | clearAttribute(DirectoryServer.getAttributeType(attrName)); |
| | | } |
| | | |
| | | private void clearAttribute(AttributeType type) |
| | | { |
| | | replaceAttribute(Attributes.empty(type)); |
| | | } |
| | | |
| | | private void replaceAttribute(String attrName, String attrValue) |
| | | { |
| | | replaceAttribute(Attributes.create(attrName, attrValue)); |
| | | } |
| | | |
| | | private void replaceAttribute(Attribute a) |
| | | { |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether the user's account is locked because the password has been reset by an administrator |
| | |
| | | // There will never be a warning, and the user's password may be expired. |
| | | shouldWarn = ConditionResult.FALSE; |
| | | isFirstWarning = ConditionResult.FALSE; |
| | | |
| | | if (currentTime > passwordExpirationTime) |
| | | { |
| | | isPasswordExpired = ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | isPasswordExpired = ConditionResult.FALSE; |
| | | } |
| | | isPasswordExpired = ConditionResult.valueOf(currentTime > passwordExpirationTime); |
| | | } |
| | | } |
| | | else |
| | |
| | | mayUseGraceLogin = ConditionResult.FALSE; |
| | | shouldWarn = ConditionResult.FALSE; |
| | | isFirstWarning = ConditionResult.FALSE; |
| | | |
| | | if (passwordExpirationTime < currentTime) |
| | | { |
| | | isPasswordExpired = ConditionResult.TRUE; |
| | | } |
| | | else |
| | | { |
| | | isPasswordExpired = ConditionResult.FALSE; |
| | | } |
| | | isPasswordExpired = ConditionResult.valueOf(passwordExpirationTime < currentTime); |
| | | } |
| | | } |
| | | |
| | |
| | | return passwordExpirationTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the user's password is currently expired. |
| | | * |
| | |
| | | return isPasswordExpired == ConditionResult.TRUE; |
| | | } |
| | | |
| | | private void refreshIfUndefined(ConditionResult cond) |
| | | { |
| | | if (cond == null || cond == ConditionResult.UNDEFINED) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether the user's last password change was within the minimum password age. |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the user may use a grace login if the password is expired and there is at least one |
| | | * grace login remaining. Note that this does not check to see if the user's password is expired, does not |
| | |
| | | return mayUseGraceLogin == ConditionResult.TRUE; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the user should receive a warning notification that the password is about to expire. |
| | | * |
| | |
| | | return shouldWarn == ConditionResult.TRUE; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the warning that the user should receive would be the first warning for the user. |
| | | * |
| | |
| | | return isFirstWarning == ConditionResult.TRUE; |
| | | } |
| | | |
| | | |
| | | private void refreshIfUndefined(ConditionResult cond) |
| | | { |
| | | if (cond == null || cond == ConditionResult.UNDEFINED) |
| | | { |
| | | getPasswordExpirationTime(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Retrieves the length of time in seconds until the user's password expires. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the timestamp for the last required change time that the user complied with. |
| | | * |
| | |
| | | return requiredChangeTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry with a timestamp indicating that the password has been changed in accordance |
| | | * with the require change time. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry with a timestamp indicating that the password has been changed in accordance |
| | | * with the require change time. |
| | |
| | | if (getRequiredChangeTime() != requiredChangeTime) |
| | | { |
| | | this.requiredChangeTime = requiredChangeTime; |
| | | |
| | | String timeValue = GeneralizedTimeSyntax.format(requiredChangeTime); |
| | | Attribute a = Attributes.create(OP_ATTR_PWPOLICY_CHANGED_BY_REQUIRED_TIME, timeValue); |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(OP_ATTR_PWPOLICY_CHANGED_BY_REQUIRED_TIME, GeneralizedTimeSyntax.format(requiredChangeTime)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to remove any timestamp indicating that the password has been changed in accordance |
| | | * with the required change time. |
| | | */ |
| | | public void clearRequiredChangeTime() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing required change time for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing required change time for user %s", userDNString); |
| | | |
| | | this.requiredChangeTime = Long.MIN_VALUE; |
| | | |
| | | String attrName = OP_ATTR_PWPOLICY_CHANGED_BY_REQUIRED_TIME; |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(attrName), true)); |
| | | clearAttribute(OP_ATTR_PWPOLICY_CHANGED_BY_REQUIRED_TIME); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Retrieves the time that the user was first warned about an upcoming expiration. |
| | | * |
| | |
| | | return warnedTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to set the warned time to the current time. |
| | | */ |
| | | /** Updates the user entry to set the warned time to the current time. */ |
| | | public void setWarnedTime() |
| | | { |
| | | setWarnedTime(currentTime); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to set the warned time to the specified time. This method should generally |
| | | * only be used for testing purposes, since the variant that uses the current time is preferred almost |
| | |
| | | } |
| | | |
| | | this.warnedTime = warnedTime; |
| | | |
| | | AttributeType type = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_WARNED_TIME); |
| | | Attribute a = Attributes.create(type, GeneralizedTimeSyntax.createGeneralizedTimeValue(currentTime)); |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(Attributes.create(type, GeneralizedTimeSyntax.createGeneralizedTimeValue(currentTime))); |
| | | |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to clear the warned time. |
| | | */ |
| | | /** Updates the user entry to clear the warned time. */ |
| | | public void clearWarnedTime() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing warned time for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing warned time for user %s", userDNString); |
| | | |
| | | if (getWarnedTime() < 0) |
| | | if (getWarnedTime() >= 0) |
| | | { |
| | | return; |
| | | } |
| | | warnedTime = -1; |
| | | warnedTime = -1; |
| | | clearAttribute(OP_ATTR_PWPOLICY_WARNED_TIME); |
| | | |
| | | String attrName = OP_ATTR_PWPOLICY_WARNED_TIME; |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(attrName), true)); |
| | | |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Cleared the warned time for user %s", userDNString); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the times that the user has authenticated to the server using a grace login. |
| | | * |
| | |
| | | logger.traceException(e, "Error while processing grace login times for user %s", userDNString); |
| | | |
| | | graceLoginTimes = new ArrayList<>(); |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(type), true)); |
| | | clearAttribute(type); |
| | | } |
| | | } |
| | | |
| | |
| | | return graceLoginTimes; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the number of grace logins that the user has left. |
| | | * |
| | |
| | | return maxGraceLogins - theGraceLoginTimes.size(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the set of grace login times for the user to include the current time. |
| | | */ |
| | | /** Updates the set of grace login times for the user to include the current time. */ |
| | | public void updateGraceLoginTimes() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | |
| | | return highestTime; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Specifies the set of grace login use times for the associated user. If the provided list is empty |
| | | * or {@code null}, then the set will be cleared. |
| | |
| | | { |
| | | builder.add(GeneralizedTimeSyntax.format(l)); |
| | | } |
| | | Attribute a = builder.toAttribute(); |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, a, true)); |
| | | replaceAttribute(builder.toAttribute()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Updates the user entry to remove any record of previous grace logins. |
| | | */ |
| | | /** Updates the user entry to remove any record of previous grace logins. */ |
| | | public void clearGraceLoginTimes() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing grace login times for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing grace login times for user %s", userDNString); |
| | | |
| | | List<Long> graceTimes = getGraceLoginTimes(); |
| | | if (graceTimes.isEmpty()) |
| | | if (!graceTimes.isEmpty()) |
| | | { |
| | | return; |
| | | graceTimes.clear(); // graceTimes == this.graceLoginTimes |
| | | clearAttribute(OP_ATTR_PWPOLICY_GRACE_LOGIN_TIME); |
| | | } |
| | | graceTimes.clear(); // graceTimes == this.graceLoginTimes |
| | | |
| | | AttributeType type = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_GRACE_LOGIN_TIME); |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(type), true)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Retrieves a list of the clear-text passwords for the user. If the user does not have any passwords |
| | | * in the clear, then the list will be empty. |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get the broken-down components of the given password value. |
| | | * |
| | |
| | | : UserPasswordSyntax.isEncoded(passwordValue); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Encodes the provided password using the default storage schemes (using the appropriate syntax for the |
| | | * password attribute). |
| | |
| | | return encodedPasswords; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided password appears to be acceptable according to the password validators. |
| | | * |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Performs any processing that may be necessary to remove deprecated storage schemes from the user's entry |
| | | * that match the provided password and re-encodes them using the default schemes. |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | AttributeType type = passwordPolicy.getPasswordAttribute(); |
| | | List<Attribute> attrList = userEntry.getAttribute(type); |
| | | if (attrList.isEmpty()) |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | HashSet<String> existingDefaultSchemes = new HashSet<>(); |
| | | LinkedHashSet<ByteString> removedValues = new LinkedHashSet<>(); |
| | | LinkedHashSet<ByteString> updatedValues = new LinkedHashSet<>(); |
| | |
| | | || passwordPolicy.getPasswordHistoryDuration() > 0; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided password is equal to any of the current passwords, |
| | | * or any of the passwords in the history. |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets a sorted list of the password history values contained in the user's entry. |
| | | * The values will be sorted by timestamp. |
| | |
| | | return historyMap; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the provided password matches the given history value. |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds the provided password to the password history. If appropriate, one or more old passwords may be |
| | | * evicted from the list if the total size would exceed the configured count, or if passwords are older |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | // Get a sorted list of the existing values to see if there are any that should be removed. |
| | | LinkedList<Attribute> removeAttrs = new LinkedList<>(); |
| | | TreeMap<Long, ByteString> historyMap = getSortedHistoryValues(removeAttrs); |
| | | |
| | | |
| | | // If there is a maximum number of values to retain and we would be over the limit with the new value, |
| | | // then get rid of enough values (oldest first) to satisfy the count. |
| | | AttributeType historyType = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_HISTORY_LC); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // If there is a maximum duration, then get rid of any values that would be over the duration. |
| | | long historyDuration = passwordPolicy.getPasswordHistoryDuration(); |
| | | if (historyDuration > 0L) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // At this point, we can add the new value. However, we want to make sure that its timestamp |
| | | // (which is the current time) doesn't conflict with any value already in the list. If there is a conflict, |
| | | // then simply add one to it until we don't have any more conflicts. |
| | |
| | | logger.trace("Going to add history value " + newHistStr); |
| | | } |
| | | |
| | | |
| | | // Apply the changes, either by adding modifications or by directly updating the entry. |
| | | for (Attribute a : removeAttrs) |
| | | { |
| | |
| | | return historyValues.toArray(new String[historyValues.size()]); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Clears the password history state information for the user. This is only intended for testing purposes. |
| | | */ |
| | | public void clearPasswordHistory() |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("Clearing password history for user %s", userDNString); |
| | | } |
| | | logger.trace("Clearing password history for user %s", userDNString); |
| | | |
| | | modifications.add(new Modification(ModificationType.REPLACE, Attributes.empty(OP_ATTR_PWPOLICY_HISTORY_LC), true)); |
| | | clearAttribute(OP_ATTR_PWPOLICY_HISTORY_LC); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Generates a new password for the user. |
| | | * |
| | |
| | | return generator.generatePassword(userEntry); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Generates an account status notification for this user. |
| | | * |
| | |
| | | new AccountStatusNotification(notificationType, userEntry, message, notificationProperties)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Generates an account status notification for this user. |
| | | * |
| | | * @param notification The account status notification that should be generated. |
| | | */ |
| | | public void generateAccountStatusNotification(AccountStatusNotification notification) |
| | | private void generateAccountStatusNotification(AccountStatusNotification notification) |
| | | { |
| | | Collection<AccountStatusNotificationHandler<?>> handlers = passwordPolicy.getAccountStatusNotificationHandlers(); |
| | | for (AccountStatusNotificationHandler<?> handler : handlers) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of modifications that correspond to changes made in password policy processing |
| | | * that may need to be applied to the user entry. |
| | |
| | | return modifications; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void finalizeStateAfterBind() |
| | | throws DirectoryException |