mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

ludovicp
15.59.2010 b3fd8de34d9a827d582a8e33efdf18a958a6434d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 */
 
package org.opends.server.core;
 
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.opends.messages.Message;
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.std.meta.PasswordPolicyCfgDefn.
       StateUpdateFailurePolicy;
import org.opends.server.admin.std.server.PasswordPolicyCfg;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.DN;
import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.ResultCode;
import org.opends.server.types.SubEntry;
 
import static org.opends.messages.CoreMessages.*;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
 
/**
 * This class represents subentry password policy based on
 * Password Policy for LDAP Directories Internet-Draft. In
 * order to represent subentry password policies as OpenDS
 * password policies it performs a mapping of Draft defined
 * attributes to OpenDS implementation specific attributes.
 * Any missing attributes are inherited from server default
 * password policy. This class is also reponsible for any
 * Draft attributes validation ie making sure that provided
 * values are acceptable and within the predefined range.
 */
public class SubentryPasswordPolicy implements PasswordPolicyCfg
{
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
 
  // Password Policy Subentry draft attributes.
  private final String PWD_OC_POLICY = "pwdpolicy";
  private final String PWD_ATTR_ATTRIBUTE = "pwdattribute";
  private final String PWD_ATTR_MINAGE = "pwdminage";
  private final String PWD_ATTR_MAXAGE = "pwdmaxage";
  private final String PWD_ATTR_INHISTORY = "pwdinhistory";
  private final String PWD_ATTR_CHECKQUALITY = "pwdcheckquality";
  private final String PWD_ATTR_MINLENGTH = "pwdminlength";
  private final String PWD_ATTR_EXPIREWARNING = "pwdexpirewarning";
  private final String PWD_ATTR_GRACEAUTHNLIMIT = "pwdgraceauthnlimit";
  private final String PWD_ATTR_LOCKOUT = "pwdlockout";
  private final String PWD_ATTR_LOCKOUTDURATION = "pwdlockoutduration";
  private final String PWD_ATTR_MAXFAILURE = "pwdmaxfailure";
  private final String PWD_ATTR_MUSTCHANGE = "pwdmustchange";
  private final String PWD_ATTR_ALLOWUSERCHANGE = "pwdallowuserchange";
  private final String PWD_ATTR_SAFEMODIFY = "pwdsafemodify";
  private final String PWD_ATTR_FAILURECOUNTINTERVAL =
          "pwdfailurecountinterval";
 
  // Password Policy Subentry DN.
  private final DN passwordPolicySubentryDN;
  // The value of the "account-status-notification-handler" property.
  private final SortedSet<String> pAccountStatusNotificationHandler;
  // The value of the "allow-expired-password-changes" property.
  private final boolean pAllowExpiredPasswordChanges;
  // The value of the "allow-multiple-password-values" property.
  private final boolean pAllowMultiplePasswordValues;
  // The value of the "allow-pre-encoded-passwords" property.
  private final boolean pAllowPreEncodedPasswords;
  // The value of the "allow-user-password-changes" property.
  private final boolean pAllowUserPasswordChanges;
  // The value of the "default-password-storage-scheme" property.
  private final SortedSet<String> pDefaultPasswordStorageScheme;
  // The value of the "deprecated-password-storage-scheme" property.
  private final SortedSet<String> pDeprecatedPasswordStorageScheme;
  // The value of the "expire-passwords-without-warning" property.
  private final boolean pExpirePasswordsWithoutWarning;
  // The value of the "force-change-on-add" property.
  private final boolean pForceChangeOnAdd;
  // The value of the "force-change-on-reset" property.
  private final boolean pForceChangeOnReset;
  // The value of the "grace-login-count" property.
  private final int pGraceLoginCount;
  // The value of the "idle-lockout-interval" property.
  private final long pIdleLockoutInterval;
  // The value of the "last-login-time-attribute" property.
  private final AttributeType pLastLoginTimeAttribute;
  // The value of the "last-login-time-format" property.
  private final String pLastLoginTimeFormat;
  // The value of the "lockout-duration" property.
  private final long pLockoutDuration;
  // The value of the "lockout-failure-count" property.
  private final int pLockoutFailureCount;
  // The value of the "lockout-failure-expiration-interval" property.
  private final long pLockoutFailureExpirationInterval;
  // The value of the "max-password-age" property.
  private final long pMaxPasswordAge;
  // The value of the "max-password-reset-age" property.
  private final long pMaxPasswordResetAge;
  // The value of the "min-password-age" property.
  private final long pMinPasswordAge;
  // The value of the "password-attribute" property.
  private final AttributeType pPasswordAttribute;
  // The value of the "password-change-requires-current-password" property.
  private final boolean pPasswordChangeRequiresCurrentPassword;
  // The value of the "password-expiration-warning-interval" property.
  private final long pPasswordExpirationWarningInterval;
  // The value of the "password-generator" property.
  private final String pPasswordGenerator;
  // The value of the "password-history-count" property.
  private final int pPasswordHistoryCount;
  // The value of the "password-history-duration" property.
  private final long pPasswordHistoryDuration;
  // The value of the "password-validator" property.
  private final SortedSet<String> pPasswordValidator;
  // The value of the "previous-last-login-time-format" property.
  private final SortedSet<String> pPreviousLastLoginTimeFormat;
  // The value of the "require-change-by-time" property.
  private final String pRequireChangeByTime;
  // The value of the "require-secure-authentication" property.
  private final boolean pRequireSecureAuthentication;
  // The value of the "require-secure-password-changes" property.
  private final boolean pRequireSecurePasswordChanges;
  // The value of the "skip-validation-for-administrators" property.
  private final boolean pSkipValidationForAdministrators;
  // The value of the "state-update-failure-policy" property.
  private final StateUpdateFailurePolicy pStateUpdateFailurePolicy;
 
  /**
   * Creates subentry password policy object from the subentry,
   * parsing and evaluating subentry password policy attributes.
   *
   * @param  subentry password policy subentry.
   * @throws DirectoryException If a problem occurs while creating
   *                            subentry password policy instance
   *                            from given subentry.
   */
  public SubentryPasswordPolicy(SubEntry subentry)
          throws DirectoryException
  {
    // Determine if this is a password policy subentry.
    ObjectClass pwdPolicyOC =
         DirectoryServer.getObjectClass(PWD_OC_POLICY);
    Entry entry = subentry.getEntry();
    Map<ObjectClass, String> objectClasses =
            entry.getObjectClasses();
    if (pwdPolicyOC == null) {
      // This should not happen -- The server doesn't
      // have a pwdPolicy objectclass defined.
      if (debugEnabled()) {
        TRACER.debugWarning(
                "No %s objectclass is defined in the server schema.",
                PWD_OC_POLICY);
      }
      for (String ocName : objectClasses.values()) {
        if (ocName.equalsIgnoreCase(PWD_OC_POLICY)) {
          break;
        }
      }
      Message message = ERR_PWPOLICY_NO_PWDPOLICY_OC.get(
              subentry.getDN().toString());
      throw new DirectoryException(
              ResultCode.CONSTRAINT_VIOLATION, message);
    } else if (!objectClasses.containsKey(pwdPolicyOC)) {
      Message message = ERR_PWPOLICY_NO_PWDPOLICY_OC.get(
              subentry.getDN().toString());
      throw new DirectoryException(
              ResultCode.CONSTRAINT_VIOLATION, message);
    }
 
    // Get default password policy to derive default
    // policy values from.
    PasswordPolicy defaultPasswordPolicy =
            DirectoryServer.getDefaultPasswordPolicy();
    if (defaultPasswordPolicy == null) {
      throw new DirectoryException(ResultCode.OPERATIONS_ERROR,
              ERR_CONFIG_PWPOLICY_NO_DEFAULT_POLICY.get());
    }
 
    // Subentry DN for this password policy.
    this.passwordPolicySubentryDN = subentry.getDN();
 
    // Get known Password Policy draft attributes from the entry.
    // If any given attribute is missing or empty set its value
    // from default Password Policy configuration.
    AttributeValue value = getAttrValue(entry, PWD_ATTR_ATTRIBUTE);
    if ((value != null) && (value.toString().length() > 0)) {
      this.pPasswordAttribute = DirectoryServer.getAttributeType(
              value.toString().toLowerCase(), false);
      if (this.pPasswordAttribute == null) {
        throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
                ERR_PWPOLICY_UNDEFINED_PASSWORD_ATTRIBUTE.get(
                this.passwordPolicySubentryDN.toNormalizedString(),
                value.toString()));
      }
    } else {
      // This should not normally happen since pwdAttribute
      // declared as MUST but handle this anyway in case
      // the schema is not enforced for some reason.
      this.pPasswordAttribute =
              defaultPasswordPolicy.getPasswordAttribute();
    }
 
    value = getAttrValue(entry, PWD_ATTR_MINAGE);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pMinPasswordAge = Long.parseLong(value.toString());
        checkIntegerAttr(PWD_ATTR_MINAGE, this.pMinPasswordAge,
                0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pMinPasswordAge =
              defaultPasswordPolicy.getMinimumPasswordAge();
    }
 
    value = getAttrValue(entry, PWD_ATTR_MAXAGE);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pMaxPasswordAge = Long.parseLong(value.toString());
        checkIntegerAttr(PWD_ATTR_MAXAGE, this.pMaxPasswordAge,
                0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pMaxPasswordAge =
              defaultPasswordPolicy.getMaximumPasswordAge();
    }
 
    value = getAttrValue(entry, PWD_ATTR_INHISTORY);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pPasswordHistoryCount = Integer.parseInt(value.toString());
        checkIntegerAttr(PWD_ATTR_INHISTORY,
                this.pPasswordHistoryCount, 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pPasswordHistoryCount =
              defaultPasswordPolicy.getPasswordHistoryCount();
    }
 
    // This one is managed via the password validator
    // so only check if its value is acceptable.
    value = getAttrValue(entry, PWD_ATTR_CHECKQUALITY);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        int pwdCheckQuality = Integer.parseInt(value.toString());
        checkIntegerAttr(PWD_ATTR_CHECKQUALITY, pwdCheckQuality,
                 0, 2);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    }
 
    // This one is managed via the password validator
    // so only check if its value is acceptable.
    value = getAttrValue(entry, PWD_ATTR_MINLENGTH);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        int pwdMinLength = Integer.parseInt(value.toString());
        checkIntegerAttr(PWD_ATTR_MINLENGTH, pwdMinLength,
                 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    }
 
    // This one depends on lockout failure count value
    // so only check if its value is acceptable.
    value = getAttrValue(entry, PWD_ATTR_LOCKOUT);
    if ((value != null) && (value.toString().length() > 0)) {
      if (value.toString().equalsIgnoreCase(Boolean.TRUE.toString()) ||
          value.toString().equalsIgnoreCase(Boolean.FALSE.toString())) {
        Boolean.parseBoolean(value.toString());
      } else {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
                PWD_ATTR_MUSTCHANGE, value.toString()));
      }
    }
 
    value = getAttrValue(entry, PWD_ATTR_EXPIREWARNING);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pPasswordExpirationWarningInterval =
              Long.parseLong(value.toString());
        checkIntegerAttr(PWD_ATTR_EXPIREWARNING,
                this.pPasswordExpirationWarningInterval,
                 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pPasswordExpirationWarningInterval =
              defaultPasswordPolicy.getWarningInterval();
    }
 
    value = getAttrValue(entry, PWD_ATTR_GRACEAUTHNLIMIT);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pGraceLoginCount = Integer.parseInt(value.toString());
        checkIntegerAttr(PWD_ATTR_GRACEAUTHNLIMIT,
                this.pGraceLoginCount, 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pGraceLoginCount =
              defaultPasswordPolicy.getGraceLoginCount();
    }
 
    value = getAttrValue(entry, PWD_ATTR_LOCKOUTDURATION);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pLockoutDuration = Long.parseLong(value.toString());
        checkIntegerAttr(PWD_ATTR_LOCKOUTDURATION,
                this.pLockoutDuration, 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pLockoutDuration =
              defaultPasswordPolicy.getLockoutDuration();
    }
 
    value = getAttrValue(entry, PWD_ATTR_MAXFAILURE);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pLockoutFailureCount = Integer.parseInt(value.toString());
        checkIntegerAttr(PWD_ATTR_MAXFAILURE,
                this.pLockoutFailureCount, 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_MINAGE, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pLockoutFailureCount =
              defaultPasswordPolicy.getLockoutFailureCount();
    }
 
    value = getAttrValue(entry, PWD_ATTR_MUSTCHANGE);
    if ((value != null) && (value.toString().length() > 0)) {
      if (value.toString().equalsIgnoreCase(Boolean.TRUE.toString()) ||
          value.toString().equalsIgnoreCase(Boolean.FALSE.toString())) {
        this.pForceChangeOnReset =
                Boolean.parseBoolean(value.toString());
      } else {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
                PWD_ATTR_MUSTCHANGE, value.toString()));
      }
    } else {
      this.pForceChangeOnReset =
              defaultPasswordPolicy.forceChangeOnReset();
    }
 
    value = getAttrValue(entry, PWD_ATTR_ALLOWUSERCHANGE);
    if ((value != null) && (value.toString().length() > 0)) {
      if (value.toString().equalsIgnoreCase(Boolean.TRUE.toString()) ||
          value.toString().equalsIgnoreCase(Boolean.FALSE.toString())) {
        this.pAllowUserPasswordChanges =
                Boolean.parseBoolean(value.toString());
      } else {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
                PWD_ATTR_ALLOWUSERCHANGE, value.toString()));
      }
    } else {
      this.pAllowUserPasswordChanges =
              defaultPasswordPolicy.allowUserPasswordChanges();
    }
 
    value = getAttrValue(entry, PWD_ATTR_SAFEMODIFY);
    if ((value != null) && (value.toString().length() > 0)) {
      if (value.toString().equalsIgnoreCase(Boolean.TRUE.toString()) ||
          value.toString().equalsIgnoreCase(Boolean.FALSE.toString())) {
        this.pPasswordChangeRequiresCurrentPassword =
                Boolean.parseBoolean(value.toString());
      } else {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_BOOLEAN_VALUE.get(
                PWD_ATTR_SAFEMODIFY, value.toString()));
      }
    } else {
      this.pPasswordChangeRequiresCurrentPassword =
              defaultPasswordPolicy.requireCurrentPassword();
    }
 
    value = getAttrValue(entry, PWD_ATTR_FAILURECOUNTINTERVAL);
    if ((value != null) && (value.toString().length() > 0)) {
      try {
        this.pLockoutFailureExpirationInterval =
                Long.parseLong(value.toString());
        checkIntegerAttr(PWD_ATTR_FAILURECOUNTINTERVAL,
                this.pLockoutFailureExpirationInterval,
                 0, Integer.MAX_VALUE);
      } catch (NumberFormatException ne) {
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INVALID_INT_VALUE.get(
                PWD_ATTR_FAILURECOUNTINTERVAL, value.toString(),
                ne.getLocalizedMessage()));
      }
    } else {
      this.pLockoutFailureExpirationInterval =
              defaultPasswordPolicy.getLockoutFailureExpirationInterval();
    }
 
    // Get the rest Password Policy attributes from default configuration.
    SortedSet<String> accountStatusNotificationHandlerSet =
            new TreeSet<String>();
    Set<DN> accountStatusNotificationHandlerDNSet =
            defaultPasswordPolicy.getAccountStatusNotificationHandlers(
            ).keySet();
    for (DN dn : accountStatusNotificationHandlerDNSet) {
      accountStatusNotificationHandlerSet.add(dn.toNormalizedString());
    }
    this.pAccountStatusNotificationHandler =
            accountStatusNotificationHandlerSet;
    this.pAllowExpiredPasswordChanges =
            defaultPasswordPolicy.allowExpiredPasswordChanges();
    this.pAllowMultiplePasswordValues =
            defaultPasswordPolicy.allowMultiplePasswordValues();
    this.pAllowPreEncodedPasswords =
            defaultPasswordPolicy.allowPreEncodedPasswords();
    SortedSet<String> passwordStorageSchemeSet =
            new TreeSet<String>();
    for (DN dn : defaultPasswordPolicy.getDefaultStorageSchemeDNs()) {
      passwordStorageSchemeSet.add(dn.toNormalizedString());
    }
    this.pDefaultPasswordStorageScheme =
            passwordStorageSchemeSet;
    SortedSet<String> deprecatedPasswordStorageSchemeSet =
            new TreeSet<String>();
    for (DN dn : defaultPasswordPolicy.getDeprecatedStorageSchemeDNs()) {
      deprecatedPasswordStorageSchemeSet.add(dn.toNormalizedString());
    }
    this.pDeprecatedPasswordStorageScheme =
            deprecatedPasswordStorageSchemeSet;
    this.pExpirePasswordsWithoutWarning =
            defaultPasswordPolicy.expirePasswordsWithoutWarning();
    this.pForceChangeOnAdd =
            defaultPasswordPolicy.forceChangeOnAdd();
    this.pIdleLockoutInterval =
            defaultPasswordPolicy.getIdleLockoutInterval();
    this.pLastLoginTimeAttribute =
            defaultPasswordPolicy.getLastLoginTimeAttribute();
    this.pLastLoginTimeFormat =
            defaultPasswordPolicy.getLastLoginTimeFormat();
    this.pMaxPasswordResetAge =
            defaultPasswordPolicy.getMaximumPasswordResetAge();
    this.pPasswordGenerator =
            defaultPasswordPolicy.getPasswordGeneratorDN(
            ).toNormalizedString();
    this.pPasswordHistoryDuration =
            defaultPasswordPolicy.getPasswordHistoryDuration();
    SortedSet<String> passwordValidatorSet =
            new TreeSet<String>();
    Set<DN> passwordValidatorDNSet =
            defaultPasswordPolicy.getPasswordValidators(
            ).keySet();
    for (DN dn : passwordValidatorDNSet) {
      passwordValidatorSet.add(dn.toNormalizedString());
    }
    this.pPasswordValidator =
            passwordValidatorSet;
    this.pPreviousLastLoginTimeFormat = new TreeSet<String>(
            defaultPasswordPolicy.getPreviousLastLoginTimeFormats());
 
    long requireChangeByTime =
            defaultPasswordPolicy.getRequireChangeByTime();
    if (requireChangeByTime > 0) {
      this.pRequireChangeByTime = Long.toString(requireChangeByTime);
    } else {
      this.pRequireChangeByTime = null;
    }
 
    this.pRequireSecureAuthentication =
            defaultPasswordPolicy.requireSecureAuthentication();
    this.pRequireSecurePasswordChanges =
            defaultPasswordPolicy.requireSecurePasswordChanges();
    this.pSkipValidationForAdministrators =
            defaultPasswordPolicy.skipValidationForAdministrators();
    this.pStateUpdateFailurePolicy =
            defaultPasswordPolicy.getStateUpdateFailurePolicy();
  }
 
  /**
   * Helper method to validate integer values.
   * @param attrName integer attribute name.
   * @param attrValue integer value to validate.
   * @param lowerBound lowest acceptable value.
   * @param upperBound highest acceptable value.
   * @throws DirectoryException if the value is out of bounds.
   */
  private void checkIntegerAttr(String attrName, long attrValue,
          long lowerBound, long upperBound) throws DirectoryException
  {
    if (attrValue < lowerBound) {
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get(attrName,
                attrValue, lowerBound));
    }
    if (attrValue > upperBound) {
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get(attrName,
                attrValue, upperBound));
    }
  }
 
  /**
   * Helper method to retieve an attribute value from given entry.
   * @param entry the entry to retrieve an attribute value from.
   * @param pwdAttrName attribute name to retrieve the value for.
   * @return <CODE>AttributeValue</CODE> or <CODE>null</CODE>.
   */
  private AttributeValue getAttrValue(Entry entry, String pwdAttrName) {
    AttributeType pwdAttrType = DirectoryServer.getAttributeType(
            pwdAttrName, true);
    List<Attribute> pwdAttrList = entry.getAttribute(pwdAttrType);
    if ((pwdAttrList != null) && (!pwdAttrList.isEmpty()))
    {
      for (Attribute attr : pwdAttrList)
      {
        for (AttributeValue value : attr)
        {
          return value;
        }
      }
    }
    return null;
  }
 
  /**
   * {@inheritDoc}
   */
  public void addChangeListener(
          ConfigurationChangeListener<PasswordPolicyCfg> listener) {
    // N/A : This is a subentry based configuration object.
  }
 
  /**
   * {@inheritDoc}
   */
  public void removeChangeListener(
          ConfigurationChangeListener<PasswordPolicyCfg> listener) {
    // N/A : This is a subentry based configuration object.
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<String> getAccountStatusNotificationHandler() {
    return pAccountStatusNotificationHandler;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<DN> getAccountStatusNotificationHandlerDNs() {
    SortedSet<String> values = getAccountStatusNotificationHandler();
    SortedSet<DN> dnValues = new TreeSet<DN>();
    for (String value : values) {
      try {
        dnValues.add(DN.decode(value));
      } catch (DirectoryException de) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, de);
        }
      }
    }
    return dnValues;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isAllowExpiredPasswordChanges() {
    return pAllowExpiredPasswordChanges;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isAllowMultiplePasswordValues() {
    return pAllowMultiplePasswordValues;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isAllowPreEncodedPasswords() {
    return pAllowPreEncodedPasswords;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isAllowUserPasswordChanges() {
    return pAllowUserPasswordChanges;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<String> getDefaultPasswordStorageScheme() {
    return pDefaultPasswordStorageScheme;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<DN> getDefaultPasswordStorageSchemeDNs() {
    SortedSet<String> values = getDefaultPasswordStorageScheme();
    SortedSet<DN> dnValues = new TreeSet<DN>();
    for (String value : values) {
      try {
        dnValues.add(DN.decode(value));
      } catch (DirectoryException de) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, de);
        }
      }
    }
    return dnValues;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<String> getDeprecatedPasswordStorageScheme() {
    return pDeprecatedPasswordStorageScheme;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<DN> getDeprecatedPasswordStorageSchemeDNs() {
    SortedSet<String> values = getDeprecatedPasswordStorageScheme();
    SortedSet<DN> dnValues = new TreeSet<DN>();
    for (String value : values) {
      try {
        dnValues.add(DN.decode(value));
      } catch (DirectoryException de) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, de);
        }
      }
    }
    return dnValues;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isExpirePasswordsWithoutWarning() {
    return pExpirePasswordsWithoutWarning;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isForceChangeOnAdd() {
    return pForceChangeOnAdd;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isForceChangeOnReset() {
    return pForceChangeOnReset;
  }
 
  /**
   * {@inheritDoc}
   */
  public int getGraceLoginCount() {
    return pGraceLoginCount;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getIdleLockoutInterval() {
    return pIdleLockoutInterval;
  }
 
  /**
   * {@inheritDoc}
   */
  public AttributeType getLastLoginTimeAttribute() {
    return pLastLoginTimeAttribute;
  }
 
  /**
   * {@inheritDoc}
   */
  public String getLastLoginTimeFormat() {
    return pLastLoginTimeFormat;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getLockoutDuration() {
    return pLockoutDuration;
  }
 
  /**
   * {@inheritDoc}
   */
  public int getLockoutFailureCount() {
    return pLockoutFailureCount;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getLockoutFailureExpirationInterval() {
    return pLockoutFailureExpirationInterval;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getMaxPasswordAge() {
    return pMaxPasswordAge;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getMaxPasswordResetAge() {
    return pMaxPasswordResetAge;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getMinPasswordAge() {
    return pMinPasswordAge;
  }
 
  /**
   * {@inheritDoc}
   */
  public AttributeType getPasswordAttribute() {
    return pPasswordAttribute;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isPasswordChangeRequiresCurrentPassword() {
    return pPasswordChangeRequiresCurrentPassword;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getPasswordExpirationWarningInterval() {
    return pPasswordExpirationWarningInterval;
  }
 
  /**
   * {@inheritDoc}
   */
  public String getPasswordGenerator() {
    return pPasswordGenerator;
  }
 
  /**
   * {@inheritDoc}
   */
  public DN getPasswordGeneratorDN() {
    String value = getPasswordGenerator();
    if (value == null) {
      return null;
    }
    try {
      return DN.decode(value);
    } catch (DirectoryException de) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, de);
      }
      return null;
    }
  }
 
  /**
   * {@inheritDoc}
   */
  public int getPasswordHistoryCount() {
    return pPasswordHistoryCount;
  }
 
  /**
   * {@inheritDoc}
   */
  public long getPasswordHistoryDuration() {
    return pPasswordHistoryDuration;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<String> getPasswordValidator() {
    return pPasswordValidator;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<DN> getPasswordValidatorDNs() {
    SortedSet<String> values = getPasswordValidator();
    SortedSet<DN> dnValues = new TreeSet<DN>();
    for (String value : values) {
      try {
        dnValues.add(DN.decode(value));
      } catch (DirectoryException de) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, de);
        }
      }
    }
    return dnValues;
  }
 
  /**
   * {@inheritDoc}
   */
  public SortedSet<String> getPreviousLastLoginTimeFormat() {
    return pPreviousLastLoginTimeFormat;
  }
 
  /**
   * {@inheritDoc}
   */
  public String getRequireChangeByTime() {
    return pRequireChangeByTime;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isRequireSecureAuthentication() {
    return pRequireSecureAuthentication;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isRequireSecurePasswordChanges() {
    return pRequireSecurePasswordChanges;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isSkipValidationForAdministrators() {
    return pSkipValidationForAdministrators;
  }
 
  /**
   * {@inheritDoc}
   */
  public StateUpdateFailurePolicy getStateUpdateFailurePolicy() {
    return pStateUpdateFailurePolicy;
  }
 
  /**
   * {@inheritDoc}
   */
  public Class<? extends PasswordPolicyCfg> configurationClass() {
    return PasswordPolicyCfg.class;
  }
 
  /**
   * {@inheritDoc}
   */
  public DN dn() {
    return passwordPolicySubentryDN;
  }
}