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