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