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