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