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