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