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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.admin.std.meta;
028    
029    
030    
031    import org.opends.server.admin.AdministratorAction;
032    import org.opends.server.admin.BooleanPropertyDefinition;
033    import org.opends.server.admin.ClassPropertyDefinition;
034    import org.opends.server.admin.client.AuthorizationException;
035    import org.opends.server.admin.client.CommunicationException;
036    import org.opends.server.admin.client.ConcurrentModificationException;
037    import org.opends.server.admin.client.ManagedObject;
038    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
039    import org.opends.server.admin.client.OperationRejectedException;
040    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
041    import org.opends.server.admin.ManagedObjectDefinition;
042    import org.opends.server.admin.PropertyOption;
043    import org.opends.server.admin.PropertyProvider;
044    import org.opends.server.admin.server.ConfigurationChangeListener;
045    import org.opends.server.admin.server.ServerManagedObject;
046    import org.opends.server.admin.std.client.TrustManagerProviderCfgClient;
047    import org.opends.server.admin.std.server.TrustManagerProviderCfg;
048    import org.opends.server.admin.Tag;
049    import org.opends.server.admin.TopCfgDefn;
050    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
051    import org.opends.server.types.DN;
052    
053    
054    
055    /**
056     * An interface for querying the Trust Manager Provider managed object
057     * definition meta information.
058     * <p>
059     * Trust Manager Providers determine whether to trust presented
060     * certificates.
061     */
062    public final class TrustManagerProviderCfgDefn extends ManagedObjectDefinition<TrustManagerProviderCfgClient, TrustManagerProviderCfg> {
063    
064      // The singleton configuration definition instance.
065      private static final TrustManagerProviderCfgDefn INSTANCE = new TrustManagerProviderCfgDefn();
066    
067    
068    
069      // The "enabled" property definition.
070      private static final BooleanPropertyDefinition PD_ENABLED;
071    
072    
073    
074      // The "java-class" property definition.
075      private static final ClassPropertyDefinition PD_JAVA_CLASS;
076    
077    
078    
079      // Build the "enabled" property definition.
080      static {
081          BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
082          builder.setOption(PropertyOption.MANDATORY);
083          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
084          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
085          PD_ENABLED = builder.getInstance();
086          INSTANCE.registerPropertyDefinition(PD_ENABLED);
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.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
096          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
097          builder.addInstanceOf("org.opends.server.api.TrustManagerProvider");
098          PD_JAVA_CLASS = builder.getInstance();
099          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
100      }
101    
102    
103    
104      // Register the tags associated with this managed object definition.
105      static {
106        INSTANCE.registerTag(Tag.valueOf("security"));
107      }
108    
109    
110    
111      /**
112       * Get the Trust Manager Provider configuration definition
113       * singleton.
114       *
115       * @return Returns the Trust Manager Provider configuration
116       *         definition singleton.
117       */
118      public static TrustManagerProviderCfgDefn getInstance() {
119        return INSTANCE;
120      }
121    
122    
123    
124      /**
125       * Private constructor.
126       */
127      private TrustManagerProviderCfgDefn() {
128        super("trust-manager-provider", TopCfgDefn.getInstance());
129      }
130    
131    
132    
133      /**
134       * {@inheritDoc}
135       */
136      public TrustManagerProviderCfgClient createClientConfiguration(
137          ManagedObject<? extends TrustManagerProviderCfgClient> impl) {
138        return new TrustManagerProviderCfgClientImpl(impl);
139      }
140    
141    
142    
143      /**
144       * {@inheritDoc}
145       */
146      public TrustManagerProviderCfg createServerConfiguration(
147          ServerManagedObject<? extends TrustManagerProviderCfg> impl) {
148        return new TrustManagerProviderCfgServerImpl(impl);
149      }
150    
151    
152    
153      /**
154       * {@inheritDoc}
155       */
156      public Class<TrustManagerProviderCfg> getServerConfigurationClass() {
157        return TrustManagerProviderCfg.class;
158      }
159    
160    
161    
162      /**
163       * Get the "enabled" property definition.
164       * <p>
165       * Indicate whether the Trust Manager Provider is enabled for use.
166       *
167       * @return Returns the "enabled" property definition.
168       */
169      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
170        return PD_ENABLED;
171      }
172    
173    
174    
175      /**
176       * Get the "java-class" property definition.
177       * <p>
178       * The fully-qualified name of the Java class that provides the
179       * Trust Manager Provider implementation.
180       *
181       * @return Returns the "java-class" property definition.
182       */
183      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
184        return PD_JAVA_CLASS;
185      }
186    
187    
188    
189      /**
190       * Managed object client implementation.
191       */
192      private static class TrustManagerProviderCfgClientImpl implements
193        TrustManagerProviderCfgClient {
194    
195        // Private implementation.
196        private ManagedObject<? extends TrustManagerProviderCfgClient> impl;
197    
198    
199    
200        // Private constructor.
201        private TrustManagerProviderCfgClientImpl(
202            ManagedObject<? extends TrustManagerProviderCfgClient> impl) {
203          this.impl = impl;
204        }
205    
206    
207    
208        /**
209         * {@inheritDoc}
210         */
211        public Boolean isEnabled() {
212          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
213        }
214    
215    
216    
217        /**
218         * {@inheritDoc}
219         */
220        public void setEnabled(boolean value) {
221          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
222        }
223    
224    
225    
226        /**
227         * {@inheritDoc}
228         */
229        public String getJavaClass() {
230          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
231        }
232    
233    
234    
235        /**
236         * {@inheritDoc}
237         */
238        public void setJavaClass(String value) {
239          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
240        }
241    
242    
243    
244        /**
245         * {@inheritDoc}
246         */
247        public ManagedObjectDefinition<? extends TrustManagerProviderCfgClient, ? extends TrustManagerProviderCfg> definition() {
248          return INSTANCE;
249        }
250    
251    
252    
253        /**
254         * {@inheritDoc}
255         */
256        public PropertyProvider properties() {
257          return impl;
258        }
259    
260    
261    
262        /**
263         * {@inheritDoc}
264         */
265        public void commit() throws ManagedObjectAlreadyExistsException,
266            MissingMandatoryPropertiesException, ConcurrentModificationException,
267            OperationRejectedException, AuthorizationException,
268            CommunicationException {
269          impl.commit();
270        }
271    
272      }
273    
274    
275    
276      /**
277       * Managed object server implementation.
278       */
279      private static class TrustManagerProviderCfgServerImpl implements
280        TrustManagerProviderCfg {
281    
282        // Private implementation.
283        private ServerManagedObject<? extends TrustManagerProviderCfg> impl;
284    
285        // The value of the "enabled" property.
286        private final boolean pEnabled;
287    
288        // The value of the "java-class" property.
289        private final String pJavaClass;
290    
291    
292    
293        // Private constructor.
294        private TrustManagerProviderCfgServerImpl(ServerManagedObject<? extends TrustManagerProviderCfg> impl) {
295          this.impl = impl;
296          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
297          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
298        }
299    
300    
301    
302        /**
303         * {@inheritDoc}
304         */
305        public void addChangeListener(
306            ConfigurationChangeListener<TrustManagerProviderCfg> listener) {
307          impl.registerChangeListener(listener);
308        }
309    
310    
311    
312        /**
313         * {@inheritDoc}
314         */
315        public void removeChangeListener(
316            ConfigurationChangeListener<TrustManagerProviderCfg> listener) {
317          impl.deregisterChangeListener(listener);
318        }
319    
320    
321    
322        /**
323         * {@inheritDoc}
324         */
325        public boolean isEnabled() {
326          return pEnabled;
327        }
328    
329    
330    
331        /**
332         * {@inheritDoc}
333         */
334        public String getJavaClass() {
335          return pJavaClass;
336        }
337    
338    
339    
340        /**
341         * {@inheritDoc}
342         */
343        public Class<? extends TrustManagerProviderCfg> configurationClass() {
344          return TrustManagerProviderCfg.class;
345        }
346    
347    
348    
349        /**
350         * {@inheritDoc}
351         */
352        public DN dn() {
353          return impl.getDN();
354        }
355    
356      }
357    }