001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 */
016package org.forgerock.opendj.server.config.meta;
017
018
019
020import org.forgerock.opendj.config.AdministratorAction;
021import org.forgerock.opendj.config.BooleanPropertyDefinition;
022import org.forgerock.opendj.config.ClassPropertyDefinition;
023import org.forgerock.opendj.config.client.ConcurrentModificationException;
024import org.forgerock.opendj.config.client.ManagedObject;
025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
026import org.forgerock.opendj.config.client.OperationRejectedException;
027import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
028import org.forgerock.opendj.config.ManagedObjectDefinition;
029import org.forgerock.opendj.config.PropertyOption;
030import org.forgerock.opendj.config.PropertyProvider;
031import org.forgerock.opendj.config.server.ConfigurationChangeListener;
032import org.forgerock.opendj.config.server.ServerManagedObject;
033import org.forgerock.opendj.config.Tag;
034import org.forgerock.opendj.config.TopCfgDefn;
035import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
036import org.forgerock.opendj.ldap.DN;
037import org.forgerock.opendj.ldap.LdapException;
038import org.forgerock.opendj.server.config.client.SASLMechanismHandlerCfgClient;
039import org.forgerock.opendj.server.config.server.SASLMechanismHandlerCfg;
040
041
042
043/**
044 * An interface for querying the SASL Mechanism Handler managed object
045 * definition meta information.
046 * <p>
047 * The SASL mechanism handler configuration entry is the parent for
048 * all SASL mechanism handlers defined in the OpenDJ directory server.
049 */
050public final class SASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<SASLMechanismHandlerCfgClient, SASLMechanismHandlerCfg> {
051
052  /** The singleton configuration definition instance. */
053  private static final SASLMechanismHandlerCfgDefn INSTANCE = new SASLMechanismHandlerCfgDefn();
054
055
056
057  /** The "enabled" property definition. */
058  private static final BooleanPropertyDefinition PD_ENABLED;
059
060
061
062  /** The "java-class" property definition. */
063  private static final ClassPropertyDefinition PD_JAVA_CLASS;
064
065
066
067  /** Build the "enabled" property definition. */
068  static {
069      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
070      builder.setOption(PropertyOption.MANDATORY);
071      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
072      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
073      PD_ENABLED = builder.getInstance();
074      INSTANCE.registerPropertyDefinition(PD_ENABLED);
075  }
076
077
078
079  /** Build the "java-class" property definition. */
080  static {
081      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
082      builder.setOption(PropertyOption.MANDATORY);
083      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
084      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
085      builder.addInstanceOf("org.opends.server.api.SASLMechanismHandler");
086      PD_JAVA_CLASS = builder.getInstance();
087      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
088  }
089
090
091
092  // Register the tags associated with this managed object definition.
093  static {
094    INSTANCE.registerTag(Tag.valueOf("security"));
095  }
096
097
098
099  /**
100   * Get the SASL Mechanism Handler configuration definition
101   * singleton.
102   *
103   * @return Returns the SASL Mechanism Handler configuration
104   *         definition singleton.
105   */
106  public static SASLMechanismHandlerCfgDefn getInstance() {
107    return INSTANCE;
108  }
109
110
111
112  /**
113   * Private constructor.
114   */
115  private SASLMechanismHandlerCfgDefn() {
116    super("sasl-mechanism-handler", TopCfgDefn.getInstance());
117  }
118
119
120
121  /** {@inheritDoc} */
122  public SASLMechanismHandlerCfgClient createClientConfiguration(
123      ManagedObject<? extends SASLMechanismHandlerCfgClient> impl) {
124    return new SASLMechanismHandlerCfgClientImpl(impl);
125  }
126
127
128
129  /** {@inheritDoc} */
130  public SASLMechanismHandlerCfg createServerConfiguration(
131      ServerManagedObject<? extends SASLMechanismHandlerCfg> impl) {
132    return new SASLMechanismHandlerCfgServerImpl(impl);
133  }
134
135
136
137  /** {@inheritDoc} */
138  public Class<SASLMechanismHandlerCfg> getServerConfigurationClass() {
139    return SASLMechanismHandlerCfg.class;
140  }
141
142
143
144  /**
145   * Get the "enabled" property definition.
146   * <p>
147   * Indicates whether the SASL mechanism handler is enabled for use.
148   *
149   * @return Returns the "enabled" property definition.
150   */
151  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
152    return PD_ENABLED;
153  }
154
155
156
157  /**
158   * Get the "java-class" property definition.
159   * <p>
160   * Specifies the fully-qualified name of the Java class that
161   * provides the SASL mechanism handler implementation.
162   *
163   * @return Returns the "java-class" property definition.
164   */
165  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
166    return PD_JAVA_CLASS;
167  }
168
169
170
171  /**
172   * Managed object client implementation.
173   */
174  private static class SASLMechanismHandlerCfgClientImpl implements
175    SASLMechanismHandlerCfgClient {
176
177    /** Private implementation. */
178    private ManagedObject<? extends SASLMechanismHandlerCfgClient> impl;
179
180
181
182    /** Private constructor. */
183    private SASLMechanismHandlerCfgClientImpl(
184        ManagedObject<? extends SASLMechanismHandlerCfgClient> impl) {
185      this.impl = impl;
186    }
187
188
189
190    /** {@inheritDoc} */
191    public Boolean isEnabled() {
192      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
193    }
194
195
196
197    /** {@inheritDoc} */
198    public void setEnabled(boolean value) {
199      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
200    }
201
202
203
204    /** {@inheritDoc} */
205    public String getJavaClass() {
206      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
207    }
208
209
210
211    /** {@inheritDoc} */
212    public void setJavaClass(String value) {
213      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
214    }
215
216
217
218    /** {@inheritDoc} */
219    public ManagedObjectDefinition<? extends SASLMechanismHandlerCfgClient, ? extends SASLMechanismHandlerCfg> definition() {
220      return INSTANCE;
221    }
222
223
224
225    /** {@inheritDoc} */
226    public PropertyProvider properties() {
227      return impl;
228    }
229
230
231
232    /** {@inheritDoc} */
233    public void commit() throws ManagedObjectAlreadyExistsException,
234        MissingMandatoryPropertiesException, ConcurrentModificationException,
235        OperationRejectedException, LdapException {
236      impl.commit();
237    }
238
239
240
241    /** {@inheritDoc} */
242    public String toString() {
243      return impl.toString();
244    }
245  }
246
247
248
249  /**
250   * Managed object server implementation.
251   */
252  private static class SASLMechanismHandlerCfgServerImpl implements
253    SASLMechanismHandlerCfg {
254
255    /** Private implementation. */
256    private ServerManagedObject<? extends SASLMechanismHandlerCfg> impl;
257
258    /** The value of the "enabled" property. */
259    private final boolean pEnabled;
260
261    /** The value of the "java-class" property. */
262    private final String pJavaClass;
263
264
265
266    /** Private constructor. */
267    private SASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends SASLMechanismHandlerCfg> impl) {
268      this.impl = impl;
269      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
270      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
271    }
272
273
274
275    /** {@inheritDoc} */
276    public void addChangeListener(
277        ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
278      impl.registerChangeListener(listener);
279    }
280
281
282
283    /** {@inheritDoc} */
284    public void removeChangeListener(
285        ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
286      impl.deregisterChangeListener(listener);
287    }
288
289
290
291    /** {@inheritDoc} */
292    public boolean isEnabled() {
293      return pEnabled;
294    }
295
296
297
298    /** {@inheritDoc} */
299    public String getJavaClass() {
300      return pJavaClass;
301    }
302
303
304
305    /** {@inheritDoc} */
306    public Class<? extends SASLMechanismHandlerCfg> configurationClass() {
307      return SASLMechanismHandlerCfg.class;
308    }
309
310
311
312    /** {@inheritDoc} */
313    public DN dn() {
314      return impl.getDN();
315    }
316
317
318
319    /** {@inheritDoc} */
320    public String toString() {
321      return impl.toString();
322    }
323  }
324}