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.ManagedObjectAlreadyExistsException;
040import org.opends.server.admin.ManagedObjectDefinition;
041import org.opends.server.admin.PropertyOption;
042import org.opends.server.admin.PropertyProvider;
043import org.opends.server.admin.server.ConfigurationChangeListener;
044import org.opends.server.admin.server.ServerManagedObject;
045import org.opends.server.admin.std.client.PasswordValidatorCfgClient;
046import org.opends.server.admin.std.server.PasswordValidatorCfg;
047import org.opends.server.admin.Tag;
048import org.opends.server.admin.TopCfgDefn;
049import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
050import org.opends.server.types.DN;
051
052
053
054/**
055 * An interface for querying the Password Validator managed object
056 * definition meta information.
057 * <p>
058 * Password Validators are responsible for determining whether a
059 * proposed password is acceptable for use and could include checks
060 * like ensuring it meets minimum length requirements, that it has an
061 * appropriate range of characters, or that it is not in the history.
062 */
063public final class PasswordValidatorCfgDefn extends ManagedObjectDefinition<PasswordValidatorCfgClient, PasswordValidatorCfg> {
064
065  // The singleton configuration definition instance.
066  private static final PasswordValidatorCfgDefn INSTANCE = new PasswordValidatorCfgDefn();
067
068
069
070  // The "enabled" property definition.
071  private static final BooleanPropertyDefinition PD_ENABLED;
072
073
074
075  // The "java-class" property definition.
076  private static final ClassPropertyDefinition PD_JAVA_CLASS;
077
078
079
080  // Build the "enabled" property definition.
081  static {
082      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
083      builder.setOption(PropertyOption.MANDATORY);
084      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
085      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
086      PD_ENABLED = builder.getInstance();
087      INSTANCE.registerPropertyDefinition(PD_ENABLED);
088  }
089
090
091
092  // Build the "java-class" property definition.
093  static {
094      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
095      builder.setOption(PropertyOption.MANDATORY);
096      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
097      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
098      builder.addInstanceOf("org.opends.server.api.PasswordValidator");
099      PD_JAVA_CLASS = builder.getInstance();
100      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
101  }
102
103
104
105  // Register the tags associated with this managed object definition.
106  static {
107    INSTANCE.registerTag(Tag.valueOf("user-management"));
108  }
109
110
111
112  /**
113   * Get the Password Validator configuration definition singleton.
114   *
115   * @return Returns the Password Validator configuration definition
116   *         singleton.
117   */
118  public static PasswordValidatorCfgDefn getInstance() {
119    return INSTANCE;
120  }
121
122
123
124  /**
125   * Private constructor.
126   */
127  private PasswordValidatorCfgDefn() {
128    super("password-validator", TopCfgDefn.getInstance());
129  }
130
131
132
133  /**
134   * {@inheritDoc}
135   */
136  public PasswordValidatorCfgClient createClientConfiguration(
137      ManagedObject<? extends PasswordValidatorCfgClient> impl) {
138    return new PasswordValidatorCfgClientImpl(impl);
139  }
140
141
142
143  /**
144   * {@inheritDoc}
145   */
146  public PasswordValidatorCfg createServerConfiguration(
147      ServerManagedObject<? extends PasswordValidatorCfg> impl) {
148    return new PasswordValidatorCfgServerImpl(impl);
149  }
150
151
152
153  /**
154   * {@inheritDoc}
155   */
156  public Class<PasswordValidatorCfg> getServerConfigurationClass() {
157    return PasswordValidatorCfg.class;
158  }
159
160
161
162  /**
163   * Get the "enabled" property definition.
164   * <p>
165   * Indicates whether the password validator is enabled for use.
166   *
167   * @return Returns the "enabled" property definition.
168   */
169  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
170    return PD_ENABLED;
171  }
172
173
174
175  /**
176   * Get the "java-class" property definition.
177   * <p>
178   * Specifies the fully-qualified name of the Java class that
179   * provides the password validator implementation.
180   *
181   * @return Returns the "java-class" property definition.
182   */
183  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
184    return PD_JAVA_CLASS;
185  }
186
187
188
189  /**
190   * Managed object client implementation.
191   */
192  private static class PasswordValidatorCfgClientImpl implements
193    PasswordValidatorCfgClient {
194
195    // Private implementation.
196    private ManagedObject<? extends PasswordValidatorCfgClient> impl;
197
198
199
200    // Private constructor.
201    private PasswordValidatorCfgClientImpl(
202        ManagedObject<? extends PasswordValidatorCfgClient> impl) {
203      this.impl = impl;
204    }
205
206
207
208    /**
209     * {@inheritDoc}
210     */
211    public Boolean isEnabled() {
212      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
213    }
214
215
216
217    /**
218     * {@inheritDoc}
219     */
220    public void setEnabled(boolean value) {
221      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
222    }
223
224
225
226    /**
227     * {@inheritDoc}
228     */
229    public String getJavaClass() {
230      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
231    }
232
233
234
235    /**
236     * {@inheritDoc}
237     */
238    public void setJavaClass(String value) {
239      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
240    }
241
242
243
244    /**
245     * {@inheritDoc}
246     */
247    public ManagedObjectDefinition<? extends PasswordValidatorCfgClient, ? extends PasswordValidatorCfg> definition() {
248      return INSTANCE;
249    }
250
251
252
253    /**
254     * {@inheritDoc}
255     */
256    public PropertyProvider properties() {
257      return impl;
258    }
259
260
261
262    /**
263     * {@inheritDoc}
264     */
265    public void commit() throws ManagedObjectAlreadyExistsException,
266        MissingMandatoryPropertiesException, ConcurrentModificationException,
267        OperationRejectedException, AuthorizationException,
268        CommunicationException {
269      impl.commit();
270    }
271
272
273
274    /** {@inheritDoc} */
275    public String toString() {
276      return impl.toString();
277    }
278  }
279
280
281
282  /**
283   * Managed object server implementation.
284   */
285  private static class PasswordValidatorCfgServerImpl implements
286    PasswordValidatorCfg {
287
288    // Private implementation.
289    private ServerManagedObject<? extends PasswordValidatorCfg> impl;
290
291    // The value of the "enabled" property.
292    private final boolean pEnabled;
293
294    // The value of the "java-class" property.
295    private final String pJavaClass;
296
297
298
299    // Private constructor.
300    private PasswordValidatorCfgServerImpl(ServerManagedObject<? extends PasswordValidatorCfg> impl) {
301      this.impl = impl;
302      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
303      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
304    }
305
306
307
308    /**
309     * {@inheritDoc}
310     */
311    public void addChangeListener(
312        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
313      impl.registerChangeListener(listener);
314    }
315
316
317
318    /**
319     * {@inheritDoc}
320     */
321    public void removeChangeListener(
322        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
323      impl.deregisterChangeListener(listener);
324    }
325
326
327
328    /**
329     * {@inheritDoc}
330     */
331    public boolean isEnabled() {
332      return pEnabled;
333    }
334
335
336
337    /**
338     * {@inheritDoc}
339     */
340    public String getJavaClass() {
341      return pJavaClass;
342    }
343
344
345
346    /**
347     * {@inheritDoc}
348     */
349    public Class<? extends PasswordValidatorCfg> configurationClass() {
350      return PasswordValidatorCfg.class;
351    }
352
353
354
355    /**
356     * {@inheritDoc}
357     */
358    public DN dn() {
359      return impl.getDN();
360    }
361
362
363
364    /** {@inheritDoc} */
365    public String toString() {
366      return impl.toString();
367    }
368  }
369}