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  /**
146   * {@inheritDoc}
147   */
148  public PasswordModifyExtendedOperationHandlerCfgClient createClientConfiguration(
149      ManagedObject<? extends PasswordModifyExtendedOperationHandlerCfgClient> impl) {
150    return new PasswordModifyExtendedOperationHandlerCfgClientImpl(impl);
151  }
152
153
154
155  /**
156   * {@inheritDoc}
157   */
158  public PasswordModifyExtendedOperationHandlerCfg createServerConfiguration(
159      ServerManagedObject<? extends PasswordModifyExtendedOperationHandlerCfg> impl) {
160    return new PasswordModifyExtendedOperationHandlerCfgServerImpl(impl);
161  }
162
163
164
165  /**
166   * {@inheritDoc}
167   */
168  public Class<PasswordModifyExtendedOperationHandlerCfg> getServerConfigurationClass() {
169    return PasswordModifyExtendedOperationHandlerCfg.class;
170  }
171
172
173
174  /**
175   * Get the "enabled" property definition.
176   * <p>
177   * Indicates whether the Password Modify Extended Operation Handler
178   * is enabled (that is, whether the types of extended operations are
179   * allowed in the server).
180   *
181   * @return Returns the "enabled" property definition.
182   */
183  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
184    return ExtendedOperationHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
185  }
186
187
188
189  /**
190   * Get the "identity-mapper" property definition.
191   * <p>
192   * Specifies the name of the identity mapper that should be used in
193   * conjunction with the password modify extended operation.
194   * <p>
195   * This property is used to identify a user based on an
196   * authorization ID in the 'u:' form. Changes to this property take
197   * effect immediately.
198   *
199   * @return Returns the "identity-mapper" property definition.
200   */
201  public AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> getIdentityMapperPropertyDefinition() {
202    return PD_IDENTITY_MAPPER;
203  }
204
205
206
207  /**
208   * Get the "java-class" property definition.
209   * <p>
210   * Specifies the fully-qualified name of the Java class that
211   * provides the Password Modify Extended Operation Handler
212   * implementation.
213   *
214   * @return Returns the "java-class" property definition.
215   */
216  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
217    return PD_JAVA_CLASS;
218  }
219
220
221
222  /**
223   * Managed object client implementation.
224   */
225  private static class PasswordModifyExtendedOperationHandlerCfgClientImpl implements
226    PasswordModifyExtendedOperationHandlerCfgClient {
227
228    // Private implementation.
229    private ManagedObject<? extends PasswordModifyExtendedOperationHandlerCfgClient> impl;
230
231
232
233    // Private constructor.
234    private PasswordModifyExtendedOperationHandlerCfgClientImpl(
235        ManagedObject<? extends PasswordModifyExtendedOperationHandlerCfgClient> impl) {
236      this.impl = impl;
237    }
238
239
240
241    /**
242     * {@inheritDoc}
243     */
244    public Boolean isEnabled() {
245      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
246    }
247
248
249
250    /**
251     * {@inheritDoc}
252     */
253    public void setEnabled(boolean value) {
254      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
255    }
256
257
258
259    /**
260     * {@inheritDoc}
261     */
262    public String getIdentityMapper() {
263      return impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition());
264    }
265
266
267
268    /**
269     * {@inheritDoc}
270     */
271    public void setIdentityMapper(String value) {
272      impl.setPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition(), value);
273    }
274
275
276
277    /**
278     * {@inheritDoc}
279     */
280    public String getJavaClass() {
281      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
282    }
283
284
285
286    /**
287     * {@inheritDoc}
288     */
289    public void setJavaClass(String value) {
290      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
291    }
292
293
294
295    /**
296     * {@inheritDoc}
297     */
298    public ManagedObjectDefinition<? extends PasswordModifyExtendedOperationHandlerCfgClient, ? extends PasswordModifyExtendedOperationHandlerCfg> definition() {
299      return INSTANCE;
300    }
301
302
303
304    /**
305     * {@inheritDoc}
306     */
307    public PropertyProvider properties() {
308      return impl;
309    }
310
311
312
313    /**
314     * {@inheritDoc}
315     */
316    public void commit() throws ManagedObjectAlreadyExistsException,
317        MissingMandatoryPropertiesException, ConcurrentModificationException,
318        OperationRejectedException, LdapException {
319      impl.commit();
320    }
321
322  }
323
324
325
326  /**
327   * Managed object server implementation.
328   */
329  private static class PasswordModifyExtendedOperationHandlerCfgServerImpl implements
330    PasswordModifyExtendedOperationHandlerCfg {
331
332    // Private implementation.
333    private ServerManagedObject<? extends PasswordModifyExtendedOperationHandlerCfg> impl;
334
335    // The value of the "enabled" property.
336    private final boolean pEnabled;
337
338    // The value of the "identity-mapper" property.
339    private final String pIdentityMapper;
340
341    // The value of the "java-class" property.
342    private final String pJavaClass;
343
344
345
346    // Private constructor.
347    private PasswordModifyExtendedOperationHandlerCfgServerImpl(ServerManagedObject<? extends PasswordModifyExtendedOperationHandlerCfg> impl) {
348      this.impl = impl;
349      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
350      this.pIdentityMapper = impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition());
351      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
352    }
353
354
355
356    /**
357     * {@inheritDoc}
358     */
359    public void addPasswordModifyChangeListener(
360        ConfigurationChangeListener<PasswordModifyExtendedOperationHandlerCfg> listener) {
361      impl.registerChangeListener(listener);
362    }
363
364
365
366    /**
367     * {@inheritDoc}
368     */
369    public void removePasswordModifyChangeListener(
370        ConfigurationChangeListener<PasswordModifyExtendedOperationHandlerCfg> listener) {
371      impl.deregisterChangeListener(listener);
372    }
373    /**
374     * {@inheritDoc}
375     */
376    public void addChangeListener(
377        ConfigurationChangeListener<ExtendedOperationHandlerCfg> listener) {
378      impl.registerChangeListener(listener);
379    }
380
381
382
383    /**
384     * {@inheritDoc}
385     */
386    public void removeChangeListener(
387        ConfigurationChangeListener<ExtendedOperationHandlerCfg> listener) {
388      impl.deregisterChangeListener(listener);
389    }
390
391
392
393    /**
394     * {@inheritDoc}
395     */
396    public boolean isEnabled() {
397      return pEnabled;
398    }
399
400
401
402    /**
403     * {@inheritDoc}
404     */
405    public String getIdentityMapper() {
406      return pIdentityMapper;
407    }
408
409
410
411    /**
412     * {@inheritDoc}
413     */
414    public DN getIdentityMapperDN() {
415      String value = getIdentityMapper();
416      if (value == null) return null;
417      return INSTANCE.getIdentityMapperPropertyDefinition().getChildDN(value);
418    }
419
420
421
422    /**
423     * {@inheritDoc}
424     */
425    public String getJavaClass() {
426      return pJavaClass;
427    }
428
429
430
431    /**
432     * {@inheritDoc}
433     */
434    public Class<? extends PasswordModifyExtendedOperationHandlerCfg> configurationClass() {
435      return PasswordModifyExtendedOperationHandlerCfg.class;
436    }
437
438
439
440    /**
441     * {@inheritDoc}
442     */
443    public DN dn() {
444      return impl.getDN();
445    }
446
447  }
448}