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