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