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