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