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