| | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.server.admin.std.meta.PasswordPolicyCfgDefn; |
| | | import org.opends.server.admin.std.server.PasswordValidatorCfg; |
| | | import org.opends.server.api.AccountStatusNotificationHandler; |
| | | import org.opends.server.api.PasswordGenerator; |
| | | import org.opends.server.api.PasswordStorageScheme; |
| | |
| | | * This class provides a data structure for holding password policy state |
| | | * information for a user account. |
| | | */ |
| | | public class PasswordPolicyState |
| | | public final class PasswordPolicyState |
| | | { |
| | | /** |
| | | * The tracer object for the debug logger. |
| | |
| | | } |
| | | } |
| | | |
| | | PasswordPolicy policy = DirectoryServer.getPasswordPolicy(subentryDN); |
| | | PasswordPolicy policy = (PasswordPolicy) DirectoryServer |
| | | .getAuthenticationPolicy(subentryDN); |
| | | if (policy == null) |
| | | { |
| | | if (debugEnabled()) |
| | |
| | | { |
| | | if (subentry.getEntry().isPasswordPolicySubentry()) |
| | | { |
| | | PasswordPolicy policy = DirectoryServer.getPasswordPolicy( |
| | | subentry.getDN()); |
| | | PasswordPolicy policy = (PasswordPolicy) DirectoryServer |
| | | .getAuthenticationPolicy(subentry.getDN()); |
| | | if (policy == null) |
| | | { |
| | | // This shouldnt happen but if it does debug log |
| | |
| | | // FIXME: the only getter responsible for a state attribute (pwdReset) that |
| | | // considers the policy before checking the entry for the presence of the |
| | | // attribute. |
| | | if (! (passwordPolicy.allowUserPasswordChanges() |
| | | && (passwordPolicy.forceChangeOnAdd() |
| | | || passwordPolicy.forceChangeOnReset()))) |
| | | if (! (passwordPolicy.isAllowUserPasswordChanges() |
| | | && (passwordPolicy.isForceChangeOnAdd() |
| | | || passwordPolicy.isForceChangeOnReset()))) |
| | | { |
| | | mustChangePassword = ConditionResult.FALSE; |
| | | if (debugEnabled()) |
| | |
| | | { |
| | | // This feature is reponsible for neither a state field nor an entry state |
| | | // attribute. |
| | | if (passwordPolicy.getMaximumPasswordResetAge() <= 0) |
| | | if (passwordPolicy.getMaxPasswordResetAge() <= 0L) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | |
| | | } |
| | | |
| | | long maxResetTime = passwordChangedTime + |
| | | (1000L * passwordPolicy.getMaximumPasswordResetAge()); |
| | | (1000L * passwordPolicy.getMaxPasswordResetAge()); |
| | | boolean locked = (maxResetTime < currentTime); |
| | | |
| | | if (debugEnabled()) |
| | |
| | | |
| | | boolean checkWarning = false; |
| | | |
| | | int maxAge = passwordPolicy.getMaximumPasswordAge(); |
| | | if (maxAge > 0) |
| | | long maxAge = passwordPolicy.getMaxPasswordAge(); |
| | | if (maxAge > 0L) |
| | | { |
| | | long expTime = passwordChangedTime + (1000L*maxAge); |
| | | if (expTime < passwordExpirationTime) |
| | |
| | | } |
| | | } |
| | | |
| | | int maxResetAge = passwordPolicy.getMaximumPasswordResetAge(); |
| | | if (mustChangePassword() && (maxResetAge > 0)) |
| | | long maxResetAge = passwordPolicy.getMaxPasswordResetAge(); |
| | | if (mustChangePassword() && (maxResetAge > 0L)) |
| | | { |
| | | long expTime = passwordChangedTime + (1000L*maxResetAge); |
| | | if (expTime < passwordExpirationTime) |
| | |
| | | { |
| | | mayUseGraceLogin = ConditionResult.TRUE; |
| | | |
| | | int warningInterval = passwordPolicy.getWarningInterval(); |
| | | if (warningInterval > 0) |
| | | long warningInterval = passwordPolicy |
| | | .getPasswordExpirationWarningInterval(); |
| | | if (warningInterval > 0L) |
| | | { |
| | | long shouldWarnTime = |
| | | passwordExpirationTime - (warningInterval*1000L); |
| | |
| | | isFirstWarning = ConditionResult.TRUE; |
| | | setWarnedTime(); |
| | | |
| | | if (! passwordPolicy.expirePasswordsWithoutWarning()) |
| | | if (! passwordPolicy.isExpirePasswordsWithoutWarning()) |
| | | { |
| | | passwordExpirationTime = |
| | | currentTime + (warningInterval*1000L); |
| | |
| | | { |
| | | isFirstWarning = ConditionResult.FALSE; |
| | | |
| | | if (! passwordPolicy.expirePasswordsWithoutWarning()) |
| | | if (! passwordPolicy.isExpirePasswordsWithoutWarning()) |
| | | { |
| | | passwordExpirationTime = warnedTime + (warningInterval*1000L); |
| | | } |
| | |
| | | { |
| | | // The expiration time has passed, but we may not actually be |
| | | // expired if the user has not yet seen a warning. |
| | | if (passwordPolicy.expirePasswordsWithoutWarning()) |
| | | if (passwordPolicy.isExpirePasswordsWithoutWarning()) |
| | | { |
| | | shouldWarn = ConditionResult.FALSE; |
| | | isFirstWarning = ConditionResult.FALSE; |
| | |
| | | { |
| | | // This feature is reponsible for neither a state field nor entry state |
| | | // attribute. |
| | | int minAge = passwordPolicy.getMinimumPasswordAge(); |
| | | if (minAge <= 0) |
| | | long minAge = passwordPolicy.getMinPasswordAge(); |
| | | if (minAge <= 0L) |
| | | { |
| | | // There is no minimum age, so the user isn't in it. |
| | | if (debugEnabled()) |
| | |
| | | |
| | | for (Attribute a : attrList) |
| | | { |
| | | boolean usesAuthPasswordSyntax = passwordPolicy.usesAuthPasswordSyntax(); |
| | | boolean usesAuthPasswordSyntax = passwordPolicy.isAuthPasswordSyntax(); |
| | | |
| | | for (AttributeValue v : a) |
| | | { |
| | |
| | | |
| | | for (Attribute a : attrList) |
| | | { |
| | | boolean usesAuthPasswordSyntax = passwordPolicy.usesAuthPasswordSyntax(); |
| | | boolean usesAuthPasswordSyntax = passwordPolicy.isAuthPasswordSyntax(); |
| | | |
| | | for (AttributeValue v : a) |
| | | { |
| | |
| | | */ |
| | | public boolean passwordIsPreEncoded(ByteString passwordValue) |
| | | { |
| | | if (passwordPolicy.usesAuthPasswordSyntax()) |
| | | if (passwordPolicy.isAuthPasswordSyntax()) |
| | | { |
| | | return AuthPasswordSyntax.isEncoded(passwordValue); |
| | | } |
| | |
| | | throws DirectoryException |
| | | { |
| | | List<PasswordStorageScheme<?>> schemes = |
| | | passwordPolicy.getDefaultStorageSchemes(); |
| | | passwordPolicy.getDefaultPasswordStorageSchemes(); |
| | | List<ByteString> encodedPasswords = |
| | | new ArrayList<ByteString>(schemes.size()); |
| | | |
| | | if (passwordPolicy.usesAuthPasswordSyntax()) |
| | | if (passwordPolicy.isAuthPasswordSyntax()) |
| | | { |
| | | for (PasswordStorageScheme<?> s : schemes) |
| | | { |
| | |
| | | * <CODE>false</CODE> if it is not. |
| | | */ |
| | | public boolean passwordIsAcceptable(Operation operation, Entry userEntry, |
| | | ByteString newPassword, |
| | | Set<ByteString> currentPasswords, |
| | | MessageBuilder invalidReason) |
| | | ByteString newPassword, Set<ByteString> currentPasswords, |
| | | MessageBuilder invalidReason) |
| | | { |
| | | for (DN validatorDN : passwordPolicy.getPasswordValidators().keySet()) |
| | | for (PasswordValidator<?> validator : passwordPolicy |
| | | .getPasswordValidators()) |
| | | { |
| | | PasswordValidator<? extends PasswordValidatorCfg> validator = |
| | | passwordPolicy.getPasswordValidators().get(validatorDN); |
| | | |
| | | if (! validator.passwordIsAcceptable(newPassword, currentPasswords, |
| | | operation, userEntry, invalidReason)) |
| | | if (!validator.passwordIsAcceptable(newPassword, currentPasswords, |
| | | operation, userEntry, invalidReason)) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugInfo("The password provided for user %s failed " + |
| | | "the %s password validator.", |
| | | userDNString, validatorDN.toString()); |
| | | TRACER.debugInfo("The password provided for user %s failed " |
| | | + "validation: %s", userDNString, invalidReason.toString()); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugInfo("The password provided for user %s passed " + |
| | | "the %s password validator.", |
| | | userDNString, validatorDN.toString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | public void handleDeprecatedStorageSchemes(ByteString password) |
| | | { |
| | | if (passwordPolicy.getDefaultStorageSchemes().isEmpty()) |
| | | if (passwordPolicy.getDefaultPasswordStorageSchemes().isEmpty()) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | |
| | | LinkedHashSet<AttributeValue> updatedValues = |
| | | new LinkedHashSet<AttributeValue>(); |
| | | |
| | | boolean usesAuthPasswordSyntax = passwordPolicy.usesAuthPasswordSyntax(); |
| | | boolean usesAuthPasswordSyntax = passwordPolicy.isAuthPasswordSyntax(); |
| | | |
| | | for (Attribute a : attrList) |
| | | { |
| | |
| | | ByteString.valueOf(pwComponents[1].toString())); |
| | | if (passwordMatches) |
| | | { |
| | | if (passwordPolicy.isDefaultStorageScheme(schemeName)) |
| | | if (passwordPolicy.isDefaultPasswordStorageScheme(schemeName)) |
| | | { |
| | | existingDefaultSchemes.add(schemeName); |
| | | updatedValues.add(v); |
| | | } |
| | | else if (passwordPolicy.isDeprecatedStorageScheme(schemeName)) |
| | | else if (passwordPolicy |
| | | .isDeprecatedPasswordStorageScheme(schemeName)) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | |
| | | LinkedHashSet<AttributeValue> addedValues = new |
| | | LinkedHashSet<AttributeValue>(); |
| | | for (PasswordStorageScheme<?> s : |
| | | passwordPolicy.getDefaultStorageSchemes()) |
| | | passwordPolicy.getDefaultPasswordStorageSchemes()) |
| | | { |
| | | if (! existingDefaultSchemes.contains( |
| | | toLowerCase(s.getStorageSchemeName()))) |
| | |
| | | } |
| | | } |
| | | |
| | | int historyDuration = passwordPolicy.getPasswordHistoryDuration(); |
| | | if (historyDuration > 0) |
| | | long historyDuration = passwordPolicy.getPasswordHistoryDuration(); |
| | | if (historyDuration > 0L) |
| | | { |
| | | long retainDate = currentTime - (1000 * historyDuration); |
| | | Iterator<Long> iterator = historyMap.keySet().iterator(); |
| | |
| | | |
| | | // If there is a maximum duration, then get rid of any values that would be |
| | | // over the duration. |
| | | int historyDuration = passwordPolicy.getPasswordHistoryDuration(); |
| | | if (historyDuration > 0) |
| | | long historyDuration = passwordPolicy.getPasswordHistoryDuration(); |
| | | if (historyDuration > 0L) |
| | | { |
| | | long minAgeToKeep = currentTime - (1000L * historyDuration); |
| | | Iterator<Long> iterator = historyMap.keySet().iterator(); |
| | |
| | | AccountStatusNotification notification) |
| | | { |
| | | Collection<AccountStatusNotificationHandler<?>> handlers = |
| | | passwordPolicy.getAccountStatusNotificationHandlers().values(); |
| | | if ((handlers == null) || handlers.isEmpty()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | passwordPolicy.getAccountStatusNotificationHandlers(); |
| | | for (AccountStatusNotificationHandler<?> handler : handlers) |
| | | { |
| | | handler.handleStatusNotification(notification); |