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.IdentityMapperCfgClient;
041import org.opends.server.admin.std.client.PlainSASLMechanismHandlerCfgClient;
042import org.opends.server.admin.std.server.IdentityMapperCfg;
043import org.opends.server.admin.std.server.PlainSASLMechanismHandlerCfg;
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 Plain SASL Mechanism Handler managed
052 * object definition meta information.
053 * <p>
054 * The Plain SASL Mechanism Handler performs all processing related to
055 * SASL PLAIN authentication.
056 */
057public final class PlainSASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<PlainSASLMechanismHandlerCfgClient, PlainSASLMechanismHandlerCfg> {
058
059  // The singleton configuration definition instance.
060  private static final PlainSASLMechanismHandlerCfgDefn INSTANCE = new PlainSASLMechanismHandlerCfgDefn();
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.PlainSASLMechanismHandler");
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 Plain SASL Mechanism Handler configuration definition
115   * singleton.
116   *
117   * @return Returns the Plain SASL Mechanism Handler configuration
118   *         definition singleton.
119   */
120  public static PlainSASLMechanismHandlerCfgDefn getInstance() {
121    return INSTANCE;
122  }
123
124
125
126  /**
127   * Private constructor.
128   */
129  private PlainSASLMechanismHandlerCfgDefn() {
130    super("plain-sasl-mechanism-handler", SASLMechanismHandlerCfgDefn.getInstance());
131  }
132
133
134
135  /**
136   * {@inheritDoc}
137   */
138  public PlainSASLMechanismHandlerCfgClient createClientConfiguration(
139      ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl) {
140    return new PlainSASLMechanismHandlerCfgClientImpl(impl);
141  }
142
143
144
145  /**
146   * {@inheritDoc}
147   */
148  public PlainSASLMechanismHandlerCfg createServerConfiguration(
149      ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> impl) {
150    return new PlainSASLMechanismHandlerCfgServerImpl(impl);
151  }
152
153
154
155  /**
156   * {@inheritDoc}
157   */
158  public Class<PlainSASLMechanismHandlerCfg> getServerConfigurationClass() {
159    return PlainSASLMechanismHandlerCfg.class;
160  }
161
162
163
164  /**
165   * Get the "enabled" property definition.
166   * <p>
167   * Indicates whether the SASL mechanism handler is enabled for use.
168   *
169   * @return Returns the "enabled" property definition.
170   */
171  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
172    return SASLMechanismHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
173  }
174
175
176
177  /**
178   * Get the "identity-mapper" property definition.
179   * <p>
180   * Specifies the name of the identity mapper that is to be used with
181   * this SASL mechanism handler to match the authentication or
182   * authorization ID included in the SASL bind request to the
183   * 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 PlainSASLMechanismHandlerCfgClientImpl implements
211    PlainSASLMechanismHandlerCfgClient {
212
213    // Private implementation.
214    private ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl;
215
216
217
218    // Private constructor.
219    private PlainSASLMechanismHandlerCfgClientImpl(
220        ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> 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 PlainSASLMechanismHandlerCfgClient, ? extends PlainSASLMechanismHandlerCfg> 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 PlainSASLMechanismHandlerCfgServerImpl implements
322    PlainSASLMechanismHandlerCfg {
323
324    // Private implementation.
325    private ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> 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 PlainSASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> 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 addPlainChangeListener(
352        ConfigurationChangeListener<PlainSASLMechanismHandlerCfg> listener) {
353      impl.registerChangeListener(listener);
354    }
355
356
357
358    /**
359     * {@inheritDoc}
360     */
361    public void removePlainChangeListener(
362        ConfigurationChangeListener<PlainSASLMechanismHandlerCfg> 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 PlainSASLMechanismHandlerCfg> configurationClass() {
427      return PlainSASLMechanismHandlerCfg.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}