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