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 java.util.Collection;
031import java.util.SortedSet;
032import org.forgerock.opendj.config.AdministratorAction;
033import org.forgerock.opendj.config.BooleanPropertyDefinition;
034import org.forgerock.opendj.config.ClassPropertyDefinition;
035import org.forgerock.opendj.config.client.ConcurrentModificationException;
036import org.forgerock.opendj.config.client.ManagedObject;
037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
038import org.forgerock.opendj.config.client.OperationRejectedException;
039import org.forgerock.opendj.config.DefaultBehaviorProvider;
040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
041import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
042import org.forgerock.opendj.config.ManagedObjectDefinition;
043import org.forgerock.opendj.config.PropertyOption;
044import org.forgerock.opendj.config.PropertyProvider;
045import org.forgerock.opendj.config.server.ConfigurationChangeListener;
046import org.forgerock.opendj.config.server.ServerManagedObject;
047import org.forgerock.opendj.config.StringPropertyDefinition;
048import org.forgerock.opendj.config.Tag;
049import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
050import org.forgerock.opendj.ldap.DN;
051import org.forgerock.opendj.ldap.LdapException;
052import org.forgerock.opendj.server.config.client.RandomPasswordGeneratorCfgClient;
053import org.forgerock.opendj.server.config.server.PasswordGeneratorCfg;
054import org.forgerock.opendj.server.config.server.RandomPasswordGeneratorCfg;
055
056
057
058/**
059 * An interface for querying the Random Password Generator managed
060 * object definition meta information.
061 * <p>
062 * The Random Password Generator creates random passwords based on
063 * fixed-length strings built from one or more character sets.
064 */
065public final class RandomPasswordGeneratorCfgDefn extends ManagedObjectDefinition<RandomPasswordGeneratorCfgClient, RandomPasswordGeneratorCfg> {
066
067  // The singleton configuration definition instance.
068  private static final RandomPasswordGeneratorCfgDefn INSTANCE = new RandomPasswordGeneratorCfgDefn();
069
070
071
072  // The "java-class" property definition.
073  private static final ClassPropertyDefinition PD_JAVA_CLASS;
074
075
076
077  // The "password-character-set" property definition.
078  private static final StringPropertyDefinition PD_PASSWORD_CHARACTER_SET;
079
080
081
082  // The "password-format" property definition.
083  private static final StringPropertyDefinition PD_PASSWORD_FORMAT;
084
085
086
087  // Build the "java-class" property definition.
088  static {
089      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
090      builder.setOption(PropertyOption.MANDATORY);
091      builder.setOption(PropertyOption.ADVANCED);
092      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
093      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.RandomPasswordGenerator");
094      builder.setDefaultBehaviorProvider(provider);
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  // Build the "password-character-set" property definition.
103  static {
104      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "password-character-set");
105      builder.setOption(PropertyOption.MULTI_VALUED);
106      builder.setOption(PropertyOption.MANDATORY);
107      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "password-character-set"));
108      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
109      builder.setPattern(".*", "FORMAT");
110      PD_PASSWORD_CHARACTER_SET = builder.getInstance();
111      INSTANCE.registerPropertyDefinition(PD_PASSWORD_CHARACTER_SET);
112  }
113
114
115
116  // Build the "password-format" property definition.
117  static {
118      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "password-format");
119      builder.setOption(PropertyOption.MANDATORY);
120      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "password-format"));
121      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
122      builder.setPattern(".*", "FORMAT");
123      PD_PASSWORD_FORMAT = builder.getInstance();
124      INSTANCE.registerPropertyDefinition(PD_PASSWORD_FORMAT);
125  }
126
127
128
129  // Register the tags associated with this managed object definition.
130  static {
131    INSTANCE.registerTag(Tag.valueOf("user-management"));
132  }
133
134
135
136  /**
137   * Get the Random Password Generator configuration definition
138   * singleton.
139   *
140   * @return Returns the Random Password Generator configuration
141   *         definition singleton.
142   */
143  public static RandomPasswordGeneratorCfgDefn getInstance() {
144    return INSTANCE;
145  }
146
147
148
149  /**
150   * Private constructor.
151   */
152  private RandomPasswordGeneratorCfgDefn() {
153    super("random-password-generator", PasswordGeneratorCfgDefn.getInstance());
154  }
155
156
157
158  /**
159   * {@inheritDoc}
160   */
161  public RandomPasswordGeneratorCfgClient createClientConfiguration(
162      ManagedObject<? extends RandomPasswordGeneratorCfgClient> impl) {
163    return new RandomPasswordGeneratorCfgClientImpl(impl);
164  }
165
166
167
168  /**
169   * {@inheritDoc}
170   */
171  public RandomPasswordGeneratorCfg createServerConfiguration(
172      ServerManagedObject<? extends RandomPasswordGeneratorCfg> impl) {
173    return new RandomPasswordGeneratorCfgServerImpl(impl);
174  }
175
176
177
178  /**
179   * {@inheritDoc}
180   */
181  public Class<RandomPasswordGeneratorCfg> getServerConfigurationClass() {
182    return RandomPasswordGeneratorCfg.class;
183  }
184
185
186
187  /**
188   * Get the "enabled" property definition.
189   * <p>
190   * Indicates whether the Random Password Generator is enabled for
191   * use.
192   *
193   * @return Returns the "enabled" property definition.
194   */
195  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
196    return PasswordGeneratorCfgDefn.getInstance().getEnabledPropertyDefinition();
197  }
198
199
200
201  /**
202   * Get the "java-class" property definition.
203   * <p>
204   * Specifies the fully-qualified name of the Java class that
205   * provides the Random Password Generator implementation.
206   *
207   * @return Returns the "java-class" property definition.
208   */
209  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
210    return PD_JAVA_CLASS;
211  }
212
213
214
215  /**
216   * Get the "password-character-set" property definition.
217   * <p>
218   * Specifies one or more named character sets.
219   * <p>
220   * This is a multi-valued property, with each value defining a
221   * different character set. The format of the character set is the
222   * name of the set followed by a colon and the characters that are in
223   * that set. For example, the value
224   * "alpha:abcdefghijklmnopqrstuvwxyz" defines a character set named
225   * "alpha" containing all of the lower-case ASCII alphabetic
226   * characters.
227   *
228   * @return Returns the "password-character-set" property definition.
229   */
230  public StringPropertyDefinition getPasswordCharacterSetPropertyDefinition() {
231    return PD_PASSWORD_CHARACTER_SET;
232  }
233
234
235
236  /**
237   * Get the "password-format" property definition.
238   * <p>
239   * Specifies the format to use for the generated password.
240   * <p>
241   * The value is a comma-delimited list of elements in which each of
242   * those elements is comprised of the name of a character set defined
243   * in the password-character-set property, a colon, and the number of
244   * characters to include from that set. For example, a value of
245   * "alpha:3,numeric:2,alpha:3" generates an 8-character password in
246   * which the first three characters are from the "alpha" set, the
247   * next two are from the "numeric" set, and the final three are from
248   * the "alpha" set.
249   *
250   * @return Returns the "password-format" property definition.
251   */
252  public StringPropertyDefinition getPasswordFormatPropertyDefinition() {
253    return PD_PASSWORD_FORMAT;
254  }
255
256
257
258  /**
259   * Managed object client implementation.
260   */
261  private static class RandomPasswordGeneratorCfgClientImpl implements
262    RandomPasswordGeneratorCfgClient {
263
264    // Private implementation.
265    private ManagedObject<? extends RandomPasswordGeneratorCfgClient> impl;
266
267
268
269    // Private constructor.
270    private RandomPasswordGeneratorCfgClientImpl(
271        ManagedObject<? extends RandomPasswordGeneratorCfgClient> impl) {
272      this.impl = impl;
273    }
274
275
276
277    /**
278     * {@inheritDoc}
279     */
280    public Boolean isEnabled() {
281      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
282    }
283
284
285
286    /**
287     * {@inheritDoc}
288     */
289    public void setEnabled(boolean value) {
290      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
291    }
292
293
294
295    /**
296     * {@inheritDoc}
297     */
298    public String getJavaClass() {
299      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
300    }
301
302
303
304    /**
305     * {@inheritDoc}
306     */
307    public void setJavaClass(String value) {
308      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
309    }
310
311
312
313    /**
314     * {@inheritDoc}
315     */
316    public SortedSet<String> getPasswordCharacterSet() {
317      return impl.getPropertyValues(INSTANCE.getPasswordCharacterSetPropertyDefinition());
318    }
319
320
321
322    /**
323     * {@inheritDoc}
324     */
325    public void setPasswordCharacterSet(Collection<String> values) {
326      impl.setPropertyValues(INSTANCE.getPasswordCharacterSetPropertyDefinition(), values);
327    }
328
329
330
331    /**
332     * {@inheritDoc}
333     */
334    public String getPasswordFormat() {
335      return impl.getPropertyValue(INSTANCE.getPasswordFormatPropertyDefinition());
336    }
337
338
339
340    /**
341     * {@inheritDoc}
342     */
343    public void setPasswordFormat(String value) {
344      impl.setPropertyValue(INSTANCE.getPasswordFormatPropertyDefinition(), value);
345    }
346
347
348
349    /**
350     * {@inheritDoc}
351     */
352    public ManagedObjectDefinition<? extends RandomPasswordGeneratorCfgClient, ? extends RandomPasswordGeneratorCfg> definition() {
353      return INSTANCE;
354    }
355
356
357
358    /**
359     * {@inheritDoc}
360     */
361    public PropertyProvider properties() {
362      return impl;
363    }
364
365
366
367    /**
368     * {@inheritDoc}
369     */
370    public void commit() throws ManagedObjectAlreadyExistsException,
371        MissingMandatoryPropertiesException, ConcurrentModificationException,
372        OperationRejectedException, LdapException {
373      impl.commit();
374    }
375
376  }
377
378
379
380  /**
381   * Managed object server implementation.
382   */
383  private static class RandomPasswordGeneratorCfgServerImpl implements
384    RandomPasswordGeneratorCfg {
385
386    // Private implementation.
387    private ServerManagedObject<? extends RandomPasswordGeneratorCfg> impl;
388
389    // The value of the "enabled" property.
390    private final boolean pEnabled;
391
392    // The value of the "java-class" property.
393    private final String pJavaClass;
394
395    // The value of the "password-character-set" property.
396    private final SortedSet<String> pPasswordCharacterSet;
397
398    // The value of the "password-format" property.
399    private final String pPasswordFormat;
400
401
402
403    // Private constructor.
404    private RandomPasswordGeneratorCfgServerImpl(ServerManagedObject<? extends RandomPasswordGeneratorCfg> impl) {
405      this.impl = impl;
406      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
407      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
408      this.pPasswordCharacterSet = impl.getPropertyValues(INSTANCE.getPasswordCharacterSetPropertyDefinition());
409      this.pPasswordFormat = impl.getPropertyValue(INSTANCE.getPasswordFormatPropertyDefinition());
410    }
411
412
413
414    /**
415     * {@inheritDoc}
416     */
417    public void addRandomChangeListener(
418        ConfigurationChangeListener<RandomPasswordGeneratorCfg> listener) {
419      impl.registerChangeListener(listener);
420    }
421
422
423
424    /**
425     * {@inheritDoc}
426     */
427    public void removeRandomChangeListener(
428        ConfigurationChangeListener<RandomPasswordGeneratorCfg> listener) {
429      impl.deregisterChangeListener(listener);
430    }
431    /**
432     * {@inheritDoc}
433     */
434    public void addChangeListener(
435        ConfigurationChangeListener<PasswordGeneratorCfg> listener) {
436      impl.registerChangeListener(listener);
437    }
438
439
440
441    /**
442     * {@inheritDoc}
443     */
444    public void removeChangeListener(
445        ConfigurationChangeListener<PasswordGeneratorCfg> listener) {
446      impl.deregisterChangeListener(listener);
447    }
448
449
450
451    /**
452     * {@inheritDoc}
453     */
454    public boolean isEnabled() {
455      return pEnabled;
456    }
457
458
459
460    /**
461     * {@inheritDoc}
462     */
463    public String getJavaClass() {
464      return pJavaClass;
465    }
466
467
468
469    /**
470     * {@inheritDoc}
471     */
472    public SortedSet<String> getPasswordCharacterSet() {
473      return pPasswordCharacterSet;
474    }
475
476
477
478    /**
479     * {@inheritDoc}
480     */
481    public String getPasswordFormat() {
482      return pPasswordFormat;
483    }
484
485
486
487    /**
488     * {@inheritDoc}
489     */
490    public Class<? extends RandomPasswordGeneratorCfg> configurationClass() {
491      return RandomPasswordGeneratorCfg.class;
492    }
493
494
495
496    /**
497     * {@inheritDoc}
498     */
499    public DN dn() {
500      return impl.getDN();
501    }
502
503  }
504}