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.BooleanPropertyDefinition;
035    import org.opends.server.admin.ClassPropertyDefinition;
036    import org.opends.server.admin.client.AuthorizationException;
037    import org.opends.server.admin.client.CommunicationException;
038    import org.opends.server.admin.client.ConcurrentModificationException;
039    import org.opends.server.admin.client.ManagedObject;
040    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
041    import org.opends.server.admin.client.OperationRejectedException;
042    import org.opends.server.admin.DefaultBehaviorProvider;
043    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
044    import org.opends.server.admin.DurationPropertyDefinition;
045    import org.opends.server.admin.IPAddressMaskPropertyDefinition;
046    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
047    import org.opends.server.admin.ManagedObjectDefinition;
048    import org.opends.server.admin.PropertyOption;
049    import org.opends.server.admin.PropertyProvider;
050    import org.opends.server.admin.server.ConfigurationChangeListener;
051    import org.opends.server.admin.server.ServerManagedObject;
052    import org.opends.server.admin.std.client.LDIFConnectionHandlerCfgClient;
053    import org.opends.server.admin.std.server.ConnectionHandlerCfg;
054    import org.opends.server.admin.std.server.LDIFConnectionHandlerCfg;
055    import org.opends.server.admin.StringPropertyDefinition;
056    import org.opends.server.admin.Tag;
057    import org.opends.server.types.AddressMask;
058    import org.opends.server.types.DN;
059    
060    
061    
062    /**
063     * An interface for querying the LDIF Connection Handler managed
064     * object definition meta information.
065     * <p>
066     * The LDIF Connection Handler is used to process changes in the
067     * server using internal operations, where the changes to process are
068     * read from an LDIF file.
069     */
070    public final class LDIFConnectionHandlerCfgDefn extends ManagedObjectDefinition<LDIFConnectionHandlerCfgClient, LDIFConnectionHandlerCfg> {
071    
072      // The singleton configuration definition instance.
073      private static final LDIFConnectionHandlerCfgDefn INSTANCE = new LDIFConnectionHandlerCfgDefn();
074    
075    
076    
077      // The "java-class" property definition.
078      private static final ClassPropertyDefinition PD_JAVA_CLASS;
079    
080    
081    
082      // The "ldif-directory" property definition.
083      private static final StringPropertyDefinition PD_LDIF_DIRECTORY;
084    
085    
086    
087      // The "poll-interval" property definition.
088      private static final DurationPropertyDefinition PD_POLL_INTERVAL;
089    
090    
091    
092      // Build the "java-class" property definition.
093      static {
094          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
095          builder.setOption(PropertyOption.MANDATORY);
096          builder.setOption(PropertyOption.ADVANCED);
097          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
098          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.protocols.LDIFConnectionHandler");
099          builder.setDefaultBehaviorProvider(provider);
100          builder.addInstanceOf("org.opends.server.api.ConnectionHandler");
101          PD_JAVA_CLASS = builder.getInstance();
102          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
103      }
104    
105    
106    
107      // Build the "ldif-directory" property definition.
108      static {
109          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "ldif-directory");
110          builder.setOption(PropertyOption.MANDATORY);
111          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "ldif-directory"));
112          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("config/auto-process-ldif");
113          builder.setDefaultBehaviorProvider(provider);
114          PD_LDIF_DIRECTORY = builder.getInstance();
115          INSTANCE.registerPropertyDefinition(PD_LDIF_DIRECTORY);
116      }
117    
118    
119    
120      // Build the "poll-interval" property definition.
121      static {
122          DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "poll-interval");
123          builder.setOption(PropertyOption.MANDATORY);
124          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "poll-interval"));
125          DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("5 seconds");
126          builder.setDefaultBehaviorProvider(provider);
127          builder.setBaseUnit("ms");
128          builder.setLowerLimit("1");
129          PD_POLL_INTERVAL = builder.getInstance();
130          INSTANCE.registerPropertyDefinition(PD_POLL_INTERVAL);
131      }
132    
133    
134    
135      // Register the tags associated with this managed object definition.
136      static {
137        INSTANCE.registerTag(Tag.valueOf("core-server"));
138      }
139    
140    
141    
142      /**
143       * Get the LDIF Connection Handler configuration definition
144       * singleton.
145       *
146       * @return Returns the LDIF Connection Handler configuration
147       *         definition singleton.
148       */
149      public static LDIFConnectionHandlerCfgDefn getInstance() {
150        return INSTANCE;
151      }
152    
153    
154    
155      /**
156       * Private constructor.
157       */
158      private LDIFConnectionHandlerCfgDefn() {
159        super("ldif-connection-handler", ConnectionHandlerCfgDefn.getInstance());
160      }
161    
162    
163    
164      /**
165       * {@inheritDoc}
166       */
167      public LDIFConnectionHandlerCfgClient createClientConfiguration(
168          ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl) {
169        return new LDIFConnectionHandlerCfgClientImpl(impl);
170      }
171    
172    
173    
174      /**
175       * {@inheritDoc}
176       */
177      public LDIFConnectionHandlerCfg createServerConfiguration(
178          ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl) {
179        return new LDIFConnectionHandlerCfgServerImpl(impl);
180      }
181    
182    
183    
184      /**
185       * {@inheritDoc}
186       */
187      public Class<LDIFConnectionHandlerCfg> getServerConfigurationClass() {
188        return LDIFConnectionHandlerCfg.class;
189      }
190    
191    
192    
193      /**
194       * Get the "allowed-client" property definition.
195       * <p>
196       * Specifies a set of address masks that determines the addresses of
197       * the clients that are allowed to establish connections to this
198       * connection handler.
199       *
200       * @return Returns the "allowed-client" property definition.
201       */
202      public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() {
203        return ConnectionHandlerCfgDefn.getInstance().getAllowedClientPropertyDefinition();
204      }
205    
206    
207    
208      /**
209       * Get the "denied-client" property definition.
210       * <p>
211       * Specifies a set of address masks that determines the addresses of
212       * the clients that are not allowed to establish connections to this
213       * connection handler.
214       * <p>
215       * If both allowed and denied client masks are defined and a client
216       * connection matches one or more masks in both lists, then the
217       * connection is denied. If only a denied list is specified, then any
218       * client not matching a mask in that list is allowed.
219       *
220       * @return Returns the "denied-client" property definition.
221       */
222      public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() {
223        return ConnectionHandlerCfgDefn.getInstance().getDeniedClientPropertyDefinition();
224      }
225    
226    
227    
228      /**
229       * Get the "enabled" property definition.
230       * <p>
231       * Indicates whether the LDIF Connection Handler is enabled.
232       *
233       * @return Returns the "enabled" property definition.
234       */
235      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
236        return ConnectionHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
237      }
238    
239    
240    
241      /**
242       * Get the "java-class" property definition.
243       * <p>
244       * Specifies the fully-qualified name of the Java class that
245       * provides the LDIF Connection Handler implementation.
246       *
247       * @return Returns the "java-class" property definition.
248       */
249      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
250        return PD_JAVA_CLASS;
251      }
252    
253    
254    
255      /**
256       * Get the "ldif-directory" property definition.
257       * <p>
258       * Specifies the path to the directory in which the LDIF files
259       * should be placed.
260       *
261       * @return Returns the "ldif-directory" property definition.
262       */
263      public StringPropertyDefinition getLDIFDirectoryPropertyDefinition() {
264        return PD_LDIF_DIRECTORY;
265      }
266    
267    
268    
269      /**
270       * Get the "poll-interval" property definition.
271       * <p>
272       * Specifies how frequently the LDIF connection handler should check
273       * the LDIF directory to determine whether a new LDIF file has been
274       * added.
275       *
276       * @return Returns the "poll-interval" property definition.
277       */
278      public DurationPropertyDefinition getPollIntervalPropertyDefinition() {
279        return PD_POLL_INTERVAL;
280      }
281    
282    
283    
284      /**
285       * Managed object client implementation.
286       */
287      private static class LDIFConnectionHandlerCfgClientImpl implements
288        LDIFConnectionHandlerCfgClient {
289    
290        // Private implementation.
291        private ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl;
292    
293    
294    
295        // Private constructor.
296        private LDIFConnectionHandlerCfgClientImpl(
297            ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl) {
298          this.impl = impl;
299        }
300    
301    
302    
303        /**
304         * {@inheritDoc}
305         */
306        public SortedSet<AddressMask> getAllowedClient() {
307          return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition());
308        }
309    
310    
311    
312        /**
313         * {@inheritDoc}
314         */
315        public void setAllowedClient(Collection<AddressMask> values) {
316          impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values);
317        }
318    
319    
320    
321        /**
322         * {@inheritDoc}
323         */
324        public SortedSet<AddressMask> getDeniedClient() {
325          return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition());
326        }
327    
328    
329    
330        /**
331         * {@inheritDoc}
332         */
333        public void setDeniedClient(Collection<AddressMask> values) {
334          impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values);
335        }
336    
337    
338    
339        /**
340         * {@inheritDoc}
341         */
342        public Boolean isEnabled() {
343          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
344        }
345    
346    
347    
348        /**
349         * {@inheritDoc}
350         */
351        public void setEnabled(boolean value) {
352          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
353        }
354    
355    
356    
357        /**
358         * {@inheritDoc}
359         */
360        public String getJavaClass() {
361          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
362        }
363    
364    
365    
366        /**
367         * {@inheritDoc}
368         */
369        public void setJavaClass(String value) {
370          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
371        }
372    
373    
374    
375        /**
376         * {@inheritDoc}
377         */
378        public String getLDIFDirectory() {
379          return impl.getPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition());
380        }
381    
382    
383    
384        /**
385         * {@inheritDoc}
386         */
387        public void setLDIFDirectory(String value) {
388          impl.setPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition(), value);
389        }
390    
391    
392    
393        /**
394         * {@inheritDoc}
395         */
396        public long getPollInterval() {
397          return impl.getPropertyValue(INSTANCE.getPollIntervalPropertyDefinition());
398        }
399    
400    
401    
402        /**
403         * {@inheritDoc}
404         */
405        public void setPollInterval(long value) {
406          impl.setPropertyValue(INSTANCE.getPollIntervalPropertyDefinition(), value);
407        }
408    
409    
410    
411        /**
412         * {@inheritDoc}
413         */
414        public ManagedObjectDefinition<? extends LDIFConnectionHandlerCfgClient, ? extends LDIFConnectionHandlerCfg> definition() {
415          return INSTANCE;
416        }
417    
418    
419    
420        /**
421         * {@inheritDoc}
422         */
423        public PropertyProvider properties() {
424          return impl;
425        }
426    
427    
428    
429        /**
430         * {@inheritDoc}
431         */
432        public void commit() throws ManagedObjectAlreadyExistsException,
433            MissingMandatoryPropertiesException, ConcurrentModificationException,
434            OperationRejectedException, AuthorizationException,
435            CommunicationException {
436          impl.commit();
437        }
438    
439      }
440    
441    
442    
443      /**
444       * Managed object server implementation.
445       */
446      private static class LDIFConnectionHandlerCfgServerImpl implements
447        LDIFConnectionHandlerCfg {
448    
449        // Private implementation.
450        private ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl;
451    
452        // The value of the "allowed-client" property.
453        private final SortedSet<AddressMask> pAllowedClient;
454    
455        // The value of the "denied-client" property.
456        private final SortedSet<AddressMask> pDeniedClient;
457    
458        // The value of the "enabled" property.
459        private final boolean pEnabled;
460    
461        // The value of the "java-class" property.
462        private final String pJavaClass;
463    
464        // The value of the "ldif-directory" property.
465        private final String pLDIFDirectory;
466    
467        // The value of the "poll-interval" property.
468        private final long pPollInterval;
469    
470    
471    
472        // Private constructor.
473        private LDIFConnectionHandlerCfgServerImpl(ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl) {
474          this.impl = impl;
475          this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition());
476          this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition());
477          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
478          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
479          this.pLDIFDirectory = impl.getPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition());
480          this.pPollInterval = impl.getPropertyValue(INSTANCE.getPollIntervalPropertyDefinition());
481        }
482    
483    
484    
485        /**
486         * {@inheritDoc}
487         */
488        public void addLDIFChangeListener(
489            ConfigurationChangeListener<LDIFConnectionHandlerCfg> listener) {
490          impl.registerChangeListener(listener);
491        }
492    
493    
494    
495        /**
496         * {@inheritDoc}
497         */
498        public void removeLDIFChangeListener(
499            ConfigurationChangeListener<LDIFConnectionHandlerCfg> listener) {
500          impl.deregisterChangeListener(listener);
501        }
502        /**
503         * {@inheritDoc}
504         */
505        public void addChangeListener(
506            ConfigurationChangeListener<ConnectionHandlerCfg> listener) {
507          impl.registerChangeListener(listener);
508        }
509    
510    
511    
512        /**
513         * {@inheritDoc}
514         */
515        public void removeChangeListener(
516            ConfigurationChangeListener<ConnectionHandlerCfg> listener) {
517          impl.deregisterChangeListener(listener);
518        }
519    
520    
521    
522        /**
523         * {@inheritDoc}
524         */
525        public SortedSet<AddressMask> getAllowedClient() {
526          return pAllowedClient;
527        }
528    
529    
530    
531        /**
532         * {@inheritDoc}
533         */
534        public SortedSet<AddressMask> getDeniedClient() {
535          return pDeniedClient;
536        }
537    
538    
539    
540        /**
541         * {@inheritDoc}
542         */
543        public boolean isEnabled() {
544          return pEnabled;
545        }
546    
547    
548    
549        /**
550         * {@inheritDoc}
551         */
552        public String getJavaClass() {
553          return pJavaClass;
554        }
555    
556    
557    
558        /**
559         * {@inheritDoc}
560         */
561        public String getLDIFDirectory() {
562          return pLDIFDirectory;
563        }
564    
565    
566    
567        /**
568         * {@inheritDoc}
569         */
570        public long getPollInterval() {
571          return pPollInterval;
572        }
573    
574    
575    
576        /**
577         * {@inheritDoc}
578         */
579        public Class<? extends LDIFConnectionHandlerCfg> configurationClass() {
580          return LDIFConnectionHandlerCfg.class;
581        }
582    
583    
584    
585        /**
586         * {@inheritDoc}
587         */
588        public DN dn() {
589          return impl.getDN();
590        }
591    
592      }
593    }