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