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.config.UndefinedDefaultBehaviorProvider;
048import org.forgerock.opendj.ldap.DN;
049import org.forgerock.opendj.ldap.LdapException;
050import org.forgerock.opendj.server.config.client.UniqueCharactersPasswordValidatorCfgClient;
051import org.forgerock.opendj.server.config.server.PasswordValidatorCfg;
052import org.forgerock.opendj.server.config.server.UniqueCharactersPasswordValidatorCfg;
053
054
055
056/**
057 * An interface for querying the Unique Characters Password Validator
058 * managed object definition meta information.
059 * <p>
060 * The Unique Characters Password Validator is used to determine
061 * whether a proposed password is acceptable based on the number of
062 * unique characters that it contains.
063 */
064public final class UniqueCharactersPasswordValidatorCfgDefn extends ManagedObjectDefinition<UniqueCharactersPasswordValidatorCfgClient, UniqueCharactersPasswordValidatorCfg> {
065
066  /** The singleton configuration definition instance. */
067  private static final UniqueCharactersPasswordValidatorCfgDefn INSTANCE = new UniqueCharactersPasswordValidatorCfgDefn();
068
069
070
071  /** The "case-sensitive-validation" property definition. */
072  private static final BooleanPropertyDefinition PD_CASE_SENSITIVE_VALIDATION;
073
074
075
076  /** The "java-class" property definition. */
077  private static final ClassPropertyDefinition PD_JAVA_CLASS;
078
079
080
081  /** The "min-unique-characters" property definition. */
082  private static final IntegerPropertyDefinition PD_MIN_UNIQUE_CHARACTERS;
083
084
085
086  /** Build the "case-sensitive-validation" property definition. */
087  static {
088      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "case-sensitive-validation");
089      builder.setOption(PropertyOption.MANDATORY);
090      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "case-sensitive-validation"));
091      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
092      PD_CASE_SENSITIVE_VALIDATION = builder.getInstance();
093      INSTANCE.registerPropertyDefinition(PD_CASE_SENSITIVE_VALIDATION);
094  }
095
096
097
098  /** Build the "java-class" property definition. */
099  static {
100      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
101      builder.setOption(PropertyOption.MANDATORY);
102      builder.setOption(PropertyOption.ADVANCED);
103      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
104      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.UniqueCharactersPasswordValidator");
105      builder.setDefaultBehaviorProvider(provider);
106      builder.addInstanceOf("org.opends.server.api.PasswordValidator");
107      PD_JAVA_CLASS = builder.getInstance();
108      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
109  }
110
111
112
113  /** Build the "min-unique-characters" property definition. */
114  static {
115      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-unique-characters");
116      builder.setOption(PropertyOption.MANDATORY);
117      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-unique-characters"));
118      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
119      builder.setLowerLimit(0);
120      PD_MIN_UNIQUE_CHARACTERS = builder.getInstance();
121      INSTANCE.registerPropertyDefinition(PD_MIN_UNIQUE_CHARACTERS);
122  }
123
124
125
126  // Register the tags associated with this managed object definition.
127  static {
128    INSTANCE.registerTag(Tag.valueOf("user-management"));
129  }
130
131
132
133  /**
134   * Get the Unique Characters Password Validator configuration
135   * definition singleton.
136   *
137   * @return Returns the Unique Characters Password Validator
138   *         configuration definition singleton.
139   */
140  public static UniqueCharactersPasswordValidatorCfgDefn getInstance() {
141    return INSTANCE;
142  }
143
144
145
146  /**
147   * Private constructor.
148   */
149  private UniqueCharactersPasswordValidatorCfgDefn() {
150    super("unique-characters-password-validator", PasswordValidatorCfgDefn.getInstance());
151  }
152
153
154
155  /** {@inheritDoc} */
156  public UniqueCharactersPasswordValidatorCfgClient createClientConfiguration(
157      ManagedObject<? extends UniqueCharactersPasswordValidatorCfgClient> impl) {
158    return new UniqueCharactersPasswordValidatorCfgClientImpl(impl);
159  }
160
161
162
163  /** {@inheritDoc} */
164  public UniqueCharactersPasswordValidatorCfg createServerConfiguration(
165      ServerManagedObject<? extends UniqueCharactersPasswordValidatorCfg> impl) {
166    return new UniqueCharactersPasswordValidatorCfgServerImpl(impl);
167  }
168
169
170
171  /** {@inheritDoc} */
172  public Class<UniqueCharactersPasswordValidatorCfg> getServerConfigurationClass() {
173    return UniqueCharactersPasswordValidatorCfg.class;
174  }
175
176
177
178  /**
179   * Get the "case-sensitive-validation" property definition.
180   * <p>
181   * Indicates whether this password validator should treat password
182   * characters in a case-sensitive manner.
183   * <p>
184   * A value of true indicates that the validator does not consider a
185   * capital letter to be the same as its lower-case counterpart. A
186   * value of false indicates that the validator ignores differences in
187   * capitalization when looking at the number of unique characters in
188   * the password.
189   *
190   * @return Returns the "case-sensitive-validation" property definition.
191   */
192  public BooleanPropertyDefinition getCaseSensitiveValidationPropertyDefinition() {
193    return PD_CASE_SENSITIVE_VALIDATION;
194  }
195
196
197
198  /**
199   * Get the "enabled" property definition.
200   * <p>
201   * Indicates whether the password validator is enabled for use.
202   *
203   * @return Returns the "enabled" property definition.
204   */
205  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
206    return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
207  }
208
209
210
211  /**
212   * Get the "java-class" property definition.
213   * <p>
214   * Specifies the fully-qualified name of the Java class that
215   * provides the password validator implementation.
216   *
217   * @return Returns the "java-class" property definition.
218   */
219  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
220    return PD_JAVA_CLASS;
221  }
222
223
224
225  /**
226   * Get the "min-unique-characters" property definition.
227   * <p>
228   * Specifies the minimum number of unique characters that a password
229   * will be allowed to contain.
230   * <p>
231   * A value of zero indicates that no minimum value is enforced.
232   *
233   * @return Returns the "min-unique-characters" property definition.
234   */
235  public IntegerPropertyDefinition getMinUniqueCharactersPropertyDefinition() {
236    return PD_MIN_UNIQUE_CHARACTERS;
237  }
238
239
240
241  /**
242   * Managed object client implementation.
243   */
244  private static class UniqueCharactersPasswordValidatorCfgClientImpl implements
245    UniqueCharactersPasswordValidatorCfgClient {
246
247    /** Private implementation. */
248    private ManagedObject<? extends UniqueCharactersPasswordValidatorCfgClient> impl;
249
250
251
252    /** Private constructor. */
253    private UniqueCharactersPasswordValidatorCfgClientImpl(
254        ManagedObject<? extends UniqueCharactersPasswordValidatorCfgClient> impl) {
255      this.impl = impl;
256    }
257
258
259
260    /** {@inheritDoc} */
261    public Boolean isCaseSensitiveValidation() {
262      return impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
263    }
264
265
266
267    /** {@inheritDoc} */
268    public void setCaseSensitiveValidation(boolean value) {
269      impl.setPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition(), value);
270    }
271
272
273
274    /** {@inheritDoc} */
275    public Boolean isEnabled() {
276      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
277    }
278
279
280
281    /** {@inheritDoc} */
282    public void setEnabled(boolean value) {
283      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
284    }
285
286
287
288    /** {@inheritDoc} */
289    public String getJavaClass() {
290      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
291    }
292
293
294
295    /** {@inheritDoc} */
296    public void setJavaClass(String value) {
297      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
298    }
299
300
301
302    /** {@inheritDoc} */
303    public Integer getMinUniqueCharacters() {
304      return impl.getPropertyValue(INSTANCE.getMinUniqueCharactersPropertyDefinition());
305    }
306
307
308
309    /** {@inheritDoc} */
310    public void setMinUniqueCharacters(int value) {
311      impl.setPropertyValue(INSTANCE.getMinUniqueCharactersPropertyDefinition(), value);
312    }
313
314
315
316    /** {@inheritDoc} */
317    public ManagedObjectDefinition<? extends UniqueCharactersPasswordValidatorCfgClient, ? extends UniqueCharactersPasswordValidatorCfg> definition() {
318      return INSTANCE;
319    }
320
321
322
323    /** {@inheritDoc} */
324    public PropertyProvider properties() {
325      return impl;
326    }
327
328
329
330    /** {@inheritDoc} */
331    public void commit() throws ManagedObjectAlreadyExistsException,
332        MissingMandatoryPropertiesException, ConcurrentModificationException,
333        OperationRejectedException, LdapException {
334      impl.commit();
335    }
336
337
338
339    /** {@inheritDoc} */
340    public String toString() {
341      return impl.toString();
342    }
343  }
344
345
346
347  /**
348   * Managed object server implementation.
349   */
350  private static class UniqueCharactersPasswordValidatorCfgServerImpl implements
351    UniqueCharactersPasswordValidatorCfg {
352
353    /** Private implementation. */
354    private ServerManagedObject<? extends UniqueCharactersPasswordValidatorCfg> impl;
355
356    /** The value of the "case-sensitive-validation" property. */
357    private final boolean pCaseSensitiveValidation;
358
359    /** The value of the "enabled" property. */
360    private final boolean pEnabled;
361
362    /** The value of the "java-class" property. */
363    private final String pJavaClass;
364
365    /** The value of the "min-unique-characters" property. */
366    private final int pMinUniqueCharacters;
367
368
369
370    /** Private constructor. */
371    private UniqueCharactersPasswordValidatorCfgServerImpl(ServerManagedObject<? extends UniqueCharactersPasswordValidatorCfg> impl) {
372      this.impl = impl;
373      this.pCaseSensitiveValidation = impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
374      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
375      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
376      this.pMinUniqueCharacters = impl.getPropertyValue(INSTANCE.getMinUniqueCharactersPropertyDefinition());
377    }
378
379
380
381    /** {@inheritDoc} */
382    public void addUniqueCharactersChangeListener(
383        ConfigurationChangeListener<UniqueCharactersPasswordValidatorCfg> listener) {
384      impl.registerChangeListener(listener);
385    }
386
387
388
389    /** {@inheritDoc} */
390    public void removeUniqueCharactersChangeListener(
391        ConfigurationChangeListener<UniqueCharactersPasswordValidatorCfg> listener) {
392      impl.deregisterChangeListener(listener);
393    }
394    /** {@inheritDoc} */
395    public void addChangeListener(
396        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
397      impl.registerChangeListener(listener);
398    }
399
400
401
402    /** {@inheritDoc} */
403    public void removeChangeListener(
404        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
405      impl.deregisterChangeListener(listener);
406    }
407
408
409
410    /** {@inheritDoc} */
411    public boolean isCaseSensitiveValidation() {
412      return pCaseSensitiveValidation;
413    }
414
415
416
417    /** {@inheritDoc} */
418    public boolean isEnabled() {
419      return pEnabled;
420    }
421
422
423
424    /** {@inheritDoc} */
425    public String getJavaClass() {
426      return pJavaClass;
427    }
428
429
430
431    /** {@inheritDoc} */
432    public int getMinUniqueCharacters() {
433      return pMinUniqueCharacters;
434    }
435
436
437
438    /** {@inheritDoc} */
439    public Class<? extends UniqueCharactersPasswordValidatorCfg> configurationClass() {
440      return UniqueCharactersPasswordValidatorCfg.class;
441    }
442
443
444
445    /** {@inheritDoc} */
446    public DN dn() {
447      return impl.getDN();
448    }
449
450
451
452    /** {@inheritDoc} */
453    public String toString() {
454      return impl.toString();
455    }
456  }
457}