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