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