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