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 2008 Sun Microsystems, Inc.
015 */
016package org.opends.server.admin.std.meta;
017
018
019
020import org.forgerock.opendj.ldap.DN;
021import org.opends.server.admin.AdministratorAction;
022import org.opends.server.admin.BooleanPropertyDefinition;
023import org.opends.server.admin.ClassPropertyDefinition;
024import org.opends.server.admin.client.AuthorizationException;
025import org.opends.server.admin.client.CommunicationException;
026import org.opends.server.admin.client.ConcurrentModificationException;
027import org.opends.server.admin.client.ManagedObject;
028import org.opends.server.admin.client.MissingMandatoryPropertiesException;
029import org.opends.server.admin.client.OperationRejectedException;
030import org.opends.server.admin.DefaultBehaviorProvider;
031import org.opends.server.admin.DefinedDefaultBehaviorProvider;
032import org.opends.server.admin.IntegerPropertyDefinition;
033import org.opends.server.admin.ManagedObjectAlreadyExistsException;
034import org.opends.server.admin.ManagedObjectDefinition;
035import org.opends.server.admin.PropertyOption;
036import org.opends.server.admin.PropertyProvider;
037import org.opends.server.admin.server.ConfigurationChangeListener;
038import org.opends.server.admin.server.ServerManagedObject;
039import org.opends.server.admin.std.client.DictionaryPasswordValidatorCfgClient;
040import org.opends.server.admin.std.server.DictionaryPasswordValidatorCfg;
041import org.opends.server.admin.std.server.PasswordValidatorCfg;
042import org.opends.server.admin.StringPropertyDefinition;
043import org.opends.server.admin.Tag;
044
045
046
047/**
048 * An interface for querying the Dictionary Password Validator managed
049 * object definition meta information.
050 * <p>
051 * The Dictionary Password Validator determines whether a proposed
052 * password is acceptable based on whether the given password value
053 * appears in a provided dictionary file.
054 */
055public final class DictionaryPasswordValidatorCfgDefn extends ManagedObjectDefinition<DictionaryPasswordValidatorCfgClient, DictionaryPasswordValidatorCfg> {
056
057  // The singleton configuration definition instance.
058  private static final DictionaryPasswordValidatorCfgDefn INSTANCE = new DictionaryPasswordValidatorCfgDefn();
059
060
061
062  // The "case-sensitive-validation" property definition.
063  private static final BooleanPropertyDefinition PD_CASE_SENSITIVE_VALIDATION;
064
065
066
067  // The "check-substrings" property definition.
068  private static final BooleanPropertyDefinition PD_CHECK_SUBSTRINGS;
069
070
071
072  // The "dictionary-file" property definition.
073  private static final StringPropertyDefinition PD_DICTIONARY_FILE;
074
075
076
077  // The "java-class" property definition.
078  private static final ClassPropertyDefinition PD_JAVA_CLASS;
079
080
081
082  // The "min-substring-length" property definition.
083  private static final IntegerPropertyDefinition PD_MIN_SUBSTRING_LENGTH;
084
085
086
087  // The "test-reversed-password" property definition.
088  private static final BooleanPropertyDefinition PD_TEST_REVERSED_PASSWORD;
089
090
091
092  // Build the "case-sensitive-validation" property definition.
093  static {
094      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "case-sensitive-validation");
095      builder.setOption(PropertyOption.MANDATORY);
096      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "case-sensitive-validation"));
097      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false");
098      builder.setDefaultBehaviorProvider(provider);
099      PD_CASE_SENSITIVE_VALIDATION = builder.getInstance();
100      INSTANCE.registerPropertyDefinition(PD_CASE_SENSITIVE_VALIDATION);
101  }
102
103
104
105  // Build the "check-substrings" property definition.
106  static {
107      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "check-substrings");
108      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "check-substrings"));
109      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
110      builder.setDefaultBehaviorProvider(provider);
111      PD_CHECK_SUBSTRINGS = builder.getInstance();
112      INSTANCE.registerPropertyDefinition(PD_CHECK_SUBSTRINGS);
113  }
114
115
116
117  // Build the "dictionary-file" property definition.
118  static {
119      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "dictionary-file");
120      builder.setOption(PropertyOption.MANDATORY);
121      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "dictionary-file"));
122      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("For Unix and Linux systems: config/wordlist.txt. For Windows systems: config\\wordlist.txt");
123      builder.setDefaultBehaviorProvider(provider);
124      builder.setPattern(".*", "FILE");
125      PD_DICTIONARY_FILE = builder.getInstance();
126      INSTANCE.registerPropertyDefinition(PD_DICTIONARY_FILE);
127  }
128
129
130
131  // Build the "java-class" property definition.
132  static {
133      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
134      builder.setOption(PropertyOption.MANDATORY);
135      builder.setOption(PropertyOption.ADVANCED);
136      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
137      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.DictionaryPasswordValidator");
138      builder.setDefaultBehaviorProvider(provider);
139      builder.addInstanceOf("org.opends.server.api.PasswordValidator");
140      PD_JAVA_CLASS = builder.getInstance();
141      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
142  }
143
144
145
146  // Build the "min-substring-length" property definition.
147  static {
148      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-substring-length");
149      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-substring-length"));
150      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("5");
151      builder.setDefaultBehaviorProvider(provider);
152      PD_MIN_SUBSTRING_LENGTH = builder.getInstance();
153      INSTANCE.registerPropertyDefinition(PD_MIN_SUBSTRING_LENGTH);
154  }
155
156
157
158  // Build the "test-reversed-password" property definition.
159  static {
160      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "test-reversed-password");
161      builder.setOption(PropertyOption.MANDATORY);
162      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "test-reversed-password"));
163      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
164      builder.setDefaultBehaviorProvider(provider);
165      PD_TEST_REVERSED_PASSWORD = builder.getInstance();
166      INSTANCE.registerPropertyDefinition(PD_TEST_REVERSED_PASSWORD);
167  }
168
169
170
171  // Register the tags associated with this managed object definition.
172  static {
173    INSTANCE.registerTag(Tag.valueOf("user-management"));
174  }
175
176
177
178  /**
179   * Get the Dictionary Password Validator configuration definition
180   * singleton.
181   *
182   * @return Returns the Dictionary Password Validator configuration
183   *         definition singleton.
184   */
185  public static DictionaryPasswordValidatorCfgDefn getInstance() {
186    return INSTANCE;
187  }
188
189
190
191  /**
192   * Private constructor.
193   */
194  private DictionaryPasswordValidatorCfgDefn() {
195    super("dictionary-password-validator", PasswordValidatorCfgDefn.getInstance());
196  }
197
198
199
200  /**
201   * {@inheritDoc}
202   */
203  public DictionaryPasswordValidatorCfgClient createClientConfiguration(
204      ManagedObject<? extends DictionaryPasswordValidatorCfgClient> impl) {
205    return new DictionaryPasswordValidatorCfgClientImpl(impl);
206  }
207
208
209
210  /**
211   * {@inheritDoc}
212   */
213  public DictionaryPasswordValidatorCfg createServerConfiguration(
214      ServerManagedObject<? extends DictionaryPasswordValidatorCfg> impl) {
215    return new DictionaryPasswordValidatorCfgServerImpl(impl);
216  }
217
218
219
220  /**
221   * {@inheritDoc}
222   */
223  public Class<DictionaryPasswordValidatorCfg> getServerConfigurationClass() {
224    return DictionaryPasswordValidatorCfg.class;
225  }
226
227
228
229  /**
230   * Get the "case-sensitive-validation" property definition.
231   * <p>
232   * Indicates whether this password validator is to treat password
233   * characters in a case-sensitive manner.
234   * <p>
235   * If it is set to true, then the validator rejects a password only
236   * if it appears in the dictionary with exactly the same
237   * capitalization as provided by the user.
238   *
239   * @return Returns the "case-sensitive-validation" property definition.
240   */
241  public BooleanPropertyDefinition getCaseSensitiveValidationPropertyDefinition() {
242    return PD_CASE_SENSITIVE_VALIDATION;
243  }
244
245
246
247  /**
248   * Get the "check-substrings" property definition.
249   * <p>
250   * Indicates whether this password validator is to match portions of
251   * the password string against dictionary words.
252   * <p>
253   * If "false" then only match the entire password against words
254   * otherwise ("true") check whether the password contains words.
255   *
256   * @return Returns the "check-substrings" property definition.
257   */
258  public BooleanPropertyDefinition getCheckSubstringsPropertyDefinition() {
259    return PD_CHECK_SUBSTRINGS;
260  }
261
262
263
264  /**
265   * Get the "dictionary-file" property definition.
266   * <p>
267   * Specifies the path to the file containing a list of words that
268   * cannot be used as passwords.
269   * <p>
270   * It should be formatted with one word per line. The value can be
271   * an absolute path or a path that is relative to the OpenDJ instance
272   * root.
273   *
274   * @return Returns the "dictionary-file" property definition.
275   */
276  public StringPropertyDefinition getDictionaryFilePropertyDefinition() {
277    return PD_DICTIONARY_FILE;
278  }
279
280
281
282  /**
283   * Get the "enabled" property definition.
284   * <p>
285   * Indicates whether the password validator is enabled for use.
286   *
287   * @return Returns the "enabled" property definition.
288   */
289  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
290    return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
291  }
292
293
294
295  /**
296   * Get the "java-class" property definition.
297   * <p>
298   * Specifies the fully-qualified name of the Java class that
299   * provides the password validator implementation.
300   *
301   * @return Returns the "java-class" property definition.
302   */
303  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
304    return PD_JAVA_CLASS;
305  }
306
307
308
309  /**
310   * Get the "min-substring-length" property definition.
311   * <p>
312   * Indicates the minimal length of the substring within the password
313   * in case substring checking is enabled.
314   * <p>
315   * If "check-substrings" option is set to true, then this parameter
316   * defines the length of the smallest word which should be used for
317   * substring matching. Use with caution because values below 3 might
318   * disqualify valid passwords.
319   *
320   * @return Returns the "min-substring-length" property definition.
321   */
322  public IntegerPropertyDefinition getMinSubstringLengthPropertyDefinition() {
323    return PD_MIN_SUBSTRING_LENGTH;
324  }
325
326
327
328  /**
329   * Get the "test-reversed-password" property definition.
330   * <p>
331   * Indicates whether this password validator is to test the reversed
332   * value of the provided password as well as the order in which it
333   * was given.
334   * <p>
335   * For example, if the user provides a new password of "password"
336   * and this configuration attribute is set to true, then the value
337   * "drowssap" is also tested against attribute values in the user's
338   * entry.
339   *
340   * @return Returns the "test-reversed-password" property definition.
341   */
342  public BooleanPropertyDefinition getTestReversedPasswordPropertyDefinition() {
343    return PD_TEST_REVERSED_PASSWORD;
344  }
345
346
347
348  /**
349   * Managed object client implementation.
350   */
351  private static class DictionaryPasswordValidatorCfgClientImpl implements
352    DictionaryPasswordValidatorCfgClient {
353
354    // Private implementation.
355    private ManagedObject<? extends DictionaryPasswordValidatorCfgClient> impl;
356
357
358
359    // Private constructor.
360    private DictionaryPasswordValidatorCfgClientImpl(
361        ManagedObject<? extends DictionaryPasswordValidatorCfgClient> impl) {
362      this.impl = impl;
363    }
364
365
366
367    /**
368     * {@inheritDoc}
369     */
370    public boolean isCaseSensitiveValidation() {
371      return impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
372    }
373
374
375
376    /**
377     * {@inheritDoc}
378     */
379    public void setCaseSensitiveValidation(boolean value) {
380      impl.setPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition(), value);
381    }
382
383
384
385    /**
386     * {@inheritDoc}
387     */
388    public boolean isCheckSubstrings() {
389      return impl.getPropertyValue(INSTANCE.getCheckSubstringsPropertyDefinition());
390    }
391
392
393
394    /**
395     * {@inheritDoc}
396     */
397    public void setCheckSubstrings(Boolean value) {
398      impl.setPropertyValue(INSTANCE.getCheckSubstringsPropertyDefinition(), value);
399    }
400
401
402
403    /**
404     * {@inheritDoc}
405     */
406    public String getDictionaryFile() {
407      return impl.getPropertyValue(INSTANCE.getDictionaryFilePropertyDefinition());
408    }
409
410
411
412    /**
413     * {@inheritDoc}
414     */
415    public void setDictionaryFile(String value) {
416      impl.setPropertyValue(INSTANCE.getDictionaryFilePropertyDefinition(), value);
417    }
418
419
420
421    /**
422     * {@inheritDoc}
423     */
424    public Boolean isEnabled() {
425      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
426    }
427
428
429
430    /**
431     * {@inheritDoc}
432     */
433    public void setEnabled(boolean value) {
434      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
435    }
436
437
438
439    /**
440     * {@inheritDoc}
441     */
442    public String getJavaClass() {
443      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
444    }
445
446
447
448    /**
449     * {@inheritDoc}
450     */
451    public void setJavaClass(String value) {
452      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
453    }
454
455
456
457    /**
458     * {@inheritDoc}
459     */
460    public int getMinSubstringLength() {
461      return impl.getPropertyValue(INSTANCE.getMinSubstringLengthPropertyDefinition());
462    }
463
464
465
466    /**
467     * {@inheritDoc}
468     */
469    public void setMinSubstringLength(Integer value) {
470      impl.setPropertyValue(INSTANCE.getMinSubstringLengthPropertyDefinition(), value);
471    }
472
473
474
475    /**
476     * {@inheritDoc}
477     */
478    public boolean isTestReversedPassword() {
479      return impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
480    }
481
482
483
484    /**
485     * {@inheritDoc}
486     */
487    public void setTestReversedPassword(boolean value) {
488      impl.setPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition(), value);
489    }
490
491
492
493    /**
494     * {@inheritDoc}
495     */
496    public ManagedObjectDefinition<? extends DictionaryPasswordValidatorCfgClient, ? extends DictionaryPasswordValidatorCfg> definition() {
497      return INSTANCE;
498    }
499
500
501
502    /**
503     * {@inheritDoc}
504     */
505    public PropertyProvider properties() {
506      return impl;
507    }
508
509
510
511    /**
512     * {@inheritDoc}
513     */
514    public void commit() throws ManagedObjectAlreadyExistsException,
515        MissingMandatoryPropertiesException, ConcurrentModificationException,
516        OperationRejectedException, AuthorizationException,
517        CommunicationException {
518      impl.commit();
519    }
520
521
522
523    /** {@inheritDoc} */
524    public String toString() {
525      return impl.toString();
526    }
527  }
528
529
530
531  /**
532   * Managed object server implementation.
533   */
534  private static class DictionaryPasswordValidatorCfgServerImpl implements
535    DictionaryPasswordValidatorCfg {
536
537    // Private implementation.
538    private ServerManagedObject<? extends DictionaryPasswordValidatorCfg> impl;
539
540    // The value of the "case-sensitive-validation" property.
541    private final boolean pCaseSensitiveValidation;
542
543    // The value of the "check-substrings" property.
544    private final boolean pCheckSubstrings;
545
546    // The value of the "dictionary-file" property.
547    private final String pDictionaryFile;
548
549    // The value of the "enabled" property.
550    private final boolean pEnabled;
551
552    // The value of the "java-class" property.
553    private final String pJavaClass;
554
555    // The value of the "min-substring-length" property.
556    private final int pMinSubstringLength;
557
558    // The value of the "test-reversed-password" property.
559    private final boolean pTestReversedPassword;
560
561
562
563    // Private constructor.
564    private DictionaryPasswordValidatorCfgServerImpl(ServerManagedObject<? extends DictionaryPasswordValidatorCfg> impl) {
565      this.impl = impl;
566      this.pCaseSensitiveValidation = impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
567      this.pCheckSubstrings = impl.getPropertyValue(INSTANCE.getCheckSubstringsPropertyDefinition());
568      this.pDictionaryFile = impl.getPropertyValue(INSTANCE.getDictionaryFilePropertyDefinition());
569      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
570      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
571      this.pMinSubstringLength = impl.getPropertyValue(INSTANCE.getMinSubstringLengthPropertyDefinition());
572      this.pTestReversedPassword = impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
573    }
574
575
576
577    /**
578     * {@inheritDoc}
579     */
580    public void addDictionaryChangeListener(
581        ConfigurationChangeListener<DictionaryPasswordValidatorCfg> listener) {
582      impl.registerChangeListener(listener);
583    }
584
585
586
587    /**
588     * {@inheritDoc}
589     */
590    public void removeDictionaryChangeListener(
591        ConfigurationChangeListener<DictionaryPasswordValidatorCfg> listener) {
592      impl.deregisterChangeListener(listener);
593    }
594    /**
595     * {@inheritDoc}
596     */
597    public void addChangeListener(
598        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
599      impl.registerChangeListener(listener);
600    }
601
602
603
604    /**
605     * {@inheritDoc}
606     */
607    public void removeChangeListener(
608        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
609      impl.deregisterChangeListener(listener);
610    }
611
612
613
614    /**
615     * {@inheritDoc}
616     */
617    public boolean isCaseSensitiveValidation() {
618      return pCaseSensitiveValidation;
619    }
620
621
622
623    /**
624     * {@inheritDoc}
625     */
626    public boolean isCheckSubstrings() {
627      return pCheckSubstrings;
628    }
629
630
631
632    /**
633     * {@inheritDoc}
634     */
635    public String getDictionaryFile() {
636      return pDictionaryFile;
637    }
638
639
640
641    /**
642     * {@inheritDoc}
643     */
644    public boolean isEnabled() {
645      return pEnabled;
646    }
647
648
649
650    /**
651     * {@inheritDoc}
652     */
653    public String getJavaClass() {
654      return pJavaClass;
655    }
656
657
658
659    /**
660     * {@inheritDoc}
661     */
662    public int getMinSubstringLength() {
663      return pMinSubstringLength;
664    }
665
666
667
668    /**
669     * {@inheritDoc}
670     */
671    public boolean isTestReversedPassword() {
672      return pTestReversedPassword;
673    }
674
675
676
677    /**
678     * {@inheritDoc}
679     */
680    public Class<? extends DictionaryPasswordValidatorCfg> configurationClass() {
681      return DictionaryPasswordValidatorCfg.class;
682    }
683
684
685
686    /**
687     * {@inheritDoc}
688     */
689    public DN dn() {
690      return impl.getDN();
691    }
692
693
694
695    /** {@inheritDoc} */
696    public String toString() {
697      return impl.toString();
698    }
699  }
700}