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