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