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