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.ManagedObjectAlreadyExistsException; 040import org.opends.server.admin.ManagedObjectDefinition; 041import org.opends.server.admin.PropertyOption; 042import org.opends.server.admin.PropertyProvider; 043import org.opends.server.admin.server.ConfigurationChangeListener; 044import org.opends.server.admin.server.ServerManagedObject; 045import org.opends.server.admin.std.client.PasswordGeneratorCfgClient; 046import org.opends.server.admin.std.server.PasswordGeneratorCfg; 047import org.opends.server.admin.Tag; 048import org.opends.server.admin.TopCfgDefn; 049import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 050import org.opends.server.types.DN; 051 052 053 054/** 055 * An interface for querying the Password Generator managed object 056 * definition meta information. 057 * <p> 058 * Password Generators are used by the password modify extended 059 * operation to construct a new password for the user. 060 */ 061public final class PasswordGeneratorCfgDefn extends ManagedObjectDefinition<PasswordGeneratorCfgClient, PasswordGeneratorCfg> { 062 063 // The singleton configuration definition instance. 064 private static final PasswordGeneratorCfgDefn INSTANCE = new PasswordGeneratorCfgDefn(); 065 066 067 068 // The "enabled" property definition. 069 private static final BooleanPropertyDefinition PD_ENABLED; 070 071 072 073 // The "java-class" property definition. 074 private static final ClassPropertyDefinition PD_JAVA_CLASS; 075 076 077 078 // Build the "enabled" property definition. 079 static { 080 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 081 builder.setOption(PropertyOption.MANDATORY); 082 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 083 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 084 PD_ENABLED = builder.getInstance(); 085 INSTANCE.registerPropertyDefinition(PD_ENABLED); 086 } 087 088 089 090 // Build the "java-class" property definition. 091 static { 092 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 093 builder.setOption(PropertyOption.MANDATORY); 094 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 095 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 096 builder.addInstanceOf("org.opends.server.api.PasswordGenerator"); 097 PD_JAVA_CLASS = builder.getInstance(); 098 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 099 } 100 101 102 103 // Register the tags associated with this managed object definition. 104 static { 105 INSTANCE.registerTag(Tag.valueOf("user-management")); 106 } 107 108 109 110 /** 111 * Get the Password Generator configuration definition singleton. 112 * 113 * @return Returns the Password Generator configuration definition 114 * singleton. 115 */ 116 public static PasswordGeneratorCfgDefn getInstance() { 117 return INSTANCE; 118 } 119 120 121 122 /** 123 * Private constructor. 124 */ 125 private PasswordGeneratorCfgDefn() { 126 super("password-generator", TopCfgDefn.getInstance()); 127 } 128 129 130 131 /** 132 * {@inheritDoc} 133 */ 134 public PasswordGeneratorCfgClient createClientConfiguration( 135 ManagedObject<? extends PasswordGeneratorCfgClient> impl) { 136 return new PasswordGeneratorCfgClientImpl(impl); 137 } 138 139 140 141 /** 142 * {@inheritDoc} 143 */ 144 public PasswordGeneratorCfg createServerConfiguration( 145 ServerManagedObject<? extends PasswordGeneratorCfg> impl) { 146 return new PasswordGeneratorCfgServerImpl(impl); 147 } 148 149 150 151 /** 152 * {@inheritDoc} 153 */ 154 public Class<PasswordGeneratorCfg> getServerConfigurationClass() { 155 return PasswordGeneratorCfg.class; 156 } 157 158 159 160 /** 161 * Get the "enabled" property definition. 162 * <p> 163 * Indicates whether the Password Generator is enabled for use. 164 * 165 * @return Returns the "enabled" property definition. 166 */ 167 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 168 return PD_ENABLED; 169 } 170 171 172 173 /** 174 * Get the "java-class" property definition. 175 * <p> 176 * Specifies the fully-qualified name of the Java class that 177 * provides the Password Generator implementation. 178 * 179 * @return Returns the "java-class" property definition. 180 */ 181 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 182 return PD_JAVA_CLASS; 183 } 184 185 186 187 /** 188 * Managed object client implementation. 189 */ 190 private static class PasswordGeneratorCfgClientImpl implements 191 PasswordGeneratorCfgClient { 192 193 // Private implementation. 194 private ManagedObject<? extends PasswordGeneratorCfgClient> impl; 195 196 197 198 // Private constructor. 199 private PasswordGeneratorCfgClientImpl( 200 ManagedObject<? extends PasswordGeneratorCfgClient> impl) { 201 this.impl = impl; 202 } 203 204 205 206 /** 207 * {@inheritDoc} 208 */ 209 public Boolean isEnabled() { 210 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 211 } 212 213 214 215 /** 216 * {@inheritDoc} 217 */ 218 public void setEnabled(boolean value) { 219 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 220 } 221 222 223 224 /** 225 * {@inheritDoc} 226 */ 227 public String getJavaClass() { 228 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 229 } 230 231 232 233 /** 234 * {@inheritDoc} 235 */ 236 public void setJavaClass(String value) { 237 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 238 } 239 240 241 242 /** 243 * {@inheritDoc} 244 */ 245 public ManagedObjectDefinition<? extends PasswordGeneratorCfgClient, ? extends PasswordGeneratorCfg> definition() { 246 return INSTANCE; 247 } 248 249 250 251 /** 252 * {@inheritDoc} 253 */ 254 public PropertyProvider properties() { 255 return impl; 256 } 257 258 259 260 /** 261 * {@inheritDoc} 262 */ 263 public void commit() throws ManagedObjectAlreadyExistsException, 264 MissingMandatoryPropertiesException, ConcurrentModificationException, 265 OperationRejectedException, AuthorizationException, 266 CommunicationException { 267 impl.commit(); 268 } 269 270 } 271 272 273 274 /** 275 * Managed object server implementation. 276 */ 277 private static class PasswordGeneratorCfgServerImpl implements 278 PasswordGeneratorCfg { 279 280 // Private implementation. 281 private ServerManagedObject<? extends PasswordGeneratorCfg> 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 PasswordGeneratorCfgServerImpl(ServerManagedObject<? extends PasswordGeneratorCfg> 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<PasswordGeneratorCfg> listener) { 305 impl.registerChangeListener(listener); 306 } 307 308 309 310 /** 311 * {@inheritDoc} 312 */ 313 public void removeChangeListener( 314 ConfigurationChangeListener<PasswordGeneratorCfg> 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 PasswordGeneratorCfg> configurationClass() { 342 return PasswordGeneratorCfg.class; 343 } 344 345 346 347 /** 348 * {@inheritDoc} 349 */ 350 public DN dn() { 351 return impl.getDN(); 352 } 353 354 } 355}