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.AggregationPropertyDefinition; 022import org.forgerock.opendj.config.BooleanPropertyDefinition; 023import org.forgerock.opendj.config.ClassPropertyDefinition; 024import org.forgerock.opendj.config.client.ConcurrentModificationException; 025import org.forgerock.opendj.config.client.ManagedObject; 026import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 027import org.forgerock.opendj.config.client.OperationRejectedException; 028import org.forgerock.opendj.config.conditions.Conditions; 029import org.forgerock.opendj.config.DefaultBehaviorProvider; 030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 031import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 032import org.forgerock.opendj.config.ManagedObjectDefinition; 033import org.forgerock.opendj.config.PropertyOption; 034import org.forgerock.opendj.config.PropertyProvider; 035import org.forgerock.opendj.config.server.ConfigurationChangeListener; 036import org.forgerock.opendj.config.server.ServerManagedObject; 037import org.forgerock.opendj.config.Tag; 038import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 039import org.forgerock.opendj.ldap.DN; 040import org.forgerock.opendj.ldap.LdapException; 041import org.forgerock.opendj.server.config.client.IdentityMapperCfgClient; 042import org.forgerock.opendj.server.config.client.PasswordModifyExtendedOperationHandlerCfgClient; 043import org.forgerock.opendj.server.config.server.ExtendedOperationHandlerCfg; 044import org.forgerock.opendj.server.config.server.IdentityMapperCfg; 045import org.forgerock.opendj.server.config.server.PasswordModifyExtendedOperationHandlerCfg; 046 047 048 049/** 050 * An interface for querying the Password Modify Extended Operation 051 * Handler managed object definition meta information. 052 * <p> 053 * The Password Modify Extended Operation Handler allows end users to 054 * change their own passwords, or administrators to reset user 055 * passwords. 056 */ 057public final class PasswordModifyExtendedOperationHandlerCfgDefn extends ManagedObjectDefinition<PasswordModifyExtendedOperationHandlerCfgClient, PasswordModifyExtendedOperationHandlerCfg> { 058 059 /** The singleton configuration definition instance. */ 060 private static final PasswordModifyExtendedOperationHandlerCfgDefn INSTANCE = new PasswordModifyExtendedOperationHandlerCfgDefn(); 061 062 063 064 /** The "identity-mapper" property definition. */ 065 private static final AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> PD_IDENTITY_MAPPER; 066 067 068 069 /** The "java-class" property definition. */ 070 private static final ClassPropertyDefinition PD_JAVA_CLASS; 071 072 073 074 /** Build the "identity-mapper" property definition. */ 075 static { 076 AggregationPropertyDefinition.Builder<IdentityMapperCfgClient, IdentityMapperCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "identity-mapper"); 077 builder.setOption(PropertyOption.MANDATORY); 078 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "identity-mapper")); 079 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 080 builder.setParentPath("/"); 081 builder.setRelationDefinition("identity-mapper"); 082 builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true")); 083 builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true")); 084 PD_IDENTITY_MAPPER = builder.getInstance(); 085 INSTANCE.registerPropertyDefinition(PD_IDENTITY_MAPPER); 086 INSTANCE.registerConstraint(PD_IDENTITY_MAPPER.getSourceConstraint()); 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.setOption(PropertyOption.ADVANCED); 096 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 097 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.PasswordModifyExtendedOperation"); 098 builder.setDefaultBehaviorProvider(provider); 099 builder.addInstanceOf("org.opends.server.api.ExtendedOperationHandler"); 100 PD_JAVA_CLASS = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 102 } 103 104 105 106 // Register the tags associated with this managed object definition. 107 static { 108 INSTANCE.registerTag(Tag.valueOf("core-server")); 109 } 110 111 112 113 /** 114 * Get the Password Modify Extended Operation Handler configuration 115 * definition singleton. 116 * 117 * @return Returns the Password Modify Extended Operation Handler 118 * configuration definition singleton. 119 */ 120 public static PasswordModifyExtendedOperationHandlerCfgDefn getInstance() { 121 return INSTANCE; 122 } 123 124 125 126 /** 127 * Private constructor. 128 */ 129 private PasswordModifyExtendedOperationHandlerCfgDefn() { 130 super("password-modify-extended-operation-handler", ExtendedOperationHandlerCfgDefn.getInstance()); 131 } 132 133 134 135 /** {@inheritDoc} */ 136 public PasswordModifyExtendedOperationHandlerCfgClient createClientConfiguration( 137 ManagedObject<? extends PasswordModifyExtendedOperationHandlerCfgClient> impl) { 138 return new PasswordModifyExtendedOperationHandlerCfgClientImpl(impl); 139 } 140 141 142 143 /** {@inheritDoc} */ 144 public PasswordModifyExtendedOperationHandlerCfg createServerConfiguration( 145 ServerManagedObject<? extends PasswordModifyExtendedOperationHandlerCfg> impl) { 146 return new PasswordModifyExtendedOperationHandlerCfgServerImpl(impl); 147 } 148 149 150 151 /** {@inheritDoc} */ 152 public Class<PasswordModifyExtendedOperationHandlerCfg> getServerConfigurationClass() { 153 return PasswordModifyExtendedOperationHandlerCfg.class; 154 } 155 156 157 158 /** 159 * Get the "enabled" property definition. 160 * <p> 161 * Indicates whether the Password Modify Extended Operation Handler 162 * is enabled (that is, whether the types of extended operations are 163 * allowed in the server). 164 * 165 * @return Returns the "enabled" property definition. 166 */ 167 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 168 return ExtendedOperationHandlerCfgDefn.getInstance().getEnabledPropertyDefinition(); 169 } 170 171 172 173 /** 174 * Get the "identity-mapper" property definition. 175 * <p> 176 * Specifies the name of the identity mapper that should be used in 177 * conjunction with the password modify extended operation. 178 * <p> 179 * This property is used to identify a user based on an 180 * authorization ID in the 'u:' form. Changes to this property take 181 * effect immediately. 182 * 183 * @return Returns the "identity-mapper" property definition. 184 */ 185 public AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> getIdentityMapperPropertyDefinition() { 186 return PD_IDENTITY_MAPPER; 187 } 188 189 190 191 /** 192 * Get the "java-class" property definition. 193 * <p> 194 * Specifies the fully-qualified name of the Java class that 195 * provides the Password Modify Extended Operation Handler 196 * implementation. 197 * 198 * @return Returns the "java-class" property definition. 199 */ 200 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 201 return PD_JAVA_CLASS; 202 } 203 204 205 206 /** 207 * Managed object client implementation. 208 */ 209 private static class PasswordModifyExtendedOperationHandlerCfgClientImpl implements 210 PasswordModifyExtendedOperationHandlerCfgClient { 211 212 /** Private implementation. */ 213 private ManagedObject<? extends PasswordModifyExtendedOperationHandlerCfgClient> impl; 214 215 216 217 /** Private constructor. */ 218 private PasswordModifyExtendedOperationHandlerCfgClientImpl( 219 ManagedObject<? extends PasswordModifyExtendedOperationHandlerCfgClient> impl) { 220 this.impl = impl; 221 } 222 223 224 225 /** {@inheritDoc} */ 226 public Boolean isEnabled() { 227 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 228 } 229 230 231 232 /** {@inheritDoc} */ 233 public void setEnabled(boolean value) { 234 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 235 } 236 237 238 239 /** {@inheritDoc} */ 240 public String getIdentityMapper() { 241 return impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition()); 242 } 243 244 245 246 /** {@inheritDoc} */ 247 public void setIdentityMapper(String value) { 248 impl.setPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition(), value); 249 } 250 251 252 253 /** {@inheritDoc} */ 254 public String getJavaClass() { 255 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 256 } 257 258 259 260 /** {@inheritDoc} */ 261 public void setJavaClass(String value) { 262 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 263 } 264 265 266 267 /** {@inheritDoc} */ 268 public ManagedObjectDefinition<? extends PasswordModifyExtendedOperationHandlerCfgClient, ? extends PasswordModifyExtendedOperationHandlerCfg> definition() { 269 return INSTANCE; 270 } 271 272 273 274 /** {@inheritDoc} */ 275 public PropertyProvider properties() { 276 return impl; 277 } 278 279 280 281 /** {@inheritDoc} */ 282 public void commit() throws ManagedObjectAlreadyExistsException, 283 MissingMandatoryPropertiesException, ConcurrentModificationException, 284 OperationRejectedException, LdapException { 285 impl.commit(); 286 } 287 288 289 290 /** {@inheritDoc} */ 291 public String toString() { 292 return impl.toString(); 293 } 294 } 295 296 297 298 /** 299 * Managed object server implementation. 300 */ 301 private static class PasswordModifyExtendedOperationHandlerCfgServerImpl implements 302 PasswordModifyExtendedOperationHandlerCfg { 303 304 /** Private implementation. */ 305 private ServerManagedObject<? extends PasswordModifyExtendedOperationHandlerCfg> impl; 306 307 /** The value of the "enabled" property. */ 308 private final boolean pEnabled; 309 310 /** The value of the "identity-mapper" property. */ 311 private final String pIdentityMapper; 312 313 /** The value of the "java-class" property. */ 314 private final String pJavaClass; 315 316 317 318 /** Private constructor. */ 319 private PasswordModifyExtendedOperationHandlerCfgServerImpl(ServerManagedObject<? extends PasswordModifyExtendedOperationHandlerCfg> impl) { 320 this.impl = impl; 321 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 322 this.pIdentityMapper = impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition()); 323 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 324 } 325 326 327 328 /** {@inheritDoc} */ 329 public void addPasswordModifyChangeListener( 330 ConfigurationChangeListener<PasswordModifyExtendedOperationHandlerCfg> listener) { 331 impl.registerChangeListener(listener); 332 } 333 334 335 336 /** {@inheritDoc} */ 337 public void removePasswordModifyChangeListener( 338 ConfigurationChangeListener<PasswordModifyExtendedOperationHandlerCfg> listener) { 339 impl.deregisterChangeListener(listener); 340 } 341 /** {@inheritDoc} */ 342 public void addChangeListener( 343 ConfigurationChangeListener<ExtendedOperationHandlerCfg> listener) { 344 impl.registerChangeListener(listener); 345 } 346 347 348 349 /** {@inheritDoc} */ 350 public void removeChangeListener( 351 ConfigurationChangeListener<ExtendedOperationHandlerCfg> listener) { 352 impl.deregisterChangeListener(listener); 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public boolean isEnabled() { 359 return pEnabled; 360 } 361 362 363 364 /** {@inheritDoc} */ 365 public String getIdentityMapper() { 366 return pIdentityMapper; 367 } 368 369 370 371 /** 372 * {@inheritDoc} 373 */ 374 public DN getIdentityMapperDN() { 375 String value = getIdentityMapper(); 376 if (value == null) return null; 377 return INSTANCE.getIdentityMapperPropertyDefinition().getChildDN(value); 378 } 379 380 381 382 /** {@inheritDoc} */ 383 public String getJavaClass() { 384 return pJavaClass; 385 } 386 387 388 389 /** {@inheritDoc} */ 390 public Class<? extends PasswordModifyExtendedOperationHandlerCfg> configurationClass() { 391 return PasswordModifyExtendedOperationHandlerCfg.class; 392 } 393 394 395 396 /** {@inheritDoc} */ 397 public DN dn() { 398 return impl.getDN(); 399 } 400 401 402 403 /** {@inheritDoc} */ 404 public String toString() { 405 return impl.toString(); 406 } 407 } 408}