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