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