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    /** {@inheritDoc} */
374    public String toString() {
375      return impl.toString();
376    }
377  }
378
379
380
381  /**
382   * Managed object server implementation.
383   */
384  private static class LengthBasedPasswordValidatorCfgServerImpl implements
385    LengthBasedPasswordValidatorCfg {
386
387    // Private implementation.
388    private ServerManagedObject<? extends LengthBasedPasswordValidatorCfg> impl;
389
390    // The value of the "enabled" property.
391    private final boolean pEnabled;
392
393    // The value of the "java-class" property.
394    private final String pJavaClass;
395
396    // The value of the "max-password-length" property.
397    private final int pMaxPasswordLength;
398
399    // The value of the "min-password-length" property.
400    private final int pMinPasswordLength;
401
402
403
404    // Private constructor.
405    private LengthBasedPasswordValidatorCfgServerImpl(ServerManagedObject<? extends LengthBasedPasswordValidatorCfg> impl) {
406      this.impl = impl;
407      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
408      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
409      this.pMaxPasswordLength = impl.getPropertyValue(INSTANCE.getMaxPasswordLengthPropertyDefinition());
410      this.pMinPasswordLength = impl.getPropertyValue(INSTANCE.getMinPasswordLengthPropertyDefinition());
411    }
412
413
414
415    /**
416     * {@inheritDoc}
417     */
418    public void addLengthBasedChangeListener(
419        ConfigurationChangeListener<LengthBasedPasswordValidatorCfg> listener) {
420      impl.registerChangeListener(listener);
421    }
422
423
424
425    /**
426     * {@inheritDoc}
427     */
428    public void removeLengthBasedChangeListener(
429        ConfigurationChangeListener<LengthBasedPasswordValidatorCfg> listener) {
430      impl.deregisterChangeListener(listener);
431    }
432    /**
433     * {@inheritDoc}
434     */
435    public void addChangeListener(
436        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
437      impl.registerChangeListener(listener);
438    }
439
440
441
442    /**
443     * {@inheritDoc}
444     */
445    public void removeChangeListener(
446        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
447      impl.deregisterChangeListener(listener);
448    }
449
450
451
452    /**
453     * {@inheritDoc}
454     */
455    public boolean isEnabled() {
456      return pEnabled;
457    }
458
459
460
461    /**
462     * {@inheritDoc}
463     */
464    public String getJavaClass() {
465      return pJavaClass;
466    }
467
468
469
470    /**
471     * {@inheritDoc}
472     */
473    public int getMaxPasswordLength() {
474      return pMaxPasswordLength;
475    }
476
477
478
479    /**
480     * {@inheritDoc}
481     */
482    public int getMinPasswordLength() {
483      return pMinPasswordLength;
484    }
485
486
487
488    /**
489     * {@inheritDoc}
490     */
491    public Class<? extends LengthBasedPasswordValidatorCfg> configurationClass() {
492      return LengthBasedPasswordValidatorCfg.class;
493    }
494
495
496
497    /**
498     * {@inheritDoc}
499     */
500    public DN dn() {
501      return impl.getDN();
502    }
503
504
505
506    /** {@inheritDoc} */
507    public String toString() {
508      return impl.toString();
509    }
510  }
511}