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