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.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.DefaultBehaviorProvider;
038import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
039import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
040import org.forgerock.opendj.config.ManagedObjectDefinition;
041import org.forgerock.opendj.config.PropertyOption;
042import org.forgerock.opendj.config.PropertyProvider;
043import org.forgerock.opendj.config.server.ConfigurationChangeListener;
044import org.forgerock.opendj.config.server.ServerManagedObject;
045import org.forgerock.opendj.config.Tag;
046import org.forgerock.opendj.ldap.DN;
047import org.forgerock.opendj.ldap.LdapException;
048import org.forgerock.opendj.server.config.client.AnonymousSASLMechanismHandlerCfgClient;
049import org.forgerock.opendj.server.config.server.AnonymousSASLMechanismHandlerCfg;
050import org.forgerock.opendj.server.config.server.SASLMechanismHandlerCfg;
051
052
053
054/**
055 * An interface for querying the Anonymous SASL Mechanism Handler
056 * managed object definition meta information.
057 * <p>
058 * The ANONYMOUS SASL mechanism provides the ability for clients to
059 * perform an anonymous bind using a SASL mechanism.
060 */
061public final class AnonymousSASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<AnonymousSASLMechanismHandlerCfgClient, AnonymousSASLMechanismHandlerCfg> {
062
063  // The singleton configuration definition instance.
064  private static final AnonymousSASLMechanismHandlerCfgDefn INSTANCE = new AnonymousSASLMechanismHandlerCfgDefn();
065
066
067
068  // The "java-class" property definition.
069  private static final ClassPropertyDefinition PD_JAVA_CLASS;
070
071
072
073  // Build the "java-class" property definition.
074  static {
075      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
076      builder.setOption(PropertyOption.MANDATORY);
077      builder.setOption(PropertyOption.ADVANCED);
078      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
079      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.AnonymousSASLMechanismHandler");
080      builder.setDefaultBehaviorProvider(provider);
081      builder.addInstanceOf("org.opends.server.api.SASLMechanismHandler");
082      PD_JAVA_CLASS = builder.getInstance();
083      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
084  }
085
086
087
088  // Register the tags associated with this managed object definition.
089  static {
090    INSTANCE.registerTag(Tag.valueOf("security"));
091  }
092
093
094
095  /**
096   * Get the Anonymous SASL Mechanism Handler configuration definition
097   * singleton.
098   *
099   * @return Returns the Anonymous SASL Mechanism Handler
100   *         configuration definition singleton.
101   */
102  public static AnonymousSASLMechanismHandlerCfgDefn getInstance() {
103    return INSTANCE;
104  }
105
106
107
108  /**
109   * Private constructor.
110   */
111  private AnonymousSASLMechanismHandlerCfgDefn() {
112    super("anonymous-sasl-mechanism-handler", SASLMechanismHandlerCfgDefn.getInstance());
113  }
114
115
116
117  /**
118   * {@inheritDoc}
119   */
120  public AnonymousSASLMechanismHandlerCfgClient createClientConfiguration(
121      ManagedObject<? extends AnonymousSASLMechanismHandlerCfgClient> impl) {
122    return new AnonymousSASLMechanismHandlerCfgClientImpl(impl);
123  }
124
125
126
127  /**
128   * {@inheritDoc}
129   */
130  public AnonymousSASLMechanismHandlerCfg createServerConfiguration(
131      ServerManagedObject<? extends AnonymousSASLMechanismHandlerCfg> impl) {
132    return new AnonymousSASLMechanismHandlerCfgServerImpl(impl);
133  }
134
135
136
137  /**
138   * {@inheritDoc}
139   */
140  public Class<AnonymousSASLMechanismHandlerCfg> getServerConfigurationClass() {
141    return AnonymousSASLMechanismHandlerCfg.class;
142  }
143
144
145
146  /**
147   * Get the "enabled" property definition.
148   * <p>
149   * Indicates whether the SASL mechanism handler is enabled for use.
150   *
151   * @return Returns the "enabled" property definition.
152   */
153  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
154    return SASLMechanismHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
155  }
156
157
158
159  /**
160   * Get the "java-class" property definition.
161   * <p>
162   * Specifies the fully-qualified name of the Java class that
163   * provides the SASL mechanism handler implementation.
164   *
165   * @return Returns the "java-class" property definition.
166   */
167  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
168    return PD_JAVA_CLASS;
169  }
170
171
172
173  /**
174   * Managed object client implementation.
175   */
176  private static class AnonymousSASLMechanismHandlerCfgClientImpl implements
177    AnonymousSASLMechanismHandlerCfgClient {
178
179    // Private implementation.
180    private ManagedObject<? extends AnonymousSASLMechanismHandlerCfgClient> impl;
181
182
183
184    // Private constructor.
185    private AnonymousSASLMechanismHandlerCfgClientImpl(
186        ManagedObject<? extends AnonymousSASLMechanismHandlerCfgClient> impl) {
187      this.impl = impl;
188    }
189
190
191
192    /**
193     * {@inheritDoc}
194     */
195    public Boolean isEnabled() {
196      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
197    }
198
199
200
201    /**
202     * {@inheritDoc}
203     */
204    public void setEnabled(boolean value) {
205      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
206    }
207
208
209
210    /**
211     * {@inheritDoc}
212     */
213    public String getJavaClass() {
214      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
215    }
216
217
218
219    /**
220     * {@inheritDoc}
221     */
222    public void setJavaClass(String value) {
223      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
224    }
225
226
227
228    /**
229     * {@inheritDoc}
230     */
231    public ManagedObjectDefinition<? extends AnonymousSASLMechanismHandlerCfgClient, ? extends AnonymousSASLMechanismHandlerCfg> definition() {
232      return INSTANCE;
233    }
234
235
236
237    /**
238     * {@inheritDoc}
239     */
240    public PropertyProvider properties() {
241      return impl;
242    }
243
244
245
246    /**
247     * {@inheritDoc}
248     */
249    public void commit() throws ManagedObjectAlreadyExistsException,
250        MissingMandatoryPropertiesException, ConcurrentModificationException,
251        OperationRejectedException, LdapException {
252      impl.commit();
253    }
254
255  }
256
257
258
259  /**
260   * Managed object server implementation.
261   */
262  private static class AnonymousSASLMechanismHandlerCfgServerImpl implements
263    AnonymousSASLMechanismHandlerCfg {
264
265    // Private implementation.
266    private ServerManagedObject<? extends AnonymousSASLMechanismHandlerCfg> impl;
267
268    // The value of the "enabled" property.
269    private final boolean pEnabled;
270
271    // The value of the "java-class" property.
272    private final String pJavaClass;
273
274
275
276    // Private constructor.
277    private AnonymousSASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends AnonymousSASLMechanismHandlerCfg> impl) {
278      this.impl = impl;
279      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
280      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
281    }
282
283
284
285    /**
286     * {@inheritDoc}
287     */
288    public void addAnonymousChangeListener(
289        ConfigurationChangeListener<AnonymousSASLMechanismHandlerCfg> listener) {
290      impl.registerChangeListener(listener);
291    }
292
293
294
295    /**
296     * {@inheritDoc}
297     */
298    public void removeAnonymousChangeListener(
299        ConfigurationChangeListener<AnonymousSASLMechanismHandlerCfg> listener) {
300      impl.deregisterChangeListener(listener);
301    }
302    /**
303     * {@inheritDoc}
304     */
305    public void addChangeListener(
306        ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
307      impl.registerChangeListener(listener);
308    }
309
310
311
312    /**
313     * {@inheritDoc}
314     */
315    public void removeChangeListener(
316        ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
317      impl.deregisterChangeListener(listener);
318    }
319
320
321
322    /**
323     * {@inheritDoc}
324     */
325    public boolean isEnabled() {
326      return pEnabled;
327    }
328
329
330
331    /**
332     * {@inheritDoc}
333     */
334    public String getJavaClass() {
335      return pJavaClass;
336    }
337
338
339
340    /**
341     * {@inheritDoc}
342     */
343    public Class<? extends AnonymousSASLMechanismHandlerCfg> configurationClass() {
344      return AnonymousSASLMechanismHandlerCfg.class;
345    }
346
347
348
349    /**
350     * {@inheritDoc}
351     */
352    public DN dn() {
353      return impl.getDN();
354    }
355
356  }
357}