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.IdentityMapperCfgClient;
042import org.forgerock.opendj.server.config.client.PlainSASLMechanismHandlerCfgClient;
043import org.forgerock.opendj.server.config.server.IdentityMapperCfg;
044import org.forgerock.opendj.server.config.server.PlainSASLMechanismHandlerCfg;
045import org.forgerock.opendj.server.config.server.SASLMechanismHandlerCfg;
046
047
048
049/**
050 * An interface for querying the Plain SASL Mechanism Handler managed
051 * object definition meta information.
052 * <p>
053 * The Plain SASL Mechanism Handler performs all processing related to
054 * SASL PLAIN authentication.
055 */
056public final class PlainSASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<PlainSASLMechanismHandlerCfgClient, PlainSASLMechanismHandlerCfg> {
057
058  /** The singleton configuration definition instance. */
059  private static final PlainSASLMechanismHandlerCfgDefn INSTANCE = new PlainSASLMechanismHandlerCfgDefn();
060
061
062
063  /** The "identity-mapper" property definition. */
064  private static final AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> PD_IDENTITY_MAPPER;
065
066
067
068  /** The "java-class" property definition. */
069  private static final ClassPropertyDefinition PD_JAVA_CLASS;
070
071
072
073  /** Build the "identity-mapper" property definition. */
074  static {
075      AggregationPropertyDefinition.Builder<IdentityMapperCfgClient, IdentityMapperCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "identity-mapper");
076      builder.setOption(PropertyOption.MANDATORY);
077      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "identity-mapper"));
078      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
079      builder.setParentPath("/");
080      builder.setRelationDefinition("identity-mapper");
081      builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true"));
082      builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true"));
083      PD_IDENTITY_MAPPER = builder.getInstance();
084      INSTANCE.registerPropertyDefinition(PD_IDENTITY_MAPPER);
085      INSTANCE.registerConstraint(PD_IDENTITY_MAPPER.getSourceConstraint());
086  }
087
088
089
090  /** Build the "java-class" property definition. */
091  static {
092      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
093      builder.setOption(PropertyOption.MANDATORY);
094      builder.setOption(PropertyOption.ADVANCED);
095      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
096      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.PlainSASLMechanismHandler");
097      builder.setDefaultBehaviorProvider(provider);
098      builder.addInstanceOf("org.opends.server.api.SASLMechanismHandler");
099      PD_JAVA_CLASS = builder.getInstance();
100      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
101  }
102
103
104
105  // Register the tags associated with this managed object definition.
106  static {
107    INSTANCE.registerTag(Tag.valueOf("security"));
108  }
109
110
111
112  /**
113   * Get the Plain SASL Mechanism Handler configuration definition
114   * singleton.
115   *
116   * @return Returns the Plain SASL Mechanism Handler configuration
117   *         definition singleton.
118   */
119  public static PlainSASLMechanismHandlerCfgDefn getInstance() {
120    return INSTANCE;
121  }
122
123
124
125  /**
126   * Private constructor.
127   */
128  private PlainSASLMechanismHandlerCfgDefn() {
129    super("plain-sasl-mechanism-handler", SASLMechanismHandlerCfgDefn.getInstance());
130  }
131
132
133
134  /** {@inheritDoc} */
135  public PlainSASLMechanismHandlerCfgClient createClientConfiguration(
136      ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl) {
137    return new PlainSASLMechanismHandlerCfgClientImpl(impl);
138  }
139
140
141
142  /** {@inheritDoc} */
143  public PlainSASLMechanismHandlerCfg createServerConfiguration(
144      ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> impl) {
145    return new PlainSASLMechanismHandlerCfgServerImpl(impl);
146  }
147
148
149
150  /** {@inheritDoc} */
151  public Class<PlainSASLMechanismHandlerCfg> getServerConfigurationClass() {
152    return PlainSASLMechanismHandlerCfg.class;
153  }
154
155
156
157  /**
158   * Get the "enabled" property definition.
159   * <p>
160   * Indicates whether the SASL mechanism handler is enabled for use.
161   *
162   * @return Returns the "enabled" property definition.
163   */
164  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
165    return SASLMechanismHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
166  }
167
168
169
170  /**
171   * Get the "identity-mapper" property definition.
172   * <p>
173   * Specifies the name of the identity mapper that is to be used with
174   * this SASL mechanism handler to match the authentication or
175   * authorization ID included in the SASL bind request to the
176   * 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 PlainSASLMechanismHandlerCfgClientImpl implements
204    PlainSASLMechanismHandlerCfgClient {
205
206    /** Private implementation. */
207    private ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl;
208
209
210
211    /** Private constructor. */
212    private PlainSASLMechanismHandlerCfgClientImpl(
213        ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> 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 PlainSASLMechanismHandlerCfgClient, ? extends PlainSASLMechanismHandlerCfg> 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 PlainSASLMechanismHandlerCfgServerImpl implements
296    PlainSASLMechanismHandlerCfg {
297
298    /** Private implementation. */
299    private ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> 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 PlainSASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> 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 addPlainChangeListener(
324        ConfigurationChangeListener<PlainSASLMechanismHandlerCfg> listener) {
325      impl.registerChangeListener(listener);
326    }
327
328
329
330    /** {@inheritDoc} */
331    public void removePlainChangeListener(
332        ConfigurationChangeListener<PlainSASLMechanismHandlerCfg> 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 PlainSASLMechanismHandlerCfg> configurationClass() {
385      return PlainSASLMechanismHandlerCfg.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}