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 org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.DefaultBehaviorProvider;
038import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
039import org.forgerock.opendj.config.IntegerPropertyDefinition;
040import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
041import org.forgerock.opendj.config.ManagedObjectDefinition;
042import org.forgerock.opendj.config.PropertyOption;
043import org.forgerock.opendj.config.PropertyProvider;
044import org.forgerock.opendj.config.server.ConfigurationChangeListener;
045import org.forgerock.opendj.config.server.ServerManagedObject;
046import org.forgerock.opendj.config.Tag;
047import org.forgerock.opendj.ldap.DN;
048import org.forgerock.opendj.ldap.LdapException;
049import org.forgerock.opendj.server.config.client.LengthBasedPasswordValidatorCfgClient;
050import org.forgerock.opendj.server.config.server.LengthBasedPasswordValidatorCfg;
051import org.forgerock.opendj.server.config.server.PasswordValidatorCfg;
052
053
054
055/**
056 * An interface for querying the Length Based Password Validator
057 * managed object definition meta information.
058 * <p>
059 * The Length Based Password Validator is used to determine whether a
060 * proposed password is acceptable based on whether the number of
061 * characters it contains falls within an acceptable range of values.
062 */
063public final class LengthBasedPasswordValidatorCfgDefn extends ManagedObjectDefinition<LengthBasedPasswordValidatorCfgClient, LengthBasedPasswordValidatorCfg> {
064
065  // The singleton configuration definition instance.
066  private static final LengthBasedPasswordValidatorCfgDefn INSTANCE = new LengthBasedPasswordValidatorCfgDefn();
067
068
069
070  // The "java-class" property definition.
071  private static final ClassPropertyDefinition PD_JAVA_CLASS;
072
073
074
075  // The "max-password-length" property definition.
076  private static final IntegerPropertyDefinition PD_MAX_PASSWORD_LENGTH;
077
078
079
080  // The "min-password-length" property definition.
081  private static final IntegerPropertyDefinition PD_MIN_PASSWORD_LENGTH;
082
083
084
085  // Build the "java-class" property definition.
086  static {
087      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
088      builder.setOption(PropertyOption.MANDATORY);
089      builder.setOption(PropertyOption.ADVANCED);
090      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
091      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.LengthBasedPasswordValidator");
092      builder.setDefaultBehaviorProvider(provider);
093      builder.addInstanceOf("org.opends.server.api.PasswordValidator");
094      PD_JAVA_CLASS = builder.getInstance();
095      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
096  }
097
098
099
100  // Build the "max-password-length" property definition.
101  static {
102      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-password-length");
103      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-password-length"));
104      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("0");
105      builder.setDefaultBehaviorProvider(provider);
106      builder.setUpperLimit(2147483647);
107      builder.setLowerLimit(0);
108      PD_MAX_PASSWORD_LENGTH = builder.getInstance();
109      INSTANCE.registerPropertyDefinition(PD_MAX_PASSWORD_LENGTH);
110  }
111
112
113
114  // Build the "min-password-length" property definition.
115  static {
116      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-password-length");
117      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-password-length"));
118      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("6");
119      builder.setDefaultBehaviorProvider(provider);
120      builder.setUpperLimit(2147483647);
121      builder.setLowerLimit(0);
122      PD_MIN_PASSWORD_LENGTH = builder.getInstance();
123      INSTANCE.registerPropertyDefinition(PD_MIN_PASSWORD_LENGTH);
124  }
125
126
127
128  // Register the tags associated with this managed object definition.
129  static {
130    INSTANCE.registerTag(Tag.valueOf("user-management"));
131  }
132
133
134
135  /**
136   * Get the Length Based Password Validator configuration definition
137   * singleton.
138   *
139   * @return Returns the Length Based Password Validator configuration
140   *         definition singleton.
141   */
142  public static LengthBasedPasswordValidatorCfgDefn getInstance() {
143    return INSTANCE;
144  }
145
146
147
148  /**
149   * Private constructor.
150   */
151  private LengthBasedPasswordValidatorCfgDefn() {
152    super("length-based-password-validator", PasswordValidatorCfgDefn.getInstance());
153  }
154
155
156
157  /**
158   * {@inheritDoc}
159   */
160  public LengthBasedPasswordValidatorCfgClient createClientConfiguration(
161      ManagedObject<? extends LengthBasedPasswordValidatorCfgClient> impl) {
162    return new LengthBasedPasswordValidatorCfgClientImpl(impl);
163  }
164
165
166
167  /**
168   * {@inheritDoc}
169   */
170  public LengthBasedPasswordValidatorCfg createServerConfiguration(
171      ServerManagedObject<? extends LengthBasedPasswordValidatorCfg> impl) {
172    return new LengthBasedPasswordValidatorCfgServerImpl(impl);
173  }
174
175
176
177  /**
178   * {@inheritDoc}
179   */
180  public Class<LengthBasedPasswordValidatorCfg> getServerConfigurationClass() {
181    return LengthBasedPasswordValidatorCfg.class;
182  }
183
184
185
186  /**
187   * Get the "enabled" property definition.
188   * <p>
189   * Indicates whether the password validator is enabled for use.
190   *
191   * @return Returns the "enabled" property definition.
192   */
193  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
194    return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
195  }
196
197
198
199  /**
200   * Get the "java-class" property definition.
201   * <p>
202   * Specifies the fully-qualified name of the Java class that
203   * provides the password validator implementation.
204   *
205   * @return Returns the "java-class" property definition.
206   */
207  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
208    return PD_JAVA_CLASS;
209  }
210
211
212
213  /**
214   * Get the "max-password-length" property definition.
215   * <p>
216   * Specifies the maximum number of characters that can be included
217   * in a proposed password.
218   * <p>
219   * A value of zero indicates that there will be no upper bound
220   * enforced. If both minimum and maximum lengths are defined, then
221   * the minimum length must be less than or equal to the maximum
222   * length.
223   *
224   * @return Returns the "max-password-length" property definition.
225   */
226  public IntegerPropertyDefinition getMaxPasswordLengthPropertyDefinition() {
227    return PD_MAX_PASSWORD_LENGTH;
228  }
229
230
231
232  /**
233   * Get the "min-password-length" property definition.
234   * <p>
235   * Specifies the minimum number of characters that must be included
236   * in a proposed password.
237   * <p>
238   * A value of zero indicates that there will be no lower bound
239   * enforced. If both minimum and maximum lengths are defined, then
240   * the minimum length must be less than or equal to the maximum
241   * length.
242   *
243   * @return Returns the "min-password-length" property definition.
244   */
245  public IntegerPropertyDefinition getMinPasswordLengthPropertyDefinition() {
246    return PD_MIN_PASSWORD_LENGTH;
247  }
248
249
250
251  /**
252   * Managed object client implementation.
253   */
254  private static class LengthBasedPasswordValidatorCfgClientImpl implements
255    LengthBasedPasswordValidatorCfgClient {
256
257    // Private implementation.
258    private ManagedObject<? extends LengthBasedPasswordValidatorCfgClient> impl;
259
260
261
262    // Private constructor.
263    private LengthBasedPasswordValidatorCfgClientImpl(
264        ManagedObject<? extends LengthBasedPasswordValidatorCfgClient> impl) {
265      this.impl = impl;
266    }
267
268
269
270    /**
271     * {@inheritDoc}
272     */
273    public Boolean isEnabled() {
274      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
275    }
276
277
278
279    /**
280     * {@inheritDoc}
281     */
282    public void setEnabled(boolean value) {
283      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
284    }
285
286
287
288    /**
289     * {@inheritDoc}
290     */
291    public String getJavaClass() {
292      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
293    }
294
295
296
297    /**
298     * {@inheritDoc}
299     */
300    public void setJavaClass(String value) {
301      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
302    }
303
304
305
306    /**
307     * {@inheritDoc}
308     */
309    public int getMaxPasswordLength() {
310      return impl.getPropertyValue(INSTANCE.getMaxPasswordLengthPropertyDefinition());
311    }
312
313
314
315    /**
316     * {@inheritDoc}
317     */
318    public void setMaxPasswordLength(Integer value) {
319      impl.setPropertyValue(INSTANCE.getMaxPasswordLengthPropertyDefinition(), value);
320    }
321
322
323
324    /**
325     * {@inheritDoc}
326     */
327    public int getMinPasswordLength() {
328      return impl.getPropertyValue(INSTANCE.getMinPasswordLengthPropertyDefinition());
329    }
330
331
332
333    /**
334     * {@inheritDoc}
335     */
336    public void setMinPasswordLength(Integer value) {
337      impl.setPropertyValue(INSTANCE.getMinPasswordLengthPropertyDefinition(), value);
338    }
339
340
341
342    /**
343     * {@inheritDoc}
344     */
345    public ManagedObjectDefinition<? extends LengthBasedPasswordValidatorCfgClient, ? extends LengthBasedPasswordValidatorCfg> definition() {
346      return INSTANCE;
347    }
348
349
350
351    /**
352     * {@inheritDoc}
353     */
354    public PropertyProvider properties() {
355      return impl;
356    }
357
358
359
360    /**
361     * {@inheritDoc}
362     */
363    public void commit() throws ManagedObjectAlreadyExistsException,
364        MissingMandatoryPropertiesException, ConcurrentModificationException,
365        OperationRejectedException, LdapException {
366      impl.commit();
367    }
368
369  }
370
371
372
373  /**
374   * Managed object server implementation.
375   */
376  private static class LengthBasedPasswordValidatorCfgServerImpl implements
377    LengthBasedPasswordValidatorCfg {
378
379    // Private implementation.
380    private ServerManagedObject<? extends LengthBasedPasswordValidatorCfg> impl;
381
382    // The value of the "enabled" property.
383    private final boolean pEnabled;
384
385    // The value of the "java-class" property.
386    private final String pJavaClass;
387
388    // The value of the "max-password-length" property.
389    private final int pMaxPasswordLength;
390
391    // The value of the "min-password-length" property.
392    private final int pMinPasswordLength;
393
394
395
396    // Private constructor.
397    private LengthBasedPasswordValidatorCfgServerImpl(ServerManagedObject<? extends LengthBasedPasswordValidatorCfg> impl) {
398      this.impl = impl;
399      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
400      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
401      this.pMaxPasswordLength = impl.getPropertyValue(INSTANCE.getMaxPasswordLengthPropertyDefinition());
402      this.pMinPasswordLength = impl.getPropertyValue(INSTANCE.getMinPasswordLengthPropertyDefinition());
403    }
404
405
406
407    /**
408     * {@inheritDoc}
409     */
410    public void addLengthBasedChangeListener(
411        ConfigurationChangeListener<LengthBasedPasswordValidatorCfg> listener) {
412      impl.registerChangeListener(listener);
413    }
414
415
416
417    /**
418     * {@inheritDoc}
419     */
420    public void removeLengthBasedChangeListener(
421        ConfigurationChangeListener<LengthBasedPasswordValidatorCfg> listener) {
422      impl.deregisterChangeListener(listener);
423    }
424    /**
425     * {@inheritDoc}
426     */
427    public void addChangeListener(
428        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
429      impl.registerChangeListener(listener);
430    }
431
432
433
434    /**
435     * {@inheritDoc}
436     */
437    public void removeChangeListener(
438        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
439      impl.deregisterChangeListener(listener);
440    }
441
442
443
444    /**
445     * {@inheritDoc}
446     */
447    public boolean isEnabled() {
448      return pEnabled;
449    }
450
451
452
453    /**
454     * {@inheritDoc}
455     */
456    public String getJavaClass() {
457      return pJavaClass;
458    }
459
460
461
462    /**
463     * {@inheritDoc}
464     */
465    public int getMaxPasswordLength() {
466      return pMaxPasswordLength;
467    }
468
469
470
471    /**
472     * {@inheritDoc}
473     */
474    public int getMinPasswordLength() {
475      return pMinPasswordLength;
476    }
477
478
479
480    /**
481     * {@inheritDoc}
482     */
483    public Class<? extends LengthBasedPasswordValidatorCfg> configurationClass() {
484      return LengthBasedPasswordValidatorCfg.class;
485    }
486
487
488
489    /**
490     * {@inheritDoc}
491     */
492    public DN dn() {
493      return impl.getDN();
494    }
495
496  }
497}