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