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