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