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