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