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.RepeatedCharactersPasswordValidatorCfgClient;
051import org.forgerock.opendj.server.config.server.PasswordValidatorCfg;
052import org.forgerock.opendj.server.config.server.RepeatedCharactersPasswordValidatorCfg;
053
054
055
056/**
057 * An interface for querying the Repeated Characters Password
058 * Validator managed object definition meta information.
059 * <p>
060 * The Repeated Characters Password Validator is used to determine
061 * whether a proposed password is acceptable based on the number of
062 * times any character appears consecutively in a password value.
063 */
064public final class RepeatedCharactersPasswordValidatorCfgDefn extends ManagedObjectDefinition<RepeatedCharactersPasswordValidatorCfgClient, RepeatedCharactersPasswordValidatorCfg> {
065
066  // The singleton configuration definition instance.
067  private static final RepeatedCharactersPasswordValidatorCfgDefn INSTANCE = new RepeatedCharactersPasswordValidatorCfgDefn();
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 "max-consecutive-length" property definition.
082  private static final IntegerPropertyDefinition PD_MAX_CONSECUTIVE_LENGTH;
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.RepeatedCharactersPasswordValidator");
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 "max-consecutive-length" property definition.
114  static {
115      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-consecutive-length");
116      builder.setOption(PropertyOption.MANDATORY);
117      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-consecutive-length"));
118      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
119      builder.setLowerLimit(0);
120      PD_MAX_CONSECUTIVE_LENGTH = builder.getInstance();
121      INSTANCE.registerPropertyDefinition(PD_MAX_CONSECUTIVE_LENGTH);
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 Repeated Characters Password Validator configuration
135   * definition singleton.
136   *
137   * @return Returns the Repeated Characters Password Validator
138   *         configuration definition singleton.
139   */
140  public static RepeatedCharactersPasswordValidatorCfgDefn getInstance() {
141    return INSTANCE;
142  }
143
144
145
146  /**
147   * Private constructor.
148   */
149  private RepeatedCharactersPasswordValidatorCfgDefn() {
150    super("repeated-characters-password-validator", PasswordValidatorCfgDefn.getInstance());
151  }
152
153
154
155  /**
156   * {@inheritDoc}
157   */
158  public RepeatedCharactersPasswordValidatorCfgClient createClientConfiguration(
159      ManagedObject<? extends RepeatedCharactersPasswordValidatorCfgClient> impl) {
160    return new RepeatedCharactersPasswordValidatorCfgClientImpl(impl);
161  }
162
163
164
165  /**
166   * {@inheritDoc}
167   */
168  public RepeatedCharactersPasswordValidatorCfg createServerConfiguration(
169      ServerManagedObject<? extends RepeatedCharactersPasswordValidatorCfg> impl) {
170    return new RepeatedCharactersPasswordValidatorCfgServerImpl(impl);
171  }
172
173
174
175  /**
176   * {@inheritDoc}
177   */
178  public Class<RepeatedCharactersPasswordValidatorCfg> getServerConfigurationClass() {
179    return RepeatedCharactersPasswordValidatorCfg.class;
180  }
181
182
183
184  /**
185   * Get the "case-sensitive-validation" property definition.
186   * <p>
187   * Indicates whether this password validator should treat password
188   * characters in a case-sensitive manner.
189   * <p>
190   * If the value of this property is false, the validator ignores any
191   * differences in capitalization when looking for consecutive
192   * characters in the password. If the value is true, the validator
193   * considers a character to be repeating only if all consecutive
194   * occurrences use the same capitalization.
195   *
196   * @return Returns the "case-sensitive-validation" property definition.
197   */
198  public BooleanPropertyDefinition getCaseSensitiveValidationPropertyDefinition() {
199    return PD_CASE_SENSITIVE_VALIDATION;
200  }
201
202
203
204  /**
205   * Get the "enabled" property definition.
206   * <p>
207   * Indicates whether the password validator is enabled for use.
208   *
209   * @return Returns the "enabled" property definition.
210   */
211  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
212    return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
213  }
214
215
216
217  /**
218   * Get the "java-class" property definition.
219   * <p>
220   * Specifies the fully-qualified name of the Java class that
221   * provides the password validator implementation.
222   *
223   * @return Returns the "java-class" property definition.
224   */
225  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
226    return PD_JAVA_CLASS;
227  }
228
229
230
231  /**
232   * Get the "max-consecutive-length" property definition.
233   * <p>
234   * Specifies the maximum number of times that any character can
235   * appear consecutively in a password value.
236   * <p>
237   * A value of zero indicates that no maximum limit is enforced.
238   *
239   * @return Returns the "max-consecutive-length" property definition.
240   */
241  public IntegerPropertyDefinition getMaxConsecutiveLengthPropertyDefinition() {
242    return PD_MAX_CONSECUTIVE_LENGTH;
243  }
244
245
246
247  /**
248   * Managed object client implementation.
249   */
250  private static class RepeatedCharactersPasswordValidatorCfgClientImpl implements
251    RepeatedCharactersPasswordValidatorCfgClient {
252
253    // Private implementation.
254    private ManagedObject<? extends RepeatedCharactersPasswordValidatorCfgClient> impl;
255
256
257
258    // Private constructor.
259    private RepeatedCharactersPasswordValidatorCfgClientImpl(
260        ManagedObject<? extends RepeatedCharactersPasswordValidatorCfgClient> impl) {
261      this.impl = impl;
262    }
263
264
265
266    /**
267     * {@inheritDoc}
268     */
269    public Boolean isCaseSensitiveValidation() {
270      return impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
271    }
272
273
274
275    /**
276     * {@inheritDoc}
277     */
278    public void setCaseSensitiveValidation(boolean value) {
279      impl.setPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition(), value);
280    }
281
282
283
284    /**
285     * {@inheritDoc}
286     */
287    public Boolean isEnabled() {
288      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
289    }
290
291
292
293    /**
294     * {@inheritDoc}
295     */
296    public void setEnabled(boolean value) {
297      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
298    }
299
300
301
302    /**
303     * {@inheritDoc}
304     */
305    public String getJavaClass() {
306      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
307    }
308
309
310
311    /**
312     * {@inheritDoc}
313     */
314    public void setJavaClass(String value) {
315      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
316    }
317
318
319
320    /**
321     * {@inheritDoc}
322     */
323    public Integer getMaxConsecutiveLength() {
324      return impl.getPropertyValue(INSTANCE.getMaxConsecutiveLengthPropertyDefinition());
325    }
326
327
328
329    /**
330     * {@inheritDoc}
331     */
332    public void setMaxConsecutiveLength(int value) {
333      impl.setPropertyValue(INSTANCE.getMaxConsecutiveLengthPropertyDefinition(), value);
334    }
335
336
337
338    /**
339     * {@inheritDoc}
340     */
341    public ManagedObjectDefinition<? extends RepeatedCharactersPasswordValidatorCfgClient, ? extends RepeatedCharactersPasswordValidatorCfg> definition() {
342      return INSTANCE;
343    }
344
345
346
347    /**
348     * {@inheritDoc}
349     */
350    public PropertyProvider properties() {
351      return impl;
352    }
353
354
355
356    /**
357     * {@inheritDoc}
358     */
359    public void commit() throws ManagedObjectAlreadyExistsException,
360        MissingMandatoryPropertiesException, ConcurrentModificationException,
361        OperationRejectedException, LdapException {
362      impl.commit();
363    }
364
365  }
366
367
368
369  /**
370   * Managed object server implementation.
371   */
372  private static class RepeatedCharactersPasswordValidatorCfgServerImpl implements
373    RepeatedCharactersPasswordValidatorCfg {
374
375    // Private implementation.
376    private ServerManagedObject<? extends RepeatedCharactersPasswordValidatorCfg> impl;
377
378    // The value of the "case-sensitive-validation" property.
379    private final boolean pCaseSensitiveValidation;
380
381    // The value of the "enabled" property.
382    private final boolean pEnabled;
383
384    // The value of the "java-class" property.
385    private final String pJavaClass;
386
387    // The value of the "max-consecutive-length" property.
388    private final int pMaxConsecutiveLength;
389
390
391
392    // Private constructor.
393    private RepeatedCharactersPasswordValidatorCfgServerImpl(ServerManagedObject<? extends RepeatedCharactersPasswordValidatorCfg> impl) {
394      this.impl = impl;
395      this.pCaseSensitiveValidation = impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
396      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
397      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
398      this.pMaxConsecutiveLength = impl.getPropertyValue(INSTANCE.getMaxConsecutiveLengthPropertyDefinition());
399    }
400
401
402
403    /**
404     * {@inheritDoc}
405     */
406    public void addRepeatedCharactersChangeListener(
407        ConfigurationChangeListener<RepeatedCharactersPasswordValidatorCfg> listener) {
408      impl.registerChangeListener(listener);
409    }
410
411
412
413    /**
414     * {@inheritDoc}
415     */
416    public void removeRepeatedCharactersChangeListener(
417        ConfigurationChangeListener<RepeatedCharactersPasswordValidatorCfg> listener) {
418      impl.deregisterChangeListener(listener);
419    }
420    /**
421     * {@inheritDoc}
422     */
423    public void addChangeListener(
424        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
425      impl.registerChangeListener(listener);
426    }
427
428
429
430    /**
431     * {@inheritDoc}
432     */
433    public void removeChangeListener(
434        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
435      impl.deregisterChangeListener(listener);
436    }
437
438
439
440    /**
441     * {@inheritDoc}
442     */
443    public boolean isCaseSensitiveValidation() {
444      return pCaseSensitiveValidation;
445    }
446
447
448
449    /**
450     * {@inheritDoc}
451     */
452    public boolean isEnabled() {
453      return pEnabled;
454    }
455
456
457
458    /**
459     * {@inheritDoc}
460     */
461    public String getJavaClass() {
462      return pJavaClass;
463    }
464
465
466
467    /**
468     * {@inheritDoc}
469     */
470    public int getMaxConsecutiveLength() {
471      return pMaxConsecutiveLength;
472    }
473
474
475
476    /**
477     * {@inheritDoc}
478     */
479    public Class<? extends RepeatedCharactersPasswordValidatorCfg> configurationClass() {
480      return RepeatedCharactersPasswordValidatorCfg.class;
481    }
482
483
484
485    /**
486     * {@inheritDoc}
487     */
488    public DN dn() {
489      return impl.getDN();
490    }
491
492  }
493}