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.AggregationPropertyDefinition;
022import org.forgerock.opendj.config.BooleanPropertyDefinition;
023import org.forgerock.opendj.config.ClassPropertyDefinition;
024import org.forgerock.opendj.config.client.ConcurrentModificationException;
025import org.forgerock.opendj.config.client.ManagedObject;
026import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
027import org.forgerock.opendj.config.client.OperationRejectedException;
028import org.forgerock.opendj.config.conditions.Conditions;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
032import org.forgerock.opendj.config.ManagedObjectDefinition;
033import org.forgerock.opendj.config.PropertyOption;
034import org.forgerock.opendj.config.PropertyProvider;
035import org.forgerock.opendj.config.server.ConfigurationChangeListener;
036import org.forgerock.opendj.config.server.ServerManagedObject;
037import org.forgerock.opendj.config.Tag;
038import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
039import org.forgerock.opendj.ldap.DN;
040import org.forgerock.opendj.ldap.LdapException;
041import org.forgerock.opendj.server.config.client.CramMD5SASLMechanismHandlerCfgClient;
042import org.forgerock.opendj.server.config.client.IdentityMapperCfgClient;
043import org.forgerock.opendj.server.config.server.CramMD5SASLMechanismHandlerCfg;
044import org.forgerock.opendj.server.config.server.IdentityMapperCfg;
045import org.forgerock.opendj.server.config.server.SASLMechanismHandlerCfg;
046
047
048
049/**
050 * An interface for querying the Cram MD5 SASL Mechanism Handler
051 * managed object definition meta information.
052 * <p>
053 * The CRAM-MD5 SASL mechanism provides the ability for clients to
054 * perform password-based authentication in a manner that does not
055 * expose their password in the clear.
056 */
057public final class CramMD5SASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<CramMD5SASLMechanismHandlerCfgClient, CramMD5SASLMechanismHandlerCfg> {
058
059  /** The singleton configuration definition instance. */
060  private static final CramMD5SASLMechanismHandlerCfgDefn INSTANCE = new CramMD5SASLMechanismHandlerCfgDefn();
061
062
063
064  /** The "identity-mapper" property definition. */
065  private static final AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> PD_IDENTITY_MAPPER;
066
067
068
069  /** The "java-class" property definition. */
070  private static final ClassPropertyDefinition PD_JAVA_CLASS;
071
072
073
074  /** Build the "identity-mapper" property definition. */
075  static {
076      AggregationPropertyDefinition.Builder<IdentityMapperCfgClient, IdentityMapperCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "identity-mapper");
077      builder.setOption(PropertyOption.MANDATORY);
078      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "identity-mapper"));
079      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
080      builder.setParentPath("/");
081      builder.setRelationDefinition("identity-mapper");
082      builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true"));
083      builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true"));
084      PD_IDENTITY_MAPPER = builder.getInstance();
085      INSTANCE.registerPropertyDefinition(PD_IDENTITY_MAPPER);
086      INSTANCE.registerConstraint(PD_IDENTITY_MAPPER.getSourceConstraint());
087  }
088
089
090
091  /** Build the "java-class" property definition. */
092  static {
093      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
094      builder.setOption(PropertyOption.MANDATORY);
095      builder.setOption(PropertyOption.ADVANCED);
096      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
097      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.CRAMMD5SASLMechanismHandler");
098      builder.setDefaultBehaviorProvider(provider);
099      builder.addInstanceOf("org.opends.server.api.SASLMechanismHandler");
100      PD_JAVA_CLASS = builder.getInstance();
101      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
102  }
103
104
105
106  // Register the tags associated with this managed object definition.
107  static {
108    INSTANCE.registerTag(Tag.valueOf("security"));
109  }
110
111
112
113  /**
114   * Get the Cram MD5 SASL Mechanism Handler configuration definition
115   * singleton.
116   *
117   * @return Returns the Cram MD5 SASL Mechanism Handler configuration
118   *         definition singleton.
119   */
120  public static CramMD5SASLMechanismHandlerCfgDefn getInstance() {
121    return INSTANCE;
122  }
123
124
125
126  /**
127   * Private constructor.
128   */
129  private CramMD5SASLMechanismHandlerCfgDefn() {
130    super("cram-md5-sasl-mechanism-handler", SASLMechanismHandlerCfgDefn.getInstance());
131  }
132
133
134
135  /** {@inheritDoc} */
136  public CramMD5SASLMechanismHandlerCfgClient createClientConfiguration(
137      ManagedObject<? extends CramMD5SASLMechanismHandlerCfgClient> impl) {
138    return new CramMD5SASLMechanismHandlerCfgClientImpl(impl);
139  }
140
141
142
143  /** {@inheritDoc} */
144  public CramMD5SASLMechanismHandlerCfg createServerConfiguration(
145      ServerManagedObject<? extends CramMD5SASLMechanismHandlerCfg> impl) {
146    return new CramMD5SASLMechanismHandlerCfgServerImpl(impl);
147  }
148
149
150
151  /** {@inheritDoc} */
152  public Class<CramMD5SASLMechanismHandlerCfg> getServerConfigurationClass() {
153    return CramMD5SASLMechanismHandlerCfg.class;
154  }
155
156
157
158  /**
159   * Get the "enabled" property definition.
160   * <p>
161   * Indicates whether the SASL mechanism handler is enabled for use.
162   *
163   * @return Returns the "enabled" property definition.
164   */
165  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
166    return SASLMechanismHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
167  }
168
169
170
171  /**
172   * Get the "identity-mapper" property definition.
173   * <p>
174   * Specifies the name of the identity mapper used with this SASL
175   * mechanism handler to match the authentication ID included in the
176   * SASL bind request to the corresponding user in the directory.
177   *
178   * @return Returns the "identity-mapper" property definition.
179   */
180  public AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> getIdentityMapperPropertyDefinition() {
181    return PD_IDENTITY_MAPPER;
182  }
183
184
185
186  /**
187   * Get the "java-class" property definition.
188   * <p>
189   * Specifies the fully-qualified name of the Java class that
190   * provides the SASL mechanism handler implementation.
191   *
192   * @return Returns the "java-class" property definition.
193   */
194  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
195    return PD_JAVA_CLASS;
196  }
197
198
199
200  /**
201   * Managed object client implementation.
202   */
203  private static class CramMD5SASLMechanismHandlerCfgClientImpl implements
204    CramMD5SASLMechanismHandlerCfgClient {
205
206    /** Private implementation. */
207    private ManagedObject<? extends CramMD5SASLMechanismHandlerCfgClient> impl;
208
209
210
211    /** Private constructor. */
212    private CramMD5SASLMechanismHandlerCfgClientImpl(
213        ManagedObject<? extends CramMD5SASLMechanismHandlerCfgClient> impl) {
214      this.impl = impl;
215    }
216
217
218
219    /** {@inheritDoc} */
220    public Boolean isEnabled() {
221      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
222    }
223
224
225
226    /** {@inheritDoc} */
227    public void setEnabled(boolean value) {
228      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
229    }
230
231
232
233    /** {@inheritDoc} */
234    public String getIdentityMapper() {
235      return impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition());
236    }
237
238
239
240    /** {@inheritDoc} */
241    public void setIdentityMapper(String value) {
242      impl.setPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition(), value);
243    }
244
245
246
247    /** {@inheritDoc} */
248    public String getJavaClass() {
249      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
250    }
251
252
253
254    /** {@inheritDoc} */
255    public void setJavaClass(String value) {
256      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
257    }
258
259
260
261    /** {@inheritDoc} */
262    public ManagedObjectDefinition<? extends CramMD5SASLMechanismHandlerCfgClient, ? extends CramMD5SASLMechanismHandlerCfg> definition() {
263      return INSTANCE;
264    }
265
266
267
268    /** {@inheritDoc} */
269    public PropertyProvider properties() {
270      return impl;
271    }
272
273
274
275    /** {@inheritDoc} */
276    public void commit() throws ManagedObjectAlreadyExistsException,
277        MissingMandatoryPropertiesException, ConcurrentModificationException,
278        OperationRejectedException, LdapException {
279      impl.commit();
280    }
281
282
283
284    /** {@inheritDoc} */
285    public String toString() {
286      return impl.toString();
287    }
288  }
289
290
291
292  /**
293   * Managed object server implementation.
294   */
295  private static class CramMD5SASLMechanismHandlerCfgServerImpl implements
296    CramMD5SASLMechanismHandlerCfg {
297
298    /** Private implementation. */
299    private ServerManagedObject<? extends CramMD5SASLMechanismHandlerCfg> impl;
300
301    /** The value of the "enabled" property. */
302    private final boolean pEnabled;
303
304    /** The value of the "identity-mapper" property. */
305    private final String pIdentityMapper;
306
307    /** The value of the "java-class" property. */
308    private final String pJavaClass;
309
310
311
312    /** Private constructor. */
313    private CramMD5SASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends CramMD5SASLMechanismHandlerCfg> impl) {
314      this.impl = impl;
315      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
316      this.pIdentityMapper = impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition());
317      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
318    }
319
320
321
322    /** {@inheritDoc} */
323    public void addCramMD5ChangeListener(
324        ConfigurationChangeListener<CramMD5SASLMechanismHandlerCfg> listener) {
325      impl.registerChangeListener(listener);
326    }
327
328
329
330    /** {@inheritDoc} */
331    public void removeCramMD5ChangeListener(
332        ConfigurationChangeListener<CramMD5SASLMechanismHandlerCfg> listener) {
333      impl.deregisterChangeListener(listener);
334    }
335    /** {@inheritDoc} */
336    public void addChangeListener(
337        ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
338      impl.registerChangeListener(listener);
339    }
340
341
342
343    /** {@inheritDoc} */
344    public void removeChangeListener(
345        ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
346      impl.deregisterChangeListener(listener);
347    }
348
349
350
351    /** {@inheritDoc} */
352    public boolean isEnabled() {
353      return pEnabled;
354    }
355
356
357
358    /** {@inheritDoc} */
359    public String getIdentityMapper() {
360      return pIdentityMapper;
361    }
362
363
364
365    /**
366     * {@inheritDoc}
367     */
368    public DN getIdentityMapperDN() {
369      String value = getIdentityMapper();
370      if (value == null) return null;
371      return INSTANCE.getIdentityMapperPropertyDefinition().getChildDN(value);
372    }
373
374
375
376    /** {@inheritDoc} */
377    public String getJavaClass() {
378      return pJavaClass;
379    }
380
381
382
383    /** {@inheritDoc} */
384    public Class<? extends CramMD5SASLMechanismHandlerCfg> configurationClass() {
385      return CramMD5SASLMechanismHandlerCfg.class;
386    }
387
388
389
390    /** {@inheritDoc} */
391    public DN dn() {
392      return impl.getDN();
393    }
394
395
396
397    /** {@inheritDoc} */
398    public String toString() {
399      return impl.toString();
400    }
401  }
402}