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