001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 */
026package org.forgerock.opendj.server.config.meta;
027
028
029
030import java.util.Collection;
031import java.util.SortedSet;
032import org.forgerock.opendj.config.AdministratorAction;
033import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
034import org.forgerock.opendj.config.AttributeTypePropertyDefinition;
035import org.forgerock.opendj.config.BooleanPropertyDefinition;
036import org.forgerock.opendj.config.ClassPropertyDefinition;
037import org.forgerock.opendj.config.client.ConcurrentModificationException;
038import org.forgerock.opendj.config.client.ManagedObject;
039import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
040import org.forgerock.opendj.config.client.OperationRejectedException;
041import org.forgerock.opendj.config.DefaultBehaviorProvider;
042import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
043import org.forgerock.opendj.config.IntegerPropertyDefinition;
044import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
045import org.forgerock.opendj.config.ManagedObjectDefinition;
046import org.forgerock.opendj.config.PropertyOption;
047import org.forgerock.opendj.config.PropertyProvider;
048import org.forgerock.opendj.config.server.ConfigurationChangeListener;
049import org.forgerock.opendj.config.server.ServerManagedObject;
050import org.forgerock.opendj.config.Tag;
051import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
052import org.forgerock.opendj.ldap.DN;
053import org.forgerock.opendj.ldap.LdapException;
054import org.forgerock.opendj.ldap.schema.AttributeType;
055import org.forgerock.opendj.server.config.client.AttributeValuePasswordValidatorCfgClient;
056import org.forgerock.opendj.server.config.server.AttributeValuePasswordValidatorCfg;
057import org.forgerock.opendj.server.config.server.PasswordValidatorCfg;
058
059
060
061/**
062 * An interface for querying the Attribute Value Password Validator
063 * managed object definition meta information.
064 * <p>
065 * The Attribute Value Password Validator attempts to determine
066 * whether a proposed password is acceptable for use by determining
067 * whether that password is contained in any attribute within the
068 * user's entry.
069 */
070public final class AttributeValuePasswordValidatorCfgDefn extends ManagedObjectDefinition<AttributeValuePasswordValidatorCfgClient, AttributeValuePasswordValidatorCfg> {
071
072  /** The singleton configuration definition instance. */
073  private static final AttributeValuePasswordValidatorCfgDefn INSTANCE = new AttributeValuePasswordValidatorCfgDefn();
074
075
076
077  /** The "check-substrings" property definition. */
078  private static final BooleanPropertyDefinition PD_CHECK_SUBSTRINGS;
079
080
081
082  /** The "java-class" property definition. */
083  private static final ClassPropertyDefinition PD_JAVA_CLASS;
084
085
086
087  /** The "match-attribute" property definition. */
088  private static final AttributeTypePropertyDefinition PD_MATCH_ATTRIBUTE;
089
090
091
092  /** The "min-substring-length" property definition. */
093  private static final IntegerPropertyDefinition PD_MIN_SUBSTRING_LENGTH;
094
095
096
097  /** The "test-reversed-password" property definition. */
098  private static final BooleanPropertyDefinition PD_TEST_REVERSED_PASSWORD;
099
100
101
102  /** Build the "check-substrings" property definition. */
103  static {
104      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "check-substrings");
105      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "check-substrings"));
106      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
107      builder.setDefaultBehaviorProvider(provider);
108      PD_CHECK_SUBSTRINGS = builder.getInstance();
109      INSTANCE.registerPropertyDefinition(PD_CHECK_SUBSTRINGS);
110  }
111
112
113
114  /** Build the "java-class" property definition. */
115  static {
116      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
117      builder.setOption(PropertyOption.MANDATORY);
118      builder.setOption(PropertyOption.ADVANCED);
119      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
120      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.AttributeValuePasswordValidator");
121      builder.setDefaultBehaviorProvider(provider);
122      builder.addInstanceOf("org.opends.server.api.PasswordValidator");
123      PD_JAVA_CLASS = builder.getInstance();
124      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
125  }
126
127
128
129  /** Build the "match-attribute" property definition. */
130  static {
131      AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "match-attribute");
132      builder.setOption(PropertyOption.MULTI_VALUED);
133      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-attribute"));
134      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<AttributeType>(INSTANCE, "match-attribute"));
135      PD_MATCH_ATTRIBUTE = builder.getInstance();
136      INSTANCE.registerPropertyDefinition(PD_MATCH_ATTRIBUTE);
137  }
138
139
140
141  /** Build the "min-substring-length" property definition. */
142  static {
143      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-substring-length");
144      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-substring-length"));
145      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("5");
146      builder.setDefaultBehaviorProvider(provider);
147      PD_MIN_SUBSTRING_LENGTH = builder.getInstance();
148      INSTANCE.registerPropertyDefinition(PD_MIN_SUBSTRING_LENGTH);
149  }
150
151
152
153  /** Build the "test-reversed-password" property definition. */
154  static {
155      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "test-reversed-password");
156      builder.setOption(PropertyOption.MANDATORY);
157      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "test-reversed-password"));
158      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
159      PD_TEST_REVERSED_PASSWORD = builder.getInstance();
160      INSTANCE.registerPropertyDefinition(PD_TEST_REVERSED_PASSWORD);
161  }
162
163
164
165  // Register the tags associated with this managed object definition.
166  static {
167    INSTANCE.registerTag(Tag.valueOf("user-management"));
168  }
169
170
171
172  /**
173   * Get the Attribute Value Password Validator configuration
174   * definition singleton.
175   *
176   * @return Returns the Attribute Value Password Validator
177   *         configuration definition singleton.
178   */
179  public static AttributeValuePasswordValidatorCfgDefn getInstance() {
180    return INSTANCE;
181  }
182
183
184
185  /**
186   * Private constructor.
187   */
188  private AttributeValuePasswordValidatorCfgDefn() {
189    super("attribute-value-password-validator", PasswordValidatorCfgDefn.getInstance());
190  }
191
192
193
194  /** {@inheritDoc} */
195  public AttributeValuePasswordValidatorCfgClient createClientConfiguration(
196      ManagedObject<? extends AttributeValuePasswordValidatorCfgClient> impl) {
197    return new AttributeValuePasswordValidatorCfgClientImpl(impl);
198  }
199
200
201
202  /** {@inheritDoc} */
203  public AttributeValuePasswordValidatorCfg createServerConfiguration(
204      ServerManagedObject<? extends AttributeValuePasswordValidatorCfg> impl) {
205    return new AttributeValuePasswordValidatorCfgServerImpl(impl);
206  }
207
208
209
210  /** {@inheritDoc} */
211  public Class<AttributeValuePasswordValidatorCfg> getServerConfigurationClass() {
212    return AttributeValuePasswordValidatorCfg.class;
213  }
214
215
216
217  /**
218   * Get the "check-substrings" property definition.
219   * <p>
220   * Indicates whether this password validator is to match portions of
221   * the password string against attribute values.
222   * <p>
223   * If "false" then only match the entire password against attribute
224   * values otherwise ("true") check whether the password contains
225   * attribute values.
226   *
227   * @return Returns the "check-substrings" property definition.
228   */
229  public BooleanPropertyDefinition getCheckSubstringsPropertyDefinition() {
230    return PD_CHECK_SUBSTRINGS;
231  }
232
233
234
235  /**
236   * Get the "enabled" property definition.
237   * <p>
238   * Indicates whether the password validator is enabled for use.
239   *
240   * @return Returns the "enabled" property definition.
241   */
242  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
243    return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
244  }
245
246
247
248  /**
249   * Get the "java-class" property definition.
250   * <p>
251   * Specifies the fully-qualified name of the Java class that
252   * provides the password validator implementation.
253   *
254   * @return Returns the "java-class" property definition.
255   */
256  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
257    return PD_JAVA_CLASS;
258  }
259
260
261
262  /**
263   * Get the "match-attribute" property definition.
264   * <p>
265   * Specifies the name(s) of the attribute(s) whose values should be
266   * checked to determine whether they match the provided password. If
267   * no values are provided, then the server checks if the proposed
268   * password matches the value of any attribute in the user's entry.
269   *
270   * @return Returns the "match-attribute" property definition.
271   */
272  public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() {
273    return PD_MATCH_ATTRIBUTE;
274  }
275
276
277
278  /**
279   * Get the "min-substring-length" property definition.
280   * <p>
281   * Indicates the minimal length of the substring within the password
282   * in case substring checking is enabled.
283   * <p>
284   * If "check-substrings" option is set to true, then this parameter
285   * defines the length of the smallest word which should be used for
286   * substring matching. Use with caution because values below 3 might
287   * disqualify valid passwords.
288   *
289   * @return Returns the "min-substring-length" property definition.
290   */
291  public IntegerPropertyDefinition getMinSubstringLengthPropertyDefinition() {
292    return PD_MIN_SUBSTRING_LENGTH;
293  }
294
295
296
297  /**
298   * Get the "test-reversed-password" property definition.
299   * <p>
300   * Indicates whether this password validator should test the
301   * reversed value of the provided password as well as the order in
302   * which it was given.
303   *
304   * @return Returns the "test-reversed-password" property definition.
305   */
306  public BooleanPropertyDefinition getTestReversedPasswordPropertyDefinition() {
307    return PD_TEST_REVERSED_PASSWORD;
308  }
309
310
311
312  /**
313   * Managed object client implementation.
314   */
315  private static class AttributeValuePasswordValidatorCfgClientImpl implements
316    AttributeValuePasswordValidatorCfgClient {
317
318    /** Private implementation. */
319    private ManagedObject<? extends AttributeValuePasswordValidatorCfgClient> impl;
320
321
322
323    /** Private constructor. */
324    private AttributeValuePasswordValidatorCfgClientImpl(
325        ManagedObject<? extends AttributeValuePasswordValidatorCfgClient> impl) {
326      this.impl = impl;
327    }
328
329
330
331    /** {@inheritDoc} */
332    public boolean isCheckSubstrings() {
333      return impl.getPropertyValue(INSTANCE.getCheckSubstringsPropertyDefinition());
334    }
335
336
337
338    /** {@inheritDoc} */
339    public void setCheckSubstrings(Boolean value) {
340      impl.setPropertyValue(INSTANCE.getCheckSubstringsPropertyDefinition(), value);
341    }
342
343
344
345    /** {@inheritDoc} */
346    public Boolean isEnabled() {
347      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
348    }
349
350
351
352    /** {@inheritDoc} */
353    public void setEnabled(boolean value) {
354      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
355    }
356
357
358
359    /** {@inheritDoc} */
360    public String getJavaClass() {
361      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
362    }
363
364
365
366    /** {@inheritDoc} */
367    public void setJavaClass(String value) {
368      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
369    }
370
371
372
373    /** {@inheritDoc} */
374    public SortedSet<AttributeType> getMatchAttribute() {
375      return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
376    }
377
378
379
380    /** {@inheritDoc} */
381    public void setMatchAttribute(Collection<AttributeType> values) {
382      impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values);
383    }
384
385
386
387    /** {@inheritDoc} */
388    public int getMinSubstringLength() {
389      return impl.getPropertyValue(INSTANCE.getMinSubstringLengthPropertyDefinition());
390    }
391
392
393
394    /** {@inheritDoc} */
395    public void setMinSubstringLength(Integer value) {
396      impl.setPropertyValue(INSTANCE.getMinSubstringLengthPropertyDefinition(), value);
397    }
398
399
400
401    /** {@inheritDoc} */
402    public Boolean isTestReversedPassword() {
403      return impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
404    }
405
406
407
408    /** {@inheritDoc} */
409    public void setTestReversedPassword(boolean value) {
410      impl.setPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition(), value);
411    }
412
413
414
415    /** {@inheritDoc} */
416    public ManagedObjectDefinition<? extends AttributeValuePasswordValidatorCfgClient, ? extends AttributeValuePasswordValidatorCfg> definition() {
417      return INSTANCE;
418    }
419
420
421
422    /** {@inheritDoc} */
423    public PropertyProvider properties() {
424      return impl;
425    }
426
427
428
429    /** {@inheritDoc} */
430    public void commit() throws ManagedObjectAlreadyExistsException,
431        MissingMandatoryPropertiesException, ConcurrentModificationException,
432        OperationRejectedException, LdapException {
433      impl.commit();
434    }
435
436
437
438    /** {@inheritDoc} */
439    public String toString() {
440      return impl.toString();
441    }
442  }
443
444
445
446  /**
447   * Managed object server implementation.
448   */
449  private static class AttributeValuePasswordValidatorCfgServerImpl implements
450    AttributeValuePasswordValidatorCfg {
451
452    /** Private implementation. */
453    private ServerManagedObject<? extends AttributeValuePasswordValidatorCfg> impl;
454
455    /** The value of the "check-substrings" property. */
456    private final boolean pCheckSubstrings;
457
458    /** The value of the "enabled" property. */
459    private final boolean pEnabled;
460
461    /** The value of the "java-class" property. */
462    private final String pJavaClass;
463
464    /** The value of the "match-attribute" property. */
465    private final SortedSet<AttributeType> pMatchAttribute;
466
467    /** The value of the "min-substring-length" property. */
468    private final int pMinSubstringLength;
469
470    /** The value of the "test-reversed-password" property. */
471    private final boolean pTestReversedPassword;
472
473
474
475    /** Private constructor. */
476    private AttributeValuePasswordValidatorCfgServerImpl(ServerManagedObject<? extends AttributeValuePasswordValidatorCfg> impl) {
477      this.impl = impl;
478      this.pCheckSubstrings = impl.getPropertyValue(INSTANCE.getCheckSubstringsPropertyDefinition());
479      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
480      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
481      this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
482      this.pMinSubstringLength = impl.getPropertyValue(INSTANCE.getMinSubstringLengthPropertyDefinition());
483      this.pTestReversedPassword = impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
484    }
485
486
487
488    /** {@inheritDoc} */
489    public void addAttributeValueChangeListener(
490        ConfigurationChangeListener<AttributeValuePasswordValidatorCfg> listener) {
491      impl.registerChangeListener(listener);
492    }
493
494
495
496    /** {@inheritDoc} */
497    public void removeAttributeValueChangeListener(
498        ConfigurationChangeListener<AttributeValuePasswordValidatorCfg> listener) {
499      impl.deregisterChangeListener(listener);
500    }
501    /** {@inheritDoc} */
502    public void addChangeListener(
503        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
504      impl.registerChangeListener(listener);
505    }
506
507
508
509    /** {@inheritDoc} */
510    public void removeChangeListener(
511        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
512      impl.deregisterChangeListener(listener);
513    }
514
515
516
517    /** {@inheritDoc} */
518    public boolean isCheckSubstrings() {
519      return pCheckSubstrings;
520    }
521
522
523
524    /** {@inheritDoc} */
525    public boolean isEnabled() {
526      return pEnabled;
527    }
528
529
530
531    /** {@inheritDoc} */
532    public String getJavaClass() {
533      return pJavaClass;
534    }
535
536
537
538    /** {@inheritDoc} */
539    public SortedSet<AttributeType> getMatchAttribute() {
540      return pMatchAttribute;
541    }
542
543
544
545    /** {@inheritDoc} */
546    public int getMinSubstringLength() {
547      return pMinSubstringLength;
548    }
549
550
551
552    /** {@inheritDoc} */
553    public boolean isTestReversedPassword() {
554      return pTestReversedPassword;
555    }
556
557
558
559    /** {@inheritDoc} */
560    public Class<? extends AttributeValuePasswordValidatorCfg> configurationClass() {
561      return AttributeValuePasswordValidatorCfg.class;
562    }
563
564
565
566    /** {@inheritDoc} */
567    public DN dn() {
568      return impl.getDN();
569    }
570
571
572
573    /** {@inheritDoc} */
574    public String toString() {
575      return impl.toString();
576    }
577  }
578}