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.SimilarityBasedPasswordValidatorCfgClient; 049import org.opends.server.admin.std.server.PasswordValidatorCfg; 050import org.opends.server.admin.std.server.SimilarityBasedPasswordValidatorCfg; 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 Similarity Based Password Validator 059 * managed object definition meta information. 060 * <p> 061 * The Similarity Based Password Validator determines whether a 062 * proposed password is acceptable by measuring how similar it is to 063 * the user's current password. 064 */ 065public final class SimilarityBasedPasswordValidatorCfgDefn extends ManagedObjectDefinition<SimilarityBasedPasswordValidatorCfgClient, SimilarityBasedPasswordValidatorCfg> { 066 067 // The singleton configuration definition instance. 068 private static final SimilarityBasedPasswordValidatorCfgDefn INSTANCE = new SimilarityBasedPasswordValidatorCfgDefn(); 069 070 071 072 // The "java-class" property definition. 073 private static final ClassPropertyDefinition PD_JAVA_CLASS; 074 075 076 077 // The "min-password-difference" property definition. 078 private static final IntegerPropertyDefinition PD_MIN_PASSWORD_DIFFERENCE; 079 080 081 082 // Build the "java-class" property definition. 083 static { 084 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 085 builder.setOption(PropertyOption.MANDATORY); 086 builder.setOption(PropertyOption.ADVANCED); 087 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 088 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SimilarityBasedPasswordValidator"); 089 builder.setDefaultBehaviorProvider(provider); 090 builder.addInstanceOf("org.opends.server.api.PasswordValidator"); 091 PD_JAVA_CLASS = builder.getInstance(); 092 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 093 } 094 095 096 097 // Build the "min-password-difference" property definition. 098 static { 099 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-password-difference"); 100 builder.setOption(PropertyOption.MANDATORY); 101 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-password-difference")); 102 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>()); 103 builder.setUpperLimit(2147483647); 104 builder.setLowerLimit(0); 105 PD_MIN_PASSWORD_DIFFERENCE = builder.getInstance(); 106 INSTANCE.registerPropertyDefinition(PD_MIN_PASSWORD_DIFFERENCE); 107 } 108 109 110 111 // Register the tags associated with this managed object definition. 112 static { 113 INSTANCE.registerTag(Tag.valueOf("user-management")); 114 } 115 116 117 118 /** 119 * Get the Similarity Based Password Validator configuration 120 * definition singleton. 121 * 122 * @return Returns the Similarity Based Password Validator 123 * configuration definition singleton. 124 */ 125 public static SimilarityBasedPasswordValidatorCfgDefn getInstance() { 126 return INSTANCE; 127 } 128 129 130 131 /** 132 * Private constructor. 133 */ 134 private SimilarityBasedPasswordValidatorCfgDefn() { 135 super("similarity-based-password-validator", PasswordValidatorCfgDefn.getInstance()); 136 } 137 138 139 140 /** 141 * {@inheritDoc} 142 */ 143 public SimilarityBasedPasswordValidatorCfgClient createClientConfiguration( 144 ManagedObject<? extends SimilarityBasedPasswordValidatorCfgClient> impl) { 145 return new SimilarityBasedPasswordValidatorCfgClientImpl(impl); 146 } 147 148 149 150 /** 151 * {@inheritDoc} 152 */ 153 public SimilarityBasedPasswordValidatorCfg createServerConfiguration( 154 ServerManagedObject<? extends SimilarityBasedPasswordValidatorCfg> impl) { 155 return new SimilarityBasedPasswordValidatorCfgServerImpl(impl); 156 } 157 158 159 160 /** 161 * {@inheritDoc} 162 */ 163 public Class<SimilarityBasedPasswordValidatorCfg> getServerConfigurationClass() { 164 return SimilarityBasedPasswordValidatorCfg.class; 165 } 166 167 168 169 /** 170 * Get the "enabled" property definition. 171 * <p> 172 * Indicates whether the password validator is enabled for use. 173 * 174 * @return Returns the "enabled" property definition. 175 */ 176 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 177 return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition(); 178 } 179 180 181 182 /** 183 * Get the "java-class" property definition. 184 * <p> 185 * Specifies the fully-qualified name of the Java class that 186 * provides the password validator implementation. 187 * 188 * @return Returns the "java-class" property definition. 189 */ 190 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 191 return PD_JAVA_CLASS; 192 } 193 194 195 196 /** 197 * Get the "min-password-difference" property definition. 198 * <p> 199 * Specifies the minimum difference of new and old password. 200 * <p> 201 * A value of zero indicates that no difference between passwords is 202 * acceptable. 203 * 204 * @return Returns the "min-password-difference" property definition. 205 */ 206 public IntegerPropertyDefinition getMinPasswordDifferencePropertyDefinition() { 207 return PD_MIN_PASSWORD_DIFFERENCE; 208 } 209 210 211 212 /** 213 * Managed object client implementation. 214 */ 215 private static class SimilarityBasedPasswordValidatorCfgClientImpl implements 216 SimilarityBasedPasswordValidatorCfgClient { 217 218 // Private implementation. 219 private ManagedObject<? extends SimilarityBasedPasswordValidatorCfgClient> impl; 220 221 222 223 // Private constructor. 224 private SimilarityBasedPasswordValidatorCfgClientImpl( 225 ManagedObject<? extends SimilarityBasedPasswordValidatorCfgClient> impl) { 226 this.impl = impl; 227 } 228 229 230 231 /** 232 * {@inheritDoc} 233 */ 234 public Boolean isEnabled() { 235 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 236 } 237 238 239 240 /** 241 * {@inheritDoc} 242 */ 243 public void setEnabled(boolean value) { 244 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 245 } 246 247 248 249 /** 250 * {@inheritDoc} 251 */ 252 public String getJavaClass() { 253 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 public void setJavaClass(String value) { 262 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 public Integer getMinPasswordDifference() { 271 return impl.getPropertyValue(INSTANCE.getMinPasswordDifferencePropertyDefinition()); 272 } 273 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 public void setMinPasswordDifference(int value) { 280 impl.setPropertyValue(INSTANCE.getMinPasswordDifferencePropertyDefinition(), value); 281 } 282 283 284 285 /** 286 * {@inheritDoc} 287 */ 288 public ManagedObjectDefinition<? extends SimilarityBasedPasswordValidatorCfgClient, ? extends SimilarityBasedPasswordValidatorCfg> definition() { 289 return INSTANCE; 290 } 291 292 293 294 /** 295 * {@inheritDoc} 296 */ 297 public PropertyProvider properties() { 298 return impl; 299 } 300 301 302 303 /** 304 * {@inheritDoc} 305 */ 306 public void commit() throws ManagedObjectAlreadyExistsException, 307 MissingMandatoryPropertiesException, ConcurrentModificationException, 308 OperationRejectedException, AuthorizationException, 309 CommunicationException { 310 impl.commit(); 311 } 312 313 } 314 315 316 317 /** 318 * Managed object server implementation. 319 */ 320 private static class SimilarityBasedPasswordValidatorCfgServerImpl implements 321 SimilarityBasedPasswordValidatorCfg { 322 323 // Private implementation. 324 private ServerManagedObject<? extends SimilarityBasedPasswordValidatorCfg> impl; 325 326 // The value of the "enabled" property. 327 private final boolean pEnabled; 328 329 // The value of the "java-class" property. 330 private final String pJavaClass; 331 332 // The value of the "min-password-difference" property. 333 private final int pMinPasswordDifference; 334 335 336 337 // Private constructor. 338 private SimilarityBasedPasswordValidatorCfgServerImpl(ServerManagedObject<? extends SimilarityBasedPasswordValidatorCfg> impl) { 339 this.impl = impl; 340 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 341 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 342 this.pMinPasswordDifference = impl.getPropertyValue(INSTANCE.getMinPasswordDifferencePropertyDefinition()); 343 } 344 345 346 347 /** 348 * {@inheritDoc} 349 */ 350 public void addSimilarityBasedChangeListener( 351 ConfigurationChangeListener<SimilarityBasedPasswordValidatorCfg> listener) { 352 impl.registerChangeListener(listener); 353 } 354 355 356 357 /** 358 * {@inheritDoc} 359 */ 360 public void removeSimilarityBasedChangeListener( 361 ConfigurationChangeListener<SimilarityBasedPasswordValidatorCfg> listener) { 362 impl.deregisterChangeListener(listener); 363 } 364 /** 365 * {@inheritDoc} 366 */ 367 public void addChangeListener( 368 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 369 impl.registerChangeListener(listener); 370 } 371 372 373 374 /** 375 * {@inheritDoc} 376 */ 377 public void removeChangeListener( 378 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 379 impl.deregisterChangeListener(listener); 380 } 381 382 383 384 /** 385 * {@inheritDoc} 386 */ 387 public boolean isEnabled() { 388 return pEnabled; 389 } 390 391 392 393 /** 394 * {@inheritDoc} 395 */ 396 public String getJavaClass() { 397 return pJavaClass; 398 } 399 400 401 402 /** 403 * {@inheritDoc} 404 */ 405 public int getMinPasswordDifference() { 406 return pMinPasswordDifference; 407 } 408 409 410 411 /** 412 * {@inheritDoc} 413 */ 414 public Class<? extends SimilarityBasedPasswordValidatorCfg> configurationClass() { 415 return SimilarityBasedPasswordValidatorCfg.class; 416 } 417 418 419 420 /** 421 * {@inheritDoc} 422 */ 423 public DN dn() { 424 return impl.getDN(); 425 } 426 427 } 428}