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