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