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