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.forgerock.opendj.server.config.meta;
027
028
029
030import org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
038import org.forgerock.opendj.config.ManagedObjectDefinition;
039import org.forgerock.opendj.config.PropertyOption;
040import org.forgerock.opendj.config.PropertyProvider;
041import org.forgerock.opendj.config.server.ConfigurationChangeListener;
042import org.forgerock.opendj.config.server.ServerManagedObject;
043import org.forgerock.opendj.config.Tag;
044import org.forgerock.opendj.config.TopCfgDefn;
045import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
046import org.forgerock.opendj.ldap.DN;
047import org.forgerock.opendj.ldap.LdapException;
048import org.forgerock.opendj.server.config.client.TrustManagerProviderCfgClient;
049import org.forgerock.opendj.server.config.server.TrustManagerProviderCfg;
050
051
052
053/**
054 * An interface for querying the Trust Manager Provider managed object
055 * definition meta information.
056 * <p>
057 * Trust Manager Providers determine whether to trust presented
058 * certificates.
059 */
060public final class TrustManagerProviderCfgDefn extends ManagedObjectDefinition<TrustManagerProviderCfgClient, TrustManagerProviderCfg> {
061
062  /** The singleton configuration definition instance. */
063  private static final TrustManagerProviderCfgDefn INSTANCE = new TrustManagerProviderCfgDefn();
064
065
066
067  /** The "enabled" property definition. */
068  private static final BooleanPropertyDefinition PD_ENABLED;
069
070
071
072  /** The "java-class" property definition. */
073  private static final ClassPropertyDefinition PD_JAVA_CLASS;
074
075
076
077  /** Build the "enabled" property definition. */
078  static {
079      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
080      builder.setOption(PropertyOption.MANDATORY);
081      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
082      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
083      PD_ENABLED = builder.getInstance();
084      INSTANCE.registerPropertyDefinition(PD_ENABLED);
085  }
086
087
088
089  /** Build the "java-class" property definition. */
090  static {
091      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
092      builder.setOption(PropertyOption.MANDATORY);
093      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
094      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
095      builder.addInstanceOf("org.opends.server.api.TrustManagerProvider");
096      PD_JAVA_CLASS = builder.getInstance();
097      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
098  }
099
100
101
102  // Register the tags associated with this managed object definition.
103  static {
104    INSTANCE.registerTag(Tag.valueOf("security"));
105  }
106
107
108
109  /**
110   * Get the Trust Manager Provider configuration definition
111   * singleton.
112   *
113   * @return Returns the Trust Manager Provider configuration
114   *         definition singleton.
115   */
116  public static TrustManagerProviderCfgDefn getInstance() {
117    return INSTANCE;
118  }
119
120
121
122  /**
123   * Private constructor.
124   */
125  private TrustManagerProviderCfgDefn() {
126    super("trust-manager-provider", TopCfgDefn.getInstance());
127  }
128
129
130
131  /** {@inheritDoc} */
132  public TrustManagerProviderCfgClient createClientConfiguration(
133      ManagedObject<? extends TrustManagerProviderCfgClient> impl) {
134    return new TrustManagerProviderCfgClientImpl(impl);
135  }
136
137
138
139  /** {@inheritDoc} */
140  public TrustManagerProviderCfg createServerConfiguration(
141      ServerManagedObject<? extends TrustManagerProviderCfg> impl) {
142    return new TrustManagerProviderCfgServerImpl(impl);
143  }
144
145
146
147  /** {@inheritDoc} */
148  public Class<TrustManagerProviderCfg> getServerConfigurationClass() {
149    return TrustManagerProviderCfg.class;
150  }
151
152
153
154  /**
155   * Get the "enabled" property definition.
156   * <p>
157   * Indicate whether the Trust Manager Provider is enabled for use.
158   *
159   * @return Returns the "enabled" property definition.
160   */
161  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
162    return PD_ENABLED;
163  }
164
165
166
167  /**
168   * Get the "java-class" property definition.
169   * <p>
170   * The fully-qualified name of the Java class that provides the
171   * Trust Manager Provider implementation.
172   *
173   * @return Returns the "java-class" property definition.
174   */
175  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
176    return PD_JAVA_CLASS;
177  }
178
179
180
181  /**
182   * Managed object client implementation.
183   */
184  private static class TrustManagerProviderCfgClientImpl implements
185    TrustManagerProviderCfgClient {
186
187    /** Private implementation. */
188    private ManagedObject<? extends TrustManagerProviderCfgClient> impl;
189
190
191
192    /** Private constructor. */
193    private TrustManagerProviderCfgClientImpl(
194        ManagedObject<? extends TrustManagerProviderCfgClient> impl) {
195      this.impl = impl;
196    }
197
198
199
200    /** {@inheritDoc} */
201    public Boolean isEnabled() {
202      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
203    }
204
205
206
207    /** {@inheritDoc} */
208    public void setEnabled(boolean value) {
209      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
210    }
211
212
213
214    /** {@inheritDoc} */
215    public String getJavaClass() {
216      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
217    }
218
219
220
221    /** {@inheritDoc} */
222    public void setJavaClass(String value) {
223      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
224    }
225
226
227
228    /** {@inheritDoc} */
229    public ManagedObjectDefinition<? extends TrustManagerProviderCfgClient, ? extends TrustManagerProviderCfg> definition() {
230      return INSTANCE;
231    }
232
233
234
235    /** {@inheritDoc} */
236    public PropertyProvider properties() {
237      return impl;
238    }
239
240
241
242    /** {@inheritDoc} */
243    public void commit() throws ManagedObjectAlreadyExistsException,
244        MissingMandatoryPropertiesException, ConcurrentModificationException,
245        OperationRejectedException, LdapException {
246      impl.commit();
247    }
248
249
250
251    /** {@inheritDoc} */
252    public String toString() {
253      return impl.toString();
254    }
255  }
256
257
258
259  /**
260   * Managed object server implementation.
261   */
262  private static class TrustManagerProviderCfgServerImpl implements
263    TrustManagerProviderCfg {
264
265    /** Private implementation. */
266    private ServerManagedObject<? extends TrustManagerProviderCfg> impl;
267
268    /** The value of the "enabled" property. */
269    private final boolean pEnabled;
270
271    /** The value of the "java-class" property. */
272    private final String pJavaClass;
273
274
275
276    /** Private constructor. */
277    private TrustManagerProviderCfgServerImpl(ServerManagedObject<? extends TrustManagerProviderCfg> impl) {
278      this.impl = impl;
279      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
280      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
281    }
282
283
284
285    /** {@inheritDoc} */
286    public void addChangeListener(
287        ConfigurationChangeListener<TrustManagerProviderCfg> listener) {
288      impl.registerChangeListener(listener);
289    }
290
291
292
293    /** {@inheritDoc} */
294    public void removeChangeListener(
295        ConfigurationChangeListener<TrustManagerProviderCfg> listener) {
296      impl.deregisterChangeListener(listener);
297    }
298
299
300
301    /** {@inheritDoc} */
302    public boolean isEnabled() {
303      return pEnabled;
304    }
305
306
307
308    /** {@inheritDoc} */
309    public String getJavaClass() {
310      return pJavaClass;
311    }
312
313
314
315    /** {@inheritDoc} */
316    public Class<? extends TrustManagerProviderCfg> configurationClass() {
317      return TrustManagerProviderCfg.class;
318    }
319
320
321
322    /** {@inheritDoc} */
323    public DN dn() {
324      return impl.getDN();
325    }
326
327
328
329    /** {@inheritDoc} */
330    public String toString() {
331      return impl.toString();
332    }
333  }
334}