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.ManagedObjectAlreadyExistsException; 038import org.forgerock.opendj.config.ManagedObjectDefinition; 039import org.forgerock.opendj.config.PropertyOption; 040import org.forgerock.opendj.config.PropertyProvider; 041import org.forgerock.opendj.config.server.ConfigurationChangeListener; 042import org.forgerock.opendj.config.server.ServerManagedObject; 043import org.forgerock.opendj.config.Tag; 044import org.forgerock.opendj.config.TopCfgDefn; 045import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 046import org.forgerock.opendj.ldap.DN; 047import org.forgerock.opendj.ldap.LdapException; 048import org.forgerock.opendj.server.config.client.PasswordValidatorCfgClient; 049import org.forgerock.opendj.server.config.server.PasswordValidatorCfg; 050 051 052 053/** 054 * An interface for querying the Password Validator managed object 055 * definition meta information. 056 * <p> 057 * Password Validators are responsible for determining whether a 058 * proposed password is acceptable for use and could include checks 059 * like ensuring it meets minimum length requirements, that it has an 060 * appropriate range of characters, or that it is not in the history. 061 */ 062public final class PasswordValidatorCfgDefn extends ManagedObjectDefinition<PasswordValidatorCfgClient, PasswordValidatorCfg> { 063 064 // The singleton configuration definition instance. 065 private static final PasswordValidatorCfgDefn INSTANCE = new PasswordValidatorCfgDefn(); 066 067 068 069 // The "enabled" property definition. 070 private static final BooleanPropertyDefinition PD_ENABLED; 071 072 073 074 // The "java-class" property definition. 075 private static final ClassPropertyDefinition PD_JAVA_CLASS; 076 077 078 079 // Build the "enabled" property definition. 080 static { 081 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 082 builder.setOption(PropertyOption.MANDATORY); 083 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 084 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 085 PD_ENABLED = builder.getInstance(); 086 INSTANCE.registerPropertyDefinition(PD_ENABLED); 087 } 088 089 090 091 // Build the "java-class" property definition. 092 static { 093 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 094 builder.setOption(PropertyOption.MANDATORY); 095 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 096 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 097 builder.addInstanceOf("org.opends.server.api.PasswordValidator"); 098 PD_JAVA_CLASS = builder.getInstance(); 099 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 100 } 101 102 103 104 // Register the tags associated with this managed object definition. 105 static { 106 INSTANCE.registerTag(Tag.valueOf("user-management")); 107 } 108 109 110 111 /** 112 * Get the Password Validator configuration definition singleton. 113 * 114 * @return Returns the Password Validator configuration definition 115 * singleton. 116 */ 117 public static PasswordValidatorCfgDefn getInstance() { 118 return INSTANCE; 119 } 120 121 122 123 /** 124 * Private constructor. 125 */ 126 private PasswordValidatorCfgDefn() { 127 super("password-validator", TopCfgDefn.getInstance()); 128 } 129 130 131 132 /** 133 * {@inheritDoc} 134 */ 135 public PasswordValidatorCfgClient createClientConfiguration( 136 ManagedObject<? extends PasswordValidatorCfgClient> impl) { 137 return new PasswordValidatorCfgClientImpl(impl); 138 } 139 140 141 142 /** 143 * {@inheritDoc} 144 */ 145 public PasswordValidatorCfg createServerConfiguration( 146 ServerManagedObject<? extends PasswordValidatorCfg> impl) { 147 return new PasswordValidatorCfgServerImpl(impl); 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 public Class<PasswordValidatorCfg> getServerConfigurationClass() { 156 return PasswordValidatorCfg.class; 157 } 158 159 160 161 /** 162 * Get the "enabled" property definition. 163 * <p> 164 * Indicates whether the password validator is enabled for use. 165 * 166 * @return Returns the "enabled" property definition. 167 */ 168 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 169 return PD_ENABLED; 170 } 171 172 173 174 /** 175 * Get the "java-class" property definition. 176 * <p> 177 * Specifies the fully-qualified name of the Java class that 178 * provides the password validator implementation. 179 * 180 * @return Returns the "java-class" property definition. 181 */ 182 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 183 return PD_JAVA_CLASS; 184 } 185 186 187 188 /** 189 * Managed object client implementation. 190 */ 191 private static class PasswordValidatorCfgClientImpl implements 192 PasswordValidatorCfgClient { 193 194 // Private implementation. 195 private ManagedObject<? extends PasswordValidatorCfgClient> impl; 196 197 198 199 // Private constructor. 200 private PasswordValidatorCfgClientImpl( 201 ManagedObject<? extends PasswordValidatorCfgClient> impl) { 202 this.impl = impl; 203 } 204 205 206 207 /** 208 * {@inheritDoc} 209 */ 210 public Boolean isEnabled() { 211 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 212 } 213 214 215 216 /** 217 * {@inheritDoc} 218 */ 219 public void setEnabled(boolean value) { 220 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 221 } 222 223 224 225 /** 226 * {@inheritDoc} 227 */ 228 public String getJavaClass() { 229 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 230 } 231 232 233 234 /** 235 * {@inheritDoc} 236 */ 237 public void setJavaClass(String value) { 238 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 239 } 240 241 242 243 /** 244 * {@inheritDoc} 245 */ 246 public ManagedObjectDefinition<? extends PasswordValidatorCfgClient, ? extends PasswordValidatorCfg> definition() { 247 return INSTANCE; 248 } 249 250 251 252 /** 253 * {@inheritDoc} 254 */ 255 public PropertyProvider properties() { 256 return impl; 257 } 258 259 260 261 /** 262 * {@inheritDoc} 263 */ 264 public void commit() throws ManagedObjectAlreadyExistsException, 265 MissingMandatoryPropertiesException, ConcurrentModificationException, 266 OperationRejectedException, LdapException { 267 impl.commit(); 268 } 269 270 } 271 272 273 274 /** 275 * Managed object server implementation. 276 */ 277 private static class PasswordValidatorCfgServerImpl implements 278 PasswordValidatorCfg { 279 280 // Private implementation. 281 private ServerManagedObject<? extends PasswordValidatorCfg> impl; 282 283 // The value of the "enabled" property. 284 private final boolean pEnabled; 285 286 // The value of the "java-class" property. 287 private final String pJavaClass; 288 289 290 291 // Private constructor. 292 private PasswordValidatorCfgServerImpl(ServerManagedObject<? extends PasswordValidatorCfg> impl) { 293 this.impl = impl; 294 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 295 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 296 } 297 298 299 300 /** 301 * {@inheritDoc} 302 */ 303 public void addChangeListener( 304 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 305 impl.registerChangeListener(listener); 306 } 307 308 309 310 /** 311 * {@inheritDoc} 312 */ 313 public void removeChangeListener( 314 ConfigurationChangeListener<PasswordValidatorCfg> listener) { 315 impl.deregisterChangeListener(listener); 316 } 317 318 319 320 /** 321 * {@inheritDoc} 322 */ 323 public boolean isEnabled() { 324 return pEnabled; 325 } 326 327 328 329 /** 330 * {@inheritDoc} 331 */ 332 public String getJavaClass() { 333 return pJavaClass; 334 } 335 336 337 338 /** 339 * {@inheritDoc} 340 */ 341 public Class<? extends PasswordValidatorCfg> configurationClass() { 342 return PasswordValidatorCfg.class; 343 } 344 345 346 347 /** 348 * {@inheritDoc} 349 */ 350 public DN dn() { 351 return impl.getDN(); 352 } 353 354 } 355}