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 java.util.Collection;
032    import java.util.SortedSet;
033    import org.opends.server.admin.AdministratorAction;
034    import org.opends.server.admin.AliasDefaultBehaviorProvider;
035    import org.opends.server.admin.BooleanPropertyDefinition;
036    import org.opends.server.admin.ClassPropertyDefinition;
037    import org.opends.server.admin.client.AuthorizationException;
038    import org.opends.server.admin.client.CommunicationException;
039    import org.opends.server.admin.client.ConcurrentModificationException;
040    import org.opends.server.admin.client.ManagedObject;
041    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
042    import org.opends.server.admin.client.OperationRejectedException;
043    import org.opends.server.admin.IPAddressMaskPropertyDefinition;
044    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
045    import org.opends.server.admin.ManagedObjectDefinition;
046    import org.opends.server.admin.PropertyOption;
047    import org.opends.server.admin.PropertyProvider;
048    import org.opends.server.admin.server.ConfigurationChangeListener;
049    import org.opends.server.admin.server.ServerManagedObject;
050    import org.opends.server.admin.std.client.ConnectionHandlerCfgClient;
051    import org.opends.server.admin.std.server.ConnectionHandlerCfg;
052    import org.opends.server.admin.Tag;
053    import org.opends.server.admin.TopCfgDefn;
054    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
055    import org.opends.server.types.AddressMask;
056    import org.opends.server.types.DN;
057    
058    
059    
060    /**
061     * An interface for querying the Connection Handler managed object
062     * definition meta information.
063     * <p>
064     * Connection Handlers are responsible for handling all interaction
065     * with the clients, including accepting the connections, reading
066     * requests, and sending responses.
067     */
068    public final class ConnectionHandlerCfgDefn extends ManagedObjectDefinition<ConnectionHandlerCfgClient, ConnectionHandlerCfg> {
069    
070      // The singleton configuration definition instance.
071      private static final ConnectionHandlerCfgDefn INSTANCE = new ConnectionHandlerCfgDefn();
072    
073    
074    
075      // The "allowed-client" property definition.
076      private static final IPAddressMaskPropertyDefinition PD_ALLOWED_CLIENT;
077    
078    
079    
080      // The "denied-client" property definition.
081      private static final IPAddressMaskPropertyDefinition PD_DENIED_CLIENT;
082    
083    
084    
085      // The "enabled" property definition.
086      private static final BooleanPropertyDefinition PD_ENABLED;
087    
088    
089    
090      // The "java-class" property definition.
091      private static final ClassPropertyDefinition PD_JAVA_CLASS;
092    
093    
094    
095      // Build the "allowed-client" property definition.
096      static {
097          IPAddressMaskPropertyDefinition.Builder builder = IPAddressMaskPropertyDefinition.createBuilder(INSTANCE, "allowed-client");
098          builder.setOption(PropertyOption.MULTI_VALUED);
099          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allowed-client"));
100          builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<AddressMask>(INSTANCE, "allowed-client"));
101          PD_ALLOWED_CLIENT = builder.getInstance();
102          INSTANCE.registerPropertyDefinition(PD_ALLOWED_CLIENT);
103      }
104    
105    
106    
107      // Build the "denied-client" property definition.
108      static {
109          IPAddressMaskPropertyDefinition.Builder builder = IPAddressMaskPropertyDefinition.createBuilder(INSTANCE, "denied-client");
110          builder.setOption(PropertyOption.MULTI_VALUED);
111          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "denied-client"));
112          builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<AddressMask>(INSTANCE, "denied-client"));
113          PD_DENIED_CLIENT = builder.getInstance();
114          INSTANCE.registerPropertyDefinition(PD_DENIED_CLIENT);
115      }
116    
117    
118    
119      // Build the "enabled" property definition.
120      static {
121          BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
122          builder.setOption(PropertyOption.MANDATORY);
123          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
124          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
125          PD_ENABLED = builder.getInstance();
126          INSTANCE.registerPropertyDefinition(PD_ENABLED);
127      }
128    
129    
130    
131      // Build the "java-class" property definition.
132      static {
133          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
134          builder.setOption(PropertyOption.MANDATORY);
135          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
136          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
137          builder.addInstanceOf("org.opends.server.api.ConnectionHandler");
138          PD_JAVA_CLASS = builder.getInstance();
139          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
140      }
141    
142    
143    
144      // Register the tags associated with this managed object definition.
145      static {
146        INSTANCE.registerTag(Tag.valueOf("core-server"));
147      }
148    
149    
150    
151      /**
152       * Get the Connection Handler configuration definition singleton.
153       *
154       * @return Returns the Connection Handler configuration definition
155       *         singleton.
156       */
157      public static ConnectionHandlerCfgDefn getInstance() {
158        return INSTANCE;
159      }
160    
161    
162    
163      /**
164       * Private constructor.
165       */
166      private ConnectionHandlerCfgDefn() {
167        super("connection-handler", TopCfgDefn.getInstance());
168      }
169    
170    
171    
172      /**
173       * {@inheritDoc}
174       */
175      public ConnectionHandlerCfgClient createClientConfiguration(
176          ManagedObject<? extends ConnectionHandlerCfgClient> impl) {
177        return new ConnectionHandlerCfgClientImpl(impl);
178      }
179    
180    
181    
182      /**
183       * {@inheritDoc}
184       */
185      public ConnectionHandlerCfg createServerConfiguration(
186          ServerManagedObject<? extends ConnectionHandlerCfg> impl) {
187        return new ConnectionHandlerCfgServerImpl(impl);
188      }
189    
190    
191    
192      /**
193       * {@inheritDoc}
194       */
195      public Class<ConnectionHandlerCfg> getServerConfigurationClass() {
196        return ConnectionHandlerCfg.class;
197      }
198    
199    
200    
201      /**
202       * Get the "allowed-client" property definition.
203       * <p>
204       * Specifies a set of address masks that determines the addresses of
205       * the clients that are allowed to establish connections to this
206       * connection handler.
207       *
208       * @return Returns the "allowed-client" property definition.
209       */
210      public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() {
211        return PD_ALLOWED_CLIENT;
212      }
213    
214    
215    
216      /**
217       * Get the "denied-client" property definition.
218       * <p>
219       * Specifies a set of address masks that determines the addresses of
220       * the clients that are not allowed to establish connections to this
221       * connection handler.
222       * <p>
223       * If both allowed and denied client masks are defined and a client
224       * connection matches one or more masks in both lists, then the
225       * connection is denied. If only a denied list is specified, then any
226       * client not matching a mask in that list is allowed.
227       *
228       * @return Returns the "denied-client" property definition.
229       */
230      public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() {
231        return PD_DENIED_CLIENT;
232      }
233    
234    
235    
236      /**
237       * Get the "enabled" property definition.
238       * <p>
239       * Indicates whether the Connection Handler is enabled.
240       *
241       * @return Returns the "enabled" property definition.
242       */
243      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
244        return PD_ENABLED;
245      }
246    
247    
248    
249      /**
250       * Get the "java-class" property definition.
251       * <p>
252       * Specifies the fully-qualified name of the Java class that
253       * provides the Connection Handler implementation.
254       *
255       * @return Returns the "java-class" property definition.
256       */
257      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
258        return PD_JAVA_CLASS;
259      }
260    
261    
262    
263      /**
264       * Managed object client implementation.
265       */
266      private static class ConnectionHandlerCfgClientImpl implements
267        ConnectionHandlerCfgClient {
268    
269        // Private implementation.
270        private ManagedObject<? extends ConnectionHandlerCfgClient> impl;
271    
272    
273    
274        // Private constructor.
275        private ConnectionHandlerCfgClientImpl(
276            ManagedObject<? extends ConnectionHandlerCfgClient> impl) {
277          this.impl = impl;
278        }
279    
280    
281    
282        /**
283         * {@inheritDoc}
284         */
285        public SortedSet<AddressMask> getAllowedClient() {
286          return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition());
287        }
288    
289    
290    
291        /**
292         * {@inheritDoc}
293         */
294        public void setAllowedClient(Collection<AddressMask> values) {
295          impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values);
296        }
297    
298    
299    
300        /**
301         * {@inheritDoc}
302         */
303        public SortedSet<AddressMask> getDeniedClient() {
304          return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition());
305        }
306    
307    
308    
309        /**
310         * {@inheritDoc}
311         */
312        public void setDeniedClient(Collection<AddressMask> values) {
313          impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values);
314        }
315    
316    
317    
318        /**
319         * {@inheritDoc}
320         */
321        public Boolean isEnabled() {
322          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
323        }
324    
325    
326    
327        /**
328         * {@inheritDoc}
329         */
330        public void setEnabled(boolean value) {
331          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
332        }
333    
334    
335    
336        /**
337         * {@inheritDoc}
338         */
339        public String getJavaClass() {
340          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
341        }
342    
343    
344    
345        /**
346         * {@inheritDoc}
347         */
348        public void setJavaClass(String value) {
349          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
350        }
351    
352    
353    
354        /**
355         * {@inheritDoc}
356         */
357        public ManagedObjectDefinition<? extends ConnectionHandlerCfgClient, ? extends ConnectionHandlerCfg> definition() {
358          return INSTANCE;
359        }
360    
361    
362    
363        /**
364         * {@inheritDoc}
365         */
366        public PropertyProvider properties() {
367          return impl;
368        }
369    
370    
371    
372        /**
373         * {@inheritDoc}
374         */
375        public void commit() throws ManagedObjectAlreadyExistsException,
376            MissingMandatoryPropertiesException, ConcurrentModificationException,
377            OperationRejectedException, AuthorizationException,
378            CommunicationException {
379          impl.commit();
380        }
381    
382      }
383    
384    
385    
386      /**
387       * Managed object server implementation.
388       */
389      private static class ConnectionHandlerCfgServerImpl implements
390        ConnectionHandlerCfg {
391    
392        // Private implementation.
393        private ServerManagedObject<? extends ConnectionHandlerCfg> impl;
394    
395        // The value of the "allowed-client" property.
396        private final SortedSet<AddressMask> pAllowedClient;
397    
398        // The value of the "denied-client" property.
399        private final SortedSet<AddressMask> pDeniedClient;
400    
401        // The value of the "enabled" property.
402        private final boolean pEnabled;
403    
404        // The value of the "java-class" property.
405        private final String pJavaClass;
406    
407    
408    
409        // Private constructor.
410        private ConnectionHandlerCfgServerImpl(ServerManagedObject<? extends ConnectionHandlerCfg> impl) {
411          this.impl = impl;
412          this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition());
413          this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition());
414          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
415          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
416        }
417    
418    
419    
420        /**
421         * {@inheritDoc}
422         */
423        public void addChangeListener(
424            ConfigurationChangeListener<ConnectionHandlerCfg> listener) {
425          impl.registerChangeListener(listener);
426        }
427    
428    
429    
430        /**
431         * {@inheritDoc}
432         */
433        public void removeChangeListener(
434            ConfigurationChangeListener<ConnectionHandlerCfg> listener) {
435          impl.deregisterChangeListener(listener);
436        }
437    
438    
439    
440        /**
441         * {@inheritDoc}
442         */
443        public SortedSet<AddressMask> getAllowedClient() {
444          return pAllowedClient;
445        }
446    
447    
448    
449        /**
450         * {@inheritDoc}
451         */
452        public SortedSet<AddressMask> getDeniedClient() {
453          return pDeniedClient;
454        }
455    
456    
457    
458        /**
459         * {@inheritDoc}
460         */
461        public boolean isEnabled() {
462          return pEnabled;
463        }
464    
465    
466    
467        /**
468         * {@inheritDoc}
469         */
470        public String getJavaClass() {
471          return pJavaClass;
472        }
473    
474    
475    
476        /**
477         * {@inheritDoc}
478         */
479        public Class<? extends ConnectionHandlerCfg> configurationClass() {
480          return ConnectionHandlerCfg.class;
481        }
482    
483    
484    
485        /**
486         * {@inheritDoc}
487         */
488        public DN dn() {
489          return impl.getDN();
490        }
491    
492      }
493    }