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