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  /** {@inheritDoc} */
159  public RandomPasswordGeneratorCfgClient createClientConfiguration(
160      ManagedObject<? extends RandomPasswordGeneratorCfgClient> impl) {
161    return new RandomPasswordGeneratorCfgClientImpl(impl);
162  }
163
164
165
166  /** {@inheritDoc} */
167  public RandomPasswordGeneratorCfg createServerConfiguration(
168      ServerManagedObject<? extends RandomPasswordGeneratorCfg> impl) {
169    return new RandomPasswordGeneratorCfgServerImpl(impl);
170  }
171
172
173
174  /** {@inheritDoc} */
175  public Class<RandomPasswordGeneratorCfg> getServerConfigurationClass() {
176    return RandomPasswordGeneratorCfg.class;
177  }
178
179
180
181  /**
182   * Get the "enabled" property definition.
183   * <p>
184   * Indicates whether the Random Password Generator is enabled for
185   * use.
186   *
187   * @return Returns the "enabled" property definition.
188   */
189  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
190    return PasswordGeneratorCfgDefn.getInstance().getEnabledPropertyDefinition();
191  }
192
193
194
195  /**
196   * Get the "java-class" property definition.
197   * <p>
198   * Specifies the fully-qualified name of the Java class that
199   * provides the Random Password Generator implementation.
200   *
201   * @return Returns the "java-class" property definition.
202   */
203  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
204    return PD_JAVA_CLASS;
205  }
206
207
208
209  /**
210   * Get the "password-character-set" property definition.
211   * <p>
212   * Specifies one or more named character sets.
213   * <p>
214   * This is a multi-valued property, with each value defining a
215   * different character set. The format of the character set is the
216   * name of the set followed by a colon and the characters that are in
217   * that set. For example, the value
218   * "alpha:abcdefghijklmnopqrstuvwxyz" defines a character set named
219   * "alpha" containing all of the lower-case ASCII alphabetic
220   * characters.
221   *
222   * @return Returns the "password-character-set" property definition.
223   */
224  public StringPropertyDefinition getPasswordCharacterSetPropertyDefinition() {
225    return PD_PASSWORD_CHARACTER_SET;
226  }
227
228
229
230  /**
231   * Get the "password-format" property definition.
232   * <p>
233   * Specifies the format to use for the generated password.
234   * <p>
235   * The value is a comma-delimited list of elements in which each of
236   * those elements is comprised of the name of a character set defined
237   * in the password-character-set property, a colon, and the number of
238   * characters to include from that set. For example, a value of
239   * "alpha:3,numeric:2,alpha:3" generates an 8-character password in
240   * which the first three characters are from the "alpha" set, the
241   * next two are from the "numeric" set, and the final three are from
242   * the "alpha" set.
243   *
244   * @return Returns the "password-format" property definition.
245   */
246  public StringPropertyDefinition getPasswordFormatPropertyDefinition() {
247    return PD_PASSWORD_FORMAT;
248  }
249
250
251
252  /**
253   * Managed object client implementation.
254   */
255  private static class RandomPasswordGeneratorCfgClientImpl implements
256    RandomPasswordGeneratorCfgClient {
257
258    /** Private implementation. */
259    private ManagedObject<? extends RandomPasswordGeneratorCfgClient> impl;
260
261
262
263    /** Private constructor. */
264    private RandomPasswordGeneratorCfgClientImpl(
265        ManagedObject<? extends RandomPasswordGeneratorCfgClient> impl) {
266      this.impl = impl;
267    }
268
269
270
271    /** {@inheritDoc} */
272    public Boolean isEnabled() {
273      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
274    }
275
276
277
278    /** {@inheritDoc} */
279    public void setEnabled(boolean value) {
280      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
281    }
282
283
284
285    /** {@inheritDoc} */
286    public String getJavaClass() {
287      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
288    }
289
290
291
292    /** {@inheritDoc} */
293    public void setJavaClass(String value) {
294      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
295    }
296
297
298
299    /** {@inheritDoc} */
300    public SortedSet<String> getPasswordCharacterSet() {
301      return impl.getPropertyValues(INSTANCE.getPasswordCharacterSetPropertyDefinition());
302    }
303
304
305
306    /** {@inheritDoc} */
307    public void setPasswordCharacterSet(Collection<String> values) {
308      impl.setPropertyValues(INSTANCE.getPasswordCharacterSetPropertyDefinition(), values);
309    }
310
311
312
313    /** {@inheritDoc} */
314    public String getPasswordFormat() {
315      return impl.getPropertyValue(INSTANCE.getPasswordFormatPropertyDefinition());
316    }
317
318
319
320    /** {@inheritDoc} */
321    public void setPasswordFormat(String value) {
322      impl.setPropertyValue(INSTANCE.getPasswordFormatPropertyDefinition(), value);
323    }
324
325
326
327    /** {@inheritDoc} */
328    public ManagedObjectDefinition<? extends RandomPasswordGeneratorCfgClient, ? extends RandomPasswordGeneratorCfg> definition() {
329      return INSTANCE;
330    }
331
332
333
334    /** {@inheritDoc} */
335    public PropertyProvider properties() {
336      return impl;
337    }
338
339
340
341    /** {@inheritDoc} */
342    public void commit() throws ManagedObjectAlreadyExistsException,
343        MissingMandatoryPropertiesException, ConcurrentModificationException,
344        OperationRejectedException, LdapException {
345      impl.commit();
346    }
347
348
349
350    /** {@inheritDoc} */
351    public String toString() {
352      return impl.toString();
353    }
354  }
355
356
357
358  /**
359   * Managed object server implementation.
360   */
361  private static class RandomPasswordGeneratorCfgServerImpl implements
362    RandomPasswordGeneratorCfg {
363
364    /** Private implementation. */
365    private ServerManagedObject<? extends RandomPasswordGeneratorCfg> impl;
366
367    /** The value of the "enabled" property. */
368    private final boolean pEnabled;
369
370    /** The value of the "java-class" property. */
371    private final String pJavaClass;
372
373    /** The value of the "password-character-set" property. */
374    private final SortedSet<String> pPasswordCharacterSet;
375
376    /** The value of the "password-format" property. */
377    private final String pPasswordFormat;
378
379
380
381    /** Private constructor. */
382    private RandomPasswordGeneratorCfgServerImpl(ServerManagedObject<? extends RandomPasswordGeneratorCfg> impl) {
383      this.impl = impl;
384      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
385      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
386      this.pPasswordCharacterSet = impl.getPropertyValues(INSTANCE.getPasswordCharacterSetPropertyDefinition());
387      this.pPasswordFormat = impl.getPropertyValue(INSTANCE.getPasswordFormatPropertyDefinition());
388    }
389
390
391
392    /** {@inheritDoc} */
393    public void addRandomChangeListener(
394        ConfigurationChangeListener<RandomPasswordGeneratorCfg> listener) {
395      impl.registerChangeListener(listener);
396    }
397
398
399
400    /** {@inheritDoc} */
401    public void removeRandomChangeListener(
402        ConfigurationChangeListener<RandomPasswordGeneratorCfg> listener) {
403      impl.deregisterChangeListener(listener);
404    }
405    /** {@inheritDoc} */
406    public void addChangeListener(
407        ConfigurationChangeListener<PasswordGeneratorCfg> listener) {
408      impl.registerChangeListener(listener);
409    }
410
411
412
413    /** {@inheritDoc} */
414    public void removeChangeListener(
415        ConfigurationChangeListener<PasswordGeneratorCfg> listener) {
416      impl.deregisterChangeListener(listener);
417    }
418
419
420
421    /** {@inheritDoc} */
422    public boolean isEnabled() {
423      return pEnabled;
424    }
425
426
427
428    /** {@inheritDoc} */
429    public String getJavaClass() {
430      return pJavaClass;
431    }
432
433
434
435    /** {@inheritDoc} */
436    public SortedSet<String> getPasswordCharacterSet() {
437      return pPasswordCharacterSet;
438    }
439
440
441
442    /** {@inheritDoc} */
443    public String getPasswordFormat() {
444      return pPasswordFormat;
445    }
446
447
448
449    /** {@inheritDoc} */
450    public Class<? extends RandomPasswordGeneratorCfg> configurationClass() {
451      return RandomPasswordGeneratorCfg.class;
452    }
453
454
455
456    /** {@inheritDoc} */
457    public DN dn() {
458      return impl.getDN();
459    }
460
461
462
463    /** {@inheritDoc} */
464    public String toString() {
465      return impl.toString();
466    }
467  }
468}