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