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.AliasDefaultBehaviorProvider; 024import org.forgerock.opendj.config.BooleanPropertyDefinition; 025import org.forgerock.opendj.config.ClassPropertyDefinition; 026import org.forgerock.opendj.config.client.ConcurrentModificationException; 027import org.forgerock.opendj.config.client.ManagedObject; 028import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 029import org.forgerock.opendj.config.client.OperationRejectedException; 030import org.forgerock.opendj.config.conditions.Conditions; 031import org.forgerock.opendj.config.DefaultBehaviorProvider; 032import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 033import org.forgerock.opendj.config.GenericConstraint; 034import org.forgerock.opendj.config.IntegerPropertyDefinition; 035import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 036import org.forgerock.opendj.config.ManagedObjectDefinition; 037import org.forgerock.opendj.config.PropertyOption; 038import org.forgerock.opendj.config.PropertyProvider; 039import org.forgerock.opendj.config.server.ConfigurationChangeListener; 040import org.forgerock.opendj.config.server.ServerManagedObject; 041import org.forgerock.opendj.config.StringPropertyDefinition; 042import org.forgerock.opendj.config.Tag; 043import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 044import org.forgerock.opendj.ldap.DN; 045import org.forgerock.opendj.ldap.LdapException; 046import org.forgerock.opendj.server.config.client.CharacterSetPasswordValidatorCfgClient; 047import org.forgerock.opendj.server.config.server.CharacterSetPasswordValidatorCfg; 048import org.forgerock.opendj.server.config.server.PasswordValidatorCfg; 049 050 051 052/** 053 * An interface for querying the Character Set Password Validator 054 * managed object definition meta information. 055 * <p> 056 * The Character Set Password Validator determines whether a proposed 057 * password is acceptable by checking whether it contains a sufficient 058 * number of characters from one or more user-defined character sets 059 * and ranges. 060 */ 061public final class CharacterSetPasswordValidatorCfgDefn extends ManagedObjectDefinition<CharacterSetPasswordValidatorCfgClient, CharacterSetPasswordValidatorCfg> { 062 063 /** The singleton configuration definition instance. */ 064 private static final CharacterSetPasswordValidatorCfgDefn INSTANCE = new CharacterSetPasswordValidatorCfgDefn(); 065 066 067 068 /** The "allow-unclassified-characters" property definition. */ 069 private static final BooleanPropertyDefinition PD_ALLOW_UNCLASSIFIED_CHARACTERS; 070 071 072 073 /** The "character-set" property definition. */ 074 private static final StringPropertyDefinition PD_CHARACTER_SET; 075 076 077 078 /** The "character-set-ranges" property definition. */ 079 private static final StringPropertyDefinition PD_CHARACTER_SET_RANGES; 080 081 082 083 /** The "java-class" property definition. */ 084 private static final ClassPropertyDefinition PD_JAVA_CLASS; 085 086 087 088 /** The "min-character-sets" property definition. */ 089 private static final IntegerPropertyDefinition PD_MIN_CHARACTER_SETS; 090 091 092 093 /** Build the "allow-unclassified-characters" property definition. */ 094 static { 095 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-unclassified-characters"); 096 builder.setOption(PropertyOption.MANDATORY); 097 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-unclassified-characters")); 098 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 099 PD_ALLOW_UNCLASSIFIED_CHARACTERS = builder.getInstance(); 100 INSTANCE.registerPropertyDefinition(PD_ALLOW_UNCLASSIFIED_CHARACTERS); 101 } 102 103 104 105 /** Build the "character-set" property definition. */ 106 static { 107 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "character-set"); 108 builder.setOption(PropertyOption.MULTI_VALUED); 109 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "character-set")); 110 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "character-set")); 111 builder.setCaseInsensitive(false); 112 PD_CHARACTER_SET = builder.getInstance(); 113 INSTANCE.registerPropertyDefinition(PD_CHARACTER_SET); 114 } 115 116 117 118 /** Build the "character-set-ranges" property definition. */ 119 static { 120 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "character-set-ranges"); 121 builder.setOption(PropertyOption.MULTI_VALUED); 122 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "character-set-ranges")); 123 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "character-set-ranges")); 124 builder.setCaseInsensitive(false); 125 PD_CHARACTER_SET_RANGES = builder.getInstance(); 126 INSTANCE.registerPropertyDefinition(PD_CHARACTER_SET_RANGES); 127 } 128 129 130 131 /** Build the "java-class" property definition. */ 132 static { 133 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 134 builder.setOption(PropertyOption.MANDATORY); 135 builder.setOption(PropertyOption.ADVANCED); 136 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 137 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.CharacterSetPasswordValidator"); 138 builder.setDefaultBehaviorProvider(provider); 139 builder.addInstanceOf("org.opends.server.api.PasswordValidator"); 140 PD_JAVA_CLASS = builder.getInstance(); 141 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 142 } 143 144 145 146 /** Build the "min-character-sets" property definition. */ 147 static { 148 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-character-sets"); 149 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-character-sets")); 150 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<Integer>(INSTANCE, "min-character-sets")); 151 PD_MIN_CHARACTER_SETS = builder.getInstance(); 152 INSTANCE.registerPropertyDefinition(PD_MIN_CHARACTER_SETS); 153 } 154 155 156 157 // Register the tags associated with this managed object definition. 158 static { 159 INSTANCE.registerTag(Tag.valueOf("user-management")); 160 } 161 162 163 164 // Register the constraints associated with this managed object definition. 165 static { 166 INSTANCE.registerConstraint(new GenericConstraint(INSTANCE, 1, Conditions.or(Conditions.isPresent("character-set"), Conditions.isPresent("character-set-ranges")))); 167 } 168 169 170 171 /** 172 * Get the Character Set Password Validator configuration definition 173 * singleton. 174 * 175 * @return Returns the Character Set Password Validator 176 * configuration definition singleton. 177 */ 178 public static CharacterSetPasswordValidatorCfgDefn getInstance() { 179 return INSTANCE; 180 } 181 182 183 184 /** 185 * Private constructor. 186 */ 187 private CharacterSetPasswordValidatorCfgDefn() { 188 super("character-set-password-validator", PasswordValidatorCfgDefn.getInstance()); 189 } 190 191 192 193 /** {@inheritDoc} */ 194 public CharacterSetPasswordValidatorCfgClient createClientConfiguration( 195 ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl) { 196 return new CharacterSetPasswordValidatorCfgClientImpl(impl); 197 } 198 199 200 201 /** {@inheritDoc} */ 202 public CharacterSetPasswordValidatorCfg createServerConfiguration( 203 ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl) { 204 return new CharacterSetPasswordValidatorCfgServerImpl(impl); 205 } 206 207 208 209 /** {@inheritDoc} */ 210 public Class<CharacterSetPasswordValidatorCfg> getServerConfigurationClass() { 211 return CharacterSetPasswordValidatorCfg.class; 212 } 213 214 215 216 /** 217 * Get the "allow-unclassified-characters" property definition. 218 * <p> 219 * Indicates whether this password validator allows passwords to 220 * contain characters outside of any of the user-defined character 221 * sets and ranges. 222 * <p> 223 * If this is "false", then only those characters in the 224 * user-defined character sets and ranges may be used in passwords. 225 * Any password containing a character not included in any character 226 * set or range will be rejected. 227 * 228 * @return Returns the "allow-unclassified-characters" property definition. 229 */ 230 public BooleanPropertyDefinition getAllowUnclassifiedCharactersPropertyDefinition() { 231 return PD_ALLOW_UNCLASSIFIED_CHARACTERS; 232 } 233 234 235 236 /** 237 * Get the "character-set" property definition. 238 * <p> 239 * Specifies a character set containing characters that a password 240 * may contain and a value indicating the minimum number of 241 * characters required from that set. 242 * <p> 243 * Each value must be an integer (indicating the minimum required 244 * characters from the set which may be zero, indicating that the 245 * character set is optional) followed by a colon and the characters 246 * to include in that set (for example, 247 * "3:abcdefghijklmnopqrstuvwxyz" indicates that a user password must 248 * contain at least three characters from the set of lowercase ASCII 249 * letters). Multiple character sets can be defined in separate 250 * values, although no character can appear in more than one 251 * character set. 252 * 253 * @return Returns the "character-set" property definition. 254 */ 255 public StringPropertyDefinition getCharacterSetPropertyDefinition() { 256 return PD_CHARACTER_SET; 257 } 258 259 260 261 /** 262 * Get the "character-set-ranges" property definition. 263 * <p> 264 * Specifies a character range containing characters that a password 265 * may contain and a value indicating the minimum number of 266 * characters required from that range. 267 * <p> 268 * Each value must be an integer (indicating the minimum required 269 * characters from the range which may be zero, indicating that the 270 * character range is optional) followed by a colon and one or more 271 * range specifications. A range specification is 3 characters: the 272 * first character allowed, a minus, and the last character allowed. 273 * For example, "3:A-Za-z0-9". The ranges in each value should not 274 * overlap, and the characters in each range specification should be 275 * ordered. 276 * 277 * @return Returns the "character-set-ranges" property definition. 278 */ 279 public StringPropertyDefinition getCharacterSetRangesPropertyDefinition() { 280 return PD_CHARACTER_SET_RANGES; 281 } 282 283 284 285 /** 286 * Get the "enabled" property definition. 287 * <p> 288 * Indicates whether the password validator is enabled for use. 289 * 290 * @return Returns the "enabled" property definition. 291 */ 292 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 293 return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition(); 294 } 295 296 297 298 /** 299 * Get the "java-class" property definition. 300 * <p> 301 * Specifies the fully-qualified name of the Java class that 302 * provides the password validator implementation. 303 * 304 * @return Returns the "java-class" property definition. 305 */ 306 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 307 return PD_JAVA_CLASS; 308 } 309 310 311 312 /** 313 * Get the "min-character-sets" property definition. 314 * <p> 315 * Specifies the minimum number of character sets and ranges that a 316 * password must contain. 317 * <p> 318 * This property should only be used in conjunction with optional 319 * character sets and ranges (those requiring zero characters). Its 320 * value must include any mandatory character sets and ranges (those 321 * requiring greater than zero characters). This is useful in 322 * situations where a password must contain characters from mandatory 323 * character sets and ranges, and characters from at least N optional 324 * character sets and ranges. For example, it is quite common to 325 * require that a password contains at least one non-alphanumeric 326 * character as well as characters from two alphanumeric character 327 * sets (lower-case, upper-case, digits). In this case, this property 328 * should be set to 3. 329 * 330 * @return Returns the "min-character-sets" property definition. 331 */ 332 public IntegerPropertyDefinition getMinCharacterSetsPropertyDefinition() { 333 return PD_MIN_CHARACTER_SETS; 334 } 335 336 337 338 /** 339 * Managed object client implementation. 340 */ 341 private static class CharacterSetPasswordValidatorCfgClientImpl implements 342 CharacterSetPasswordValidatorCfgClient { 343 344 /** Private implementation. */ 345 private ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl; 346 347 348 349 /** Private constructor. */ 350 private CharacterSetPasswordValidatorCfgClientImpl( 351 ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl) { 352 this.impl = impl; 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public Boolean isAllowUnclassifiedCharacters() { 359 return impl.getPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition()); 360 } 361 362 363 364 /** {@inheritDoc} */ 365 public void setAllowUnclassifiedCharacters(boolean value) { 366 impl.setPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition(), value); 367 } 368 369 370 371 /** {@inheritDoc} */ 372 public SortedSet<String> getCharacterSet() { 373 return impl.getPropertyValues(INSTANCE.getCharacterSetPropertyDefinition()); 374 } 375 376 377 378 /** {@inheritDoc} */ 379 public void setCharacterSet(Collection<String> values) { 380 impl.setPropertyValues(INSTANCE.getCharacterSetPropertyDefinition(), values); 381 } 382 383 384 385 /** {@inheritDoc} */ 386 public SortedSet<String> getCharacterSetRanges() { 387 return impl.getPropertyValues(INSTANCE.getCharacterSetRangesPropertyDefinition()); 388 } 389 390 391 392 /** {@inheritDoc} */ 393 public void setCharacterSetRanges(Collection<String> values) { 394 impl.setPropertyValues(INSTANCE.getCharacterSetRangesPropertyDefinition(), values); 395 } 396 397 398 399 /** {@inheritDoc} */ 400 public Boolean isEnabled() { 401 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 402 } 403 404 405 406 /** {@inheritDoc} */ 407 public void setEnabled(boolean value) { 408 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 409 } 410 411 412 413 /** {@inheritDoc} */ 414 public String getJavaClass() { 415 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 416 } 417 418 419 420 /** {@inheritDoc} */ 421 public void setJavaClass(String value) { 422 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 423 } 424 425 426 427 /** {@inheritDoc} */ 428 public Integer getMinCharacterSets() { 429 return impl.getPropertyValue(INSTANCE.getMinCharacterSetsPropertyDefinition()); 430 } 431 432 433 434 /** {@inheritDoc} */ 435 public void setMinCharacterSets(Integer value) { 436 impl.setPropertyValue(INSTANCE.getMinCharacterSetsPropertyDefinition(), value); 437 } 438 439 440 441 /** {@inheritDoc} */ 442 public ManagedObjectDefinition<? extends CharacterSetPasswordValidatorCfgClient, ? extends CharacterSetPasswordValidatorCfg> definition() { 443 return INSTANCE; 444 } 445 446 447 448 /** {@inheritDoc} */ 449 public PropertyProvider properties() { 450 return impl; 451 } 452 453 454 455 /** {@inheritDoc} */ 456 public void commit() throws ManagedObjectAlreadyExistsException, 457 MissingMandatoryPropertiesException, ConcurrentModificationException, 458 OperationRejectedException, LdapException { 459 impl.commit(); 460 } 461 462 463 464 /** {@inheritDoc} */ 465 public String toString() { 466 return impl.toString(); 467 } 468 } 469 470 471 472 /** 473 * Managed object server implementation. 474 */ 475 private static class CharacterSetPasswordValidatorCfgServerImpl implements 476 CharacterSetPasswordValidatorCfg { 477 478 /** Private implementation. */ 479 private ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl; 480 481 /** The value of the "allow-unclassified-characters" property. */ 482 private final boolean pAllowUnclassifiedCharacters; 483 484 /** The value of the "character-set" property. */ 485 private final SortedSet<String> pCharacterSet; 486 487 /** The value of the "character-set-ranges" property. */ 488 private final SortedSet<String> pCharacterSetRanges; 489 490 /** The value of the "enabled" property. */ 491 private final boolean pEnabled; 492 493 /** The value of the "java-class" property. */ 494 private final String pJavaClass; 495 496 /** The value of the "min-character-sets" property. */ 497 private final Integer pMinCharacterSets; 498 499 500 501 /** Private constructor. */ 502 private CharacterSetPasswordValidatorCfgServerImpl(ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl) { 503 this.impl = impl; 504 this.pAllowUnclassifiedCharacters = impl.getPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition()); 505 this.pCharacterSet = impl.getPropertyValues(INSTANCE.getCharacterSetPropertyDefinition()); 506 this.pCharacterSetRanges = impl.getPropertyValues(INSTANCE.getCharacterSetRangesPropertyDefinition()); 507 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 508 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 509 this.pMinCharacterSets = impl.getPropertyValue(INSTANCE.getMinCharacterSetsPropertyDefinition()); 510 } 511 512 513 514 /** {@inheritDoc} */ 515 public void addCharacterSetChangeListener( 516 ConfigurationChangeListener<CharacterSetPasswordValidatorCfg> listener) { 517 impl.registerChangeListener(listener); 518 } 519 520 521 522 /** {@inheritDoc} */ 523 public void removeCharacterSetChangeListener( 524 ConfigurationChangeListener<CharacterSetPasswordValidatorCfg> listener) { 525 impl.deregisterChangeListener(listener); 526 } 527 /** {@inheritDoc} */ 528 public void addChangeListener( 529 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 530 impl.registerChangeListener(listener); 531 } 532 533 534 535 /** {@inheritDoc} */ 536 public void removeChangeListener( 537 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 538 impl.deregisterChangeListener(listener); 539 } 540 541 542 543 /** {@inheritDoc} */ 544 public boolean isAllowUnclassifiedCharacters() { 545 return pAllowUnclassifiedCharacters; 546 } 547 548 549 550 /** {@inheritDoc} */ 551 public SortedSet<String> getCharacterSet() { 552 return pCharacterSet; 553 } 554 555 556 557 /** {@inheritDoc} */ 558 public SortedSet<String> getCharacterSetRanges() { 559 return pCharacterSetRanges; 560 } 561 562 563 564 /** {@inheritDoc} */ 565 public boolean isEnabled() { 566 return pEnabled; 567 } 568 569 570 571 /** {@inheritDoc} */ 572 public String getJavaClass() { 573 return pJavaClass; 574 } 575 576 577 578 /** {@inheritDoc} */ 579 public Integer getMinCharacterSets() { 580 return pMinCharacterSets; 581 } 582 583 584 585 /** {@inheritDoc} */ 586 public Class<? extends CharacterSetPasswordValidatorCfg> configurationClass() { 587 return CharacterSetPasswordValidatorCfg.class; 588 } 589 590 591 592 /** {@inheritDoc} */ 593 public DN dn() { 594 return impl.getDN(); 595 } 596 597 598 599 /** {@inheritDoc} */ 600 public String toString() { 601 return impl.toString(); 602 } 603 } 604}