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