001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2010 Sun Microsystems, Inc.
015 * Portions copyright 2011-2016 ForgeRock AS.
016 */
017package org.opends.server.core;
018
019import java.util.Collection;
020import java.util.List;
021import java.util.Set;
022import java.util.SortedSet;
023
024import org.opends.server.admin.std.meta.PasswordPolicyCfgDefn.*;
025import org.opends.server.api.*;
026import org.forgerock.opendj.ldap.schema.AttributeType;
027import org.forgerock.opendj.ldap.DN;
028import org.opends.server.types.DirectoryException;
029import org.opends.server.types.Entry;
030
031/**
032 * This class defines a data structure that holds information about a Directory
033 * Server password policy.
034 */
035public abstract class PasswordPolicy extends AuthenticationPolicy
036{
037
038  /** Creates a new password policy. */
039  protected PasswordPolicy()
040  {
041    // Nothing to do.
042  }
043
044
045
046  /** {@inheritDoc} */
047  public abstract DN getDN();
048
049
050
051  /**
052   * Indicates whether the associated password attribute uses the auth password
053   * syntax.
054   *
055   * @return <CODE>true</CODE> if the associated password attribute uses the
056   *         auth password syntax, or <CODE>false</CODE> if not.
057   */
058  public abstract boolean isAuthPasswordSyntax();
059
060
061
062  /**
063   * Retrieves the default set of password storage schemes that will be used for
064   * this password policy. The returned set should not be modified by the
065   * caller.
066   *
067   * @return The default set of password storage schemes that will be used for
068   *         this password policy.
069   */
070  public abstract List<PasswordStorageScheme<?>>
071    getDefaultPasswordStorageSchemes();
072
073
074
075  /**
076   * Gets the "deprecated-password-storage-scheme" property.
077   * <p>
078   * Specifies the names of the password storage schemes that are considered
079   * deprecated for this password policy.
080   * <p>
081   * If a user with this password policy authenticates to the server and
082   * his/her password is encoded with a deprecated scheme, those values are
083   * removed and replaced with values encoded using the default password
084   * storage scheme(s).
085   *
086   * @return Returns an unmodifiable set containing the values of the
087   *         "deprecated-password-storage-scheme" property.
088   */
089  public abstract Set<String> getDeprecatedPasswordStorageSchemes();
090
091
092
093  /**
094   * Indicates whether the specified storage scheme is a default scheme for this
095   * password policy.
096   *
097   * @param name
098   *          The name of the password storage scheme for which to make the
099   *          determination.
100   * @return <CODE>true</CODE> if the storage scheme is a default scheme for
101   *         this password policy, or <CODE>false</CODE> if not.
102   */
103  public abstract boolean isDefaultPasswordStorageScheme(String name);
104
105
106
107  /**
108   * Indicates whether the specified storage scheme is deprecated.
109   *
110   * @param name
111   *          The name of the password storage scheme for which to make the
112   *          determination.
113   * @return <CODE>true</CODE> if the storage scheme is deprecated, or
114   *         <CODE>false</CODE> if not.
115   */
116  public abstract boolean isDeprecatedPasswordStorageScheme(String name);
117
118
119
120  /**
121   * Retrieves the set of password validators for this password policy. The
122   * returned list should not be altered by the caller.
123   *
124   * @return The set of password validators for this password policy.
125   */
126  public abstract Collection<PasswordValidator<?>> getPasswordValidators();
127
128
129
130  /**
131   * Retrieves the set of account status notification handlers that should be
132   * used with this password policy. The returned list should not be altered by
133   * the caller.
134   *
135   * @return The set of account status notification handlers that should be used
136   *         with this password policy.
137   */
138  public abstract Collection<AccountStatusNotificationHandler<?>>
139    getAccountStatusNotificationHandlers();
140
141
142
143  /**
144   * Retrieves the password generator that will be used with this password
145   * policy.
146   *
147   * @return The password generator that will be used with this password policy,
148   *         or <CODE>null</CODE> if there is none.
149   */
150  public abstract PasswordGenerator<?> getPasswordGenerator();
151
152
153
154  /**
155   * Retrieves the time by which all users will be required to change their
156   * passwords, expressed in the number of milliseconds since midnight of
157   * January 1, 1970 (i.e., the zero time for
158   * <CODE>System.currentTimeMillis()</CODE>). Any passwords not changed before
159   * this time will automatically enter a state in which they must be changed
160   * before any other operation will be allowed.
161   *
162   * @return The time by which all users will be required to change their
163   *         passwords, or zero if no such constraint is in effect.
164   */
165  public abstract long getRequireChangeByTime();
166
167
168
169  /**
170   * Gets the "allow-expired-password-changes" property.
171   * <p>
172   * Indicates whether a user whose password is expired is still allowed to
173   * change that password using the password modify extended operation.
174   *
175   * @return Returns the value of the "allow-expired-password-changes" property.
176   */
177  public abstract boolean isAllowExpiredPasswordChanges();
178
179
180
181  /**
182   * Gets the "allow-multiple-password-values" property.
183   * <p>
184   * Indicates whether user entries can have multiple distinct values for the
185   * password attribute.
186   * <p>
187   * This is potentially dangerous because many mechanisms used to change the
188   * password do not work well with such a configuration. If multiple password
189   * values are allowed, then any of them can be used to authenticate, and they
190   * are all subject to the same policy constraints.
191   *
192   * @return Returns the value of the "allow-multiple-password-values" property.
193   */
194  public abstract boolean isAllowMultiplePasswordValues();
195
196
197
198  /**
199   * Gets the "allow-pre-encoded-passwords" property.
200   * <p>
201   * Indicates whether users can change their passwords by providing a
202   * pre-encoded value.
203   * <p>
204   * This can cause a security risk because the clear-text version of the
205   * password is not known and therefore validation checks cannot be applied to
206   * it.
207   *
208   * @return Returns the value of the "allow-pre-encoded-passwords" property.
209   */
210  public abstract boolean isAllowPreEncodedPasswords();
211
212
213
214  /**
215   * Gets the "allow-user-password-changes" property.
216   * <p>
217   * Indicates whether users can change their own passwords.
218   * <p>
219   * This check is made in addition to access control evaluation. Both must
220   * allow the password change for it to occur.
221   *
222   * @return Returns the value of the "allow-user-password-changes" property.
223   */
224  public abstract boolean isAllowUserPasswordChanges();
225
226
227
228  /**
229   * Gets the "expire-passwords-without-warning" property.
230   * <p>
231   * Indicates whether the directory server allows a user's password to expire
232   * even if that user has never seen an expiration warning notification.
233   * <p>
234   * If this property is true, accounts always expire when the expiration time
235   * arrives. If this property is false or disabled, the user always receives at
236   * least one warning notification, and the password expiration is set to the
237   * warning time plus the warning interval.
238   *
239   * @return Returns the value of the "expire-passwords-without-warning"
240   *         property.
241   */
242  public abstract boolean isExpirePasswordsWithoutWarning();
243
244
245
246  /**
247   * Gets the "force-change-on-add" property.
248   * <p>
249   * Indicates whether users are forced to change their passwords upon first
250   * authenticating to the directory server after their account has been
251   * created.
252   *
253   * @return Returns the value of the "force-change-on-add" property.
254   */
255  public abstract boolean isForceChangeOnAdd();
256
257
258
259  /**
260   * Gets the "force-change-on-reset" property.
261   * <p>
262   * Indicates whether users are forced to change their passwords if they are
263   * reset by an administrator.
264   * <p>
265   * For this purpose, anyone with permission to change a given user's password
266   * other than that user is considered an administrator.
267   *
268   * @return Returns the value of the "force-change-on-reset" property.
269   */
270  public abstract boolean isForceChangeOnReset();
271
272
273
274  /**
275   * Gets the "grace-login-count" property.
276   * <p>
277   * Specifies the number of grace logins that a user is allowed after the
278   * account has expired to allow that user to choose a new password.
279   * <p>
280   * A value of 0 indicates that no grace logins are allowed.
281   *
282   * @return Returns the value of the "grace-login-count" property.
283   */
284  public abstract int getGraceLoginCount();
285
286
287
288  /**
289   * Gets the "idle-lockout-interval" property.
290   * <p>
291   * Specifies the maximum length of time that an account may remain idle (that
292   * is, the associated user does not authenticate to the server) before that
293   * user is locked out.
294   * <p>
295   * The value of this attribute is an integer followed by a unit of seconds,
296   * minutes, hours, days, or weeks. A value of 0 seconds indicates that idle
297   * accounts are not automatically locked out. This feature is available only
298   * if the last login time is maintained.
299   *
300   * @return Returns the value of the "idle-lockout-interval" property.
301   */
302  public abstract long getIdleLockoutInterval();
303
304
305
306  /**
307   * Gets the "last-login-time-attribute" property.
308   * <p>
309   * Specifies the name or OID of the attribute type that is used to hold the
310   * last login time for users with the associated password policy.
311   * <p>
312   * This attribute type must be defined in the directory server schema and must
313   * either be defined as an operational attribute or must be allowed by the set
314   * of objectClasses for all users with the associated password policy.
315   *
316   * @return Returns the value of the "last-login-time-attribute" property.
317   */
318  public abstract AttributeType getLastLoginTimeAttribute();
319
320
321
322  /**
323   * Gets the "last-login-time-format" property.
324   * <p>
325   * Specifies the format string that is used to generate the last login time
326   * value for users with the associated password policy.
327   * <p>
328   * This format string conforms to the syntax described in the API
329   * documentation for the java.text.SimpleDateFormat class.
330   *
331   * @return Returns the value of the "last-login-time-format" property.
332   */
333  public abstract String getLastLoginTimeFormat();
334
335
336
337  /**
338   * Gets the "lockout-duration" property.
339   * <p>
340   * Specifies the length of time that an account is locked after too many
341   * authentication failures.
342   * <p>
343   * The value of this attribute is an integer followed by a unit of seconds,
344   * minutes, hours, days, or weeks. A value of 0 seconds indicates that the
345   * account must remain locked until an administrator resets the password.
346   *
347   * @return Returns the value of the "lockout-duration" property.
348   */
349  public abstract long getLockoutDuration();
350
351
352
353  /**
354   * Gets the "lockout-failure-count" property.
355   * <p>
356   * Specifies the maximum number of authentication failures that a user is
357   * allowed before the account is locked out.
358   * <p>
359   * A value of 0 indicates that accounts are never locked out due to failed
360   * attempts.
361   *
362   * @return Returns the value of the "lockout-failure-count" property.
363   */
364  public abstract int getLockoutFailureCount();
365
366
367
368  /**
369   * Gets the "lockout-failure-expiration-interval" property.
370   * <p>
371   * Specifies the length of time before an authentication failure is no longer
372   * counted against a user for the purposes of account lockout.
373   * <p>
374   * The value of this attribute is an integer followed by a unit of seconds,
375   * minutes, hours, days, or weeks. A value of 0 seconds indicates that the
376   * authentication failures must never expire. The failure count is always
377   * cleared upon a successful authentication.
378   *
379   * @return Returns the value of the "lockout-failure-expiration-interval"
380   *         property.
381   */
382  public abstract long getLockoutFailureExpirationInterval();
383
384
385
386  /**
387   * Gets the "max-password-age" property.
388   * <p>
389   * Specifies the maximum length of time that a user can continue using the
390   * same password before it must be changed (that is, the password expiration
391   * interval).
392   * <p>
393   * The value of this attribute is an integer followed by a unit of seconds,
394   * minutes, hours, days, or weeks. A value of 0 seconds disables password
395   * expiration.
396   *
397   * @return Returns the value of the "max-password-age" property.
398   */
399  public abstract long getMaxPasswordAge();
400
401
402
403  /**
404   * Gets the "max-password-reset-age" property.
405   * <p>
406   * Specifies the maximum length of time that users have to change passwords
407   * after they have been reset by an administrator before they become locked.
408   * <p>
409   * The value of this attribute is an integer followed by a unit of seconds,
410   * minutes, hours, days, or weeks. A value of 0 seconds disables this feature.
411   *
412   * @return Returns the value of the "max-password-reset-age" property.
413   */
414  public abstract long getMaxPasswordResetAge();
415
416
417
418  /**
419   * Gets the "min-password-age" property.
420   * <p>
421   * Specifies the minimum length of time after a password change before the
422   * user is allowed to change the password again.
423   * <p>
424   * The value of this attribute is an integer followed by a unit of seconds,
425   * minutes, hours, days, or weeks. This setting can be used to prevent users
426   * from changing their passwords repeatedly over a short period of time to
427   * flush an old password from the history so that it can be re-used.
428   *
429   * @return Returns the value of the "min-password-age" property.
430   */
431  public abstract long getMinPasswordAge();
432
433
434
435  /**
436   * Gets the "password-attribute" property.
437   * <p>
438   * Specifies the attribute type used to hold user passwords.
439   * <p>
440   * This attribute type must be defined in the server schema, and it must have
441   * either the user password or auth password syntax.
442   *
443   * @return Returns the value of the "password-attribute" property.
444   */
445  public abstract AttributeType getPasswordAttribute();
446
447
448
449  /**
450   * Gets the "password-change-requires-current-password" property.
451   * <p>
452   * Indicates whether user password changes must use the password modify
453   * extended operation and must include the user's current password before the
454   * change is allowed.
455   *
456   * @return Returns the value of the
457   *         "password-change-requires-current-password" property.
458   */
459  public abstract boolean isPasswordChangeRequiresCurrentPassword();
460
461
462
463  /**
464   * Gets the "password-expiration-warning-interval" property.
465   * <p>
466   * Specifies the maximum length of time before a user's password actually
467   * expires that the server begins to include warning notifications in bind
468   * responses for that user.
469   * <p>
470   * The value of this attribute is an integer followed by a unit of seconds,
471   * minutes, hours, days, or weeks. A value of 0 seconds disables the warning
472   * interval.
473   *
474   * @return Returns the value of the "password-expiration-warning-interval"
475   *         property.
476   */
477  public abstract long getPasswordExpirationWarningInterval();
478
479
480
481  /**
482   * Gets the "password-history-count" property.
483   * <p>
484   * Specifies the maximum number of former passwords to maintain in the
485   * password history.
486   * <p>
487   * When choosing a new password, the proposed password is checked to ensure
488   * that it does not match the current password, nor any other password in the
489   * history list. A value of zero indicates that either no password history is
490   * to be maintained (if the password history duration has a value of zero
491   * seconds), or that there is no maximum number of passwords to maintain in
492   * the history (if the password history duration has a value greater than zero
493   * seconds).
494   *
495   * @return Returns the value of the "password-history-count" property.
496   */
497  public abstract int getPasswordHistoryCount();
498
499
500
501  /**
502   * Gets the "password-history-duration" property.
503   * <p>
504   * Specifies the maximum length of time that passwords remain in the password
505   * history.
506   * <p>
507   * When choosing a new password, the proposed password is checked to ensure
508   * that it does not match the current password, nor any other password in the
509   * history list. A value of zero seconds indicates that either no password
510   * history is to be maintained (if the password history count has a value of
511   * zero), or that there is no maximum duration for passwords in the history
512   * (if the password history count has a value greater than zero).
513   *
514   * @return Returns the value of the "password-history-duration" property.
515   */
516  public abstract long getPasswordHistoryDuration();
517
518
519
520  /**
521   * Gets the "previous-last-login-time-format" property.
522   * <p>
523   * Specifies the format string(s) that might have been used with the last
524   * login time at any point in the past for users associated with the password
525   * policy.
526   * <p>
527   * These values are used to make it possible to parse previous values, but are
528   * not used to set new values. The format strings conform to the syntax
529   * described in the API documentation for the java.text.SimpleDateFormat
530   * class.
531   *
532   * @return Returns an unmodifiable set containing the values of the
533   *         "previous-last-login-time-format" property.
534   */
535  public abstract SortedSet<String> getPreviousLastLoginTimeFormats();
536
537
538
539  /**
540   * Gets the "require-secure-authentication" property.
541   * <p>
542   * Indicates whether users with the associated password policy are required to
543   * authenticate in a secure manner.
544   * <p>
545   * This might mean either using a secure communication channel between the
546   * client and the server, or using a SASL mechanism that does not expose the
547   * credentials.
548   *
549   * @return Returns the value of the "require-secure-authentication" property.
550   */
551  public abstract boolean isRequireSecureAuthentication();
552
553
554
555  /**
556   * Gets the "require-secure-password-changes" property.
557   * <p>
558   * Indicates whether users with the associated password policy are required to
559   * change their password in a secure manner that does not expose the
560   * credentials.
561   *
562   * @return Returns the value of the "require-secure-password-changes"
563   *         property.
564   */
565  public abstract boolean isRequireSecurePasswordChanges();
566
567
568
569  /**
570   * Gets the "skip-validation-for-administrators" property.
571   * <p>
572   * Indicates whether passwords set by administrators are allowed to bypass the
573   * password validation process that is required for user password changes.
574   *
575   * @return Returns the value of the "skip-validation-for-administrators"
576   *         property.
577   */
578  public abstract boolean isSkipValidationForAdministrators();
579
580
581
582  /**
583   * Gets the "state-update-failure-policy" property.
584   * <p>
585   * Specifies how the server deals with the inability to update password policy
586   * state information during an authentication attempt.
587   * <p>
588   * In particular, this property can be used to control whether an otherwise
589   * successful bind operation fails if a failure occurs while attempting to
590   * update password policy state information (for example, to clear a record of
591   * previous authentication failures or to update the last login time). It can
592   * also be used to control whether to reject a bind request if it is known
593   * ahead of time that it will not be possible to update the authentication
594   * failure times in the event of an unsuccessful bind attempt (for example, if
595   * the backend writability mode is disabled).
596   *
597   * @return Returns the value of the "state-update-failure-policy" property.
598   */
599  public abstract StateUpdateFailurePolicy getStateUpdateFailurePolicy();
600
601
602
603  /** {@inheritDoc} */
604  public boolean isPasswordPolicy()
605  {
606    return true;
607  }
608
609
610
611  /** {@inheritDoc} */
612  public PasswordPolicyState createAuthenticationPolicyState(Entry userEntry,
613      long time) throws DirectoryException
614  {
615    return new PasswordPolicyState(this, userEntry, time);
616  }
617}