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 org.opends.server.admin.AdministratorAction; 031import org.opends.server.admin.BooleanPropertyDefinition; 032import org.opends.server.admin.ClassPropertyDefinition; 033import org.opends.server.admin.client.AuthorizationException; 034import org.opends.server.admin.client.CommunicationException; 035import org.opends.server.admin.client.ConcurrentModificationException; 036import org.opends.server.admin.client.ManagedObject; 037import org.opends.server.admin.client.MissingMandatoryPropertiesException; 038import org.opends.server.admin.client.OperationRejectedException; 039import org.opends.server.admin.DefaultBehaviorProvider; 040import org.opends.server.admin.DefinedDefaultBehaviorProvider; 041import org.opends.server.admin.IntegerPropertyDefinition; 042import org.opends.server.admin.ManagedObjectAlreadyExistsException; 043import org.opends.server.admin.ManagedObjectDefinition; 044import org.opends.server.admin.PropertyOption; 045import org.opends.server.admin.PropertyProvider; 046import org.opends.server.admin.server.ConfigurationChangeListener; 047import org.opends.server.admin.server.ServerManagedObject; 048import org.opends.server.admin.std.client.RepeatedCharactersPasswordValidatorCfgClient; 049import org.opends.server.admin.std.server.PasswordValidatorCfg; 050import org.opends.server.admin.std.server.RepeatedCharactersPasswordValidatorCfg; 051import org.opends.server.admin.Tag; 052import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 053import org.opends.server.types.DN; 054 055 056 057/** 058 * An interface for querying the Repeated Characters Password 059 * Validator managed object definition meta information. 060 * <p> 061 * The Repeated Characters Password Validator is used to determine 062 * whether a proposed password is acceptable based on the number of 063 * times any character appears consecutively in a password value. 064 */ 065public final class RepeatedCharactersPasswordValidatorCfgDefn extends ManagedObjectDefinition<RepeatedCharactersPasswordValidatorCfgClient, RepeatedCharactersPasswordValidatorCfg> { 066 067 // The singleton configuration definition instance. 068 private static final RepeatedCharactersPasswordValidatorCfgDefn INSTANCE = new RepeatedCharactersPasswordValidatorCfgDefn(); 069 070 071 072 // The "case-sensitive-validation" property definition. 073 private static final BooleanPropertyDefinition PD_CASE_SENSITIVE_VALIDATION; 074 075 076 077 // The "java-class" property definition. 078 private static final ClassPropertyDefinition PD_JAVA_CLASS; 079 080 081 082 // The "max-consecutive-length" property definition. 083 private static final IntegerPropertyDefinition PD_MAX_CONSECUTIVE_LENGTH; 084 085 086 087 // Build the "case-sensitive-validation" property definition. 088 static { 089 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "case-sensitive-validation"); 090 builder.setOption(PropertyOption.MANDATORY); 091 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "case-sensitive-validation")); 092 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 093 PD_CASE_SENSITIVE_VALIDATION = builder.getInstance(); 094 INSTANCE.registerPropertyDefinition(PD_CASE_SENSITIVE_VALIDATION); 095 } 096 097 098 099 // Build the "java-class" property definition. 100 static { 101 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 102 builder.setOption(PropertyOption.MANDATORY); 103 builder.setOption(PropertyOption.ADVANCED); 104 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 105 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.RepeatedCharactersPasswordValidator"); 106 builder.setDefaultBehaviorProvider(provider); 107 builder.addInstanceOf("org.opends.server.api.PasswordValidator"); 108 PD_JAVA_CLASS = builder.getInstance(); 109 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 110 } 111 112 113 114 // Build the "max-consecutive-length" property definition. 115 static { 116 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-consecutive-length"); 117 builder.setOption(PropertyOption.MANDATORY); 118 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-consecutive-length")); 119 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>()); 120 builder.setLowerLimit(0); 121 PD_MAX_CONSECUTIVE_LENGTH = builder.getInstance(); 122 INSTANCE.registerPropertyDefinition(PD_MAX_CONSECUTIVE_LENGTH); 123 } 124 125 126 127 // Register the tags associated with this managed object definition. 128 static { 129 INSTANCE.registerTag(Tag.valueOf("user-management")); 130 } 131 132 133 134 /** 135 * Get the Repeated Characters Password Validator configuration 136 * definition singleton. 137 * 138 * @return Returns the Repeated Characters Password Validator 139 * configuration definition singleton. 140 */ 141 public static RepeatedCharactersPasswordValidatorCfgDefn getInstance() { 142 return INSTANCE; 143 } 144 145 146 147 /** 148 * Private constructor. 149 */ 150 private RepeatedCharactersPasswordValidatorCfgDefn() { 151 super("repeated-characters-password-validator", PasswordValidatorCfgDefn.getInstance()); 152 } 153 154 155 156 /** 157 * {@inheritDoc} 158 */ 159 public RepeatedCharactersPasswordValidatorCfgClient createClientConfiguration( 160 ManagedObject<? extends RepeatedCharactersPasswordValidatorCfgClient> impl) { 161 return new RepeatedCharactersPasswordValidatorCfgClientImpl(impl); 162 } 163 164 165 166 /** 167 * {@inheritDoc} 168 */ 169 public RepeatedCharactersPasswordValidatorCfg createServerConfiguration( 170 ServerManagedObject<? extends RepeatedCharactersPasswordValidatorCfg> impl) { 171 return new RepeatedCharactersPasswordValidatorCfgServerImpl(impl); 172 } 173 174 175 176 /** 177 * {@inheritDoc} 178 */ 179 public Class<RepeatedCharactersPasswordValidatorCfg> getServerConfigurationClass() { 180 return RepeatedCharactersPasswordValidatorCfg.class; 181 } 182 183 184 185 /** 186 * Get the "case-sensitive-validation" property definition. 187 * <p> 188 * Indicates whether this password validator should treat password 189 * characters in a case-sensitive manner. 190 * <p> 191 * If the value of this property is false, the validator ignores any 192 * differences in capitalization when looking for consecutive 193 * characters in the password. If the value is true, the validator 194 * considers a character to be repeating only if all consecutive 195 * occurrences use the same capitalization. 196 * 197 * @return Returns the "case-sensitive-validation" property definition. 198 */ 199 public BooleanPropertyDefinition getCaseSensitiveValidationPropertyDefinition() { 200 return PD_CASE_SENSITIVE_VALIDATION; 201 } 202 203 204 205 /** 206 * Get the "enabled" property definition. 207 * <p> 208 * Indicates whether the password validator is enabled for use. 209 * 210 * @return Returns the "enabled" property definition. 211 */ 212 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 213 return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition(); 214 } 215 216 217 218 /** 219 * Get the "java-class" property definition. 220 * <p> 221 * Specifies the fully-qualified name of the Java class that 222 * provides the password validator implementation. 223 * 224 * @return Returns the "java-class" property definition. 225 */ 226 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 227 return PD_JAVA_CLASS; 228 } 229 230 231 232 /** 233 * Get the "max-consecutive-length" property definition. 234 * <p> 235 * Specifies the maximum number of times that any character can 236 * appear consecutively in a password value. 237 * <p> 238 * A value of zero indicates that no maximum limit is enforced. 239 * 240 * @return Returns the "max-consecutive-length" property definition. 241 */ 242 public IntegerPropertyDefinition getMaxConsecutiveLengthPropertyDefinition() { 243 return PD_MAX_CONSECUTIVE_LENGTH; 244 } 245 246 247 248 /** 249 * Managed object client implementation. 250 */ 251 private static class RepeatedCharactersPasswordValidatorCfgClientImpl implements 252 RepeatedCharactersPasswordValidatorCfgClient { 253 254 // Private implementation. 255 private ManagedObject<? extends RepeatedCharactersPasswordValidatorCfgClient> impl; 256 257 258 259 // Private constructor. 260 private RepeatedCharactersPasswordValidatorCfgClientImpl( 261 ManagedObject<? extends RepeatedCharactersPasswordValidatorCfgClient> impl) { 262 this.impl = impl; 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 public Boolean isCaseSensitiveValidation() { 271 return impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition()); 272 } 273 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 public void setCaseSensitiveValidation(boolean value) { 280 impl.setPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition(), value); 281 } 282 283 284 285 /** 286 * {@inheritDoc} 287 */ 288 public Boolean isEnabled() { 289 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 290 } 291 292 293 294 /** 295 * {@inheritDoc} 296 */ 297 public void setEnabled(boolean value) { 298 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 299 } 300 301 302 303 /** 304 * {@inheritDoc} 305 */ 306 public String getJavaClass() { 307 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 308 } 309 310 311 312 /** 313 * {@inheritDoc} 314 */ 315 public void setJavaClass(String value) { 316 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 317 } 318 319 320 321 /** 322 * {@inheritDoc} 323 */ 324 public Integer getMaxConsecutiveLength() { 325 return impl.getPropertyValue(INSTANCE.getMaxConsecutiveLengthPropertyDefinition()); 326 } 327 328 329 330 /** 331 * {@inheritDoc} 332 */ 333 public void setMaxConsecutiveLength(int value) { 334 impl.setPropertyValue(INSTANCE.getMaxConsecutiveLengthPropertyDefinition(), value); 335 } 336 337 338 339 /** 340 * {@inheritDoc} 341 */ 342 public ManagedObjectDefinition<? extends RepeatedCharactersPasswordValidatorCfgClient, ? extends RepeatedCharactersPasswordValidatorCfg> definition() { 343 return INSTANCE; 344 } 345 346 347 348 /** 349 * {@inheritDoc} 350 */ 351 public PropertyProvider properties() { 352 return impl; 353 } 354 355 356 357 /** 358 * {@inheritDoc} 359 */ 360 public void commit() throws ManagedObjectAlreadyExistsException, 361 MissingMandatoryPropertiesException, ConcurrentModificationException, 362 OperationRejectedException, AuthorizationException, 363 CommunicationException { 364 impl.commit(); 365 } 366 367 } 368 369 370 371 /** 372 * Managed object server implementation. 373 */ 374 private static class RepeatedCharactersPasswordValidatorCfgServerImpl implements 375 RepeatedCharactersPasswordValidatorCfg { 376 377 // Private implementation. 378 private ServerManagedObject<? extends RepeatedCharactersPasswordValidatorCfg> impl; 379 380 // The value of the "case-sensitive-validation" property. 381 private final boolean pCaseSensitiveValidation; 382 383 // The value of the "enabled" property. 384 private final boolean pEnabled; 385 386 // The value of the "java-class" property. 387 private final String pJavaClass; 388 389 // The value of the "max-consecutive-length" property. 390 private final int pMaxConsecutiveLength; 391 392 393 394 // Private constructor. 395 private RepeatedCharactersPasswordValidatorCfgServerImpl(ServerManagedObject<? extends RepeatedCharactersPasswordValidatorCfg> impl) { 396 this.impl = impl; 397 this.pCaseSensitiveValidation = impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition()); 398 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 399 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 400 this.pMaxConsecutiveLength = impl.getPropertyValue(INSTANCE.getMaxConsecutiveLengthPropertyDefinition()); 401 } 402 403 404 405 /** 406 * {@inheritDoc} 407 */ 408 public void addRepeatedCharactersChangeListener( 409 ConfigurationChangeListener<RepeatedCharactersPasswordValidatorCfg> listener) { 410 impl.registerChangeListener(listener); 411 } 412 413 414 415 /** 416 * {@inheritDoc} 417 */ 418 public void removeRepeatedCharactersChangeListener( 419 ConfigurationChangeListener<RepeatedCharactersPasswordValidatorCfg> listener) { 420 impl.deregisterChangeListener(listener); 421 } 422 /** 423 * {@inheritDoc} 424 */ 425 public void addChangeListener( 426 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 427 impl.registerChangeListener(listener); 428 } 429 430 431 432 /** 433 * {@inheritDoc} 434 */ 435 public void removeChangeListener( 436 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 437 impl.deregisterChangeListener(listener); 438 } 439 440 441 442 /** 443 * {@inheritDoc} 444 */ 445 public boolean isCaseSensitiveValidation() { 446 return pCaseSensitiveValidation; 447 } 448 449 450 451 /** 452 * {@inheritDoc} 453 */ 454 public boolean isEnabled() { 455 return pEnabled; 456 } 457 458 459 460 /** 461 * {@inheritDoc} 462 */ 463 public String getJavaClass() { 464 return pJavaClass; 465 } 466 467 468 469 /** 470 * {@inheritDoc} 471 */ 472 public int getMaxConsecutiveLength() { 473 return pMaxConsecutiveLength; 474 } 475 476 477 478 /** 479 * {@inheritDoc} 480 */ 481 public Class<? extends RepeatedCharactersPasswordValidatorCfg> configurationClass() { 482 return RepeatedCharactersPasswordValidatorCfg.class; 483 } 484 485 486 487 /** 488 * {@inheritDoc} 489 */ 490 public DN dn() { 491 return impl.getDN(); 492 } 493 494 } 495}