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  /**
171   * {@inheritDoc}
172   */
173  public ConnectionHandlerCfgClient createClientConfiguration(
174      ManagedObject<? extends ConnectionHandlerCfgClient> impl) {
175    return new ConnectionHandlerCfgClientImpl(impl);
176  }
177
178
179
180  /**
181   * {@inheritDoc}
182   */
183  public ConnectionHandlerCfg createServerConfiguration(
184      ServerManagedObject<? extends ConnectionHandlerCfg> impl) {
185    return new ConnectionHandlerCfgServerImpl(impl);
186  }
187
188
189
190  /**
191   * {@inheritDoc}
192   */
193  public Class<ConnectionHandlerCfg> getServerConfigurationClass() {
194    return ConnectionHandlerCfg.class;
195  }
196
197
198
199  /**
200   * Get the "allowed-client" property definition.
201   * <p>
202   * Specifies a set of host names or address masks that determine the
203   * clients that are allowed to establish connections to this
204   * Connection Handler.
205   * <p>
206   * Valid values include a host name, a fully qualified domain name,
207   * a domain name, an IP address, or a subnetwork with subnetwork
208   * mask.
209   *
210   * @return Returns the "allowed-client" property definition.
211   */
212  public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() {
213    return PD_ALLOWED_CLIENT;
214  }
215
216
217
218  /**
219   * Get the "denied-client" property definition.
220   * <p>
221   * Specifies a set of host names or address masks that determine the
222   * clients that are not allowed to establish connections to this
223   * Connection Handler.
224   * <p>
225   * Valid values include a host name, a fully qualified domain name,
226   * a domain name, an IP address, or a subnetwork with subnetwork
227   * mask. If both allowed and denied client masks are defined and a
228   * client connection matches one or more masks in both lists, then
229   * the connection is denied. If only a denied list is specified, then
230   * any client not matching a mask in that list is allowed.
231   *
232   * @return Returns the "denied-client" property definition.
233   */
234  public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() {
235    return PD_DENIED_CLIENT;
236  }
237
238
239
240  /**
241   * Get the "enabled" property definition.
242   * <p>
243   * Indicates whether the Connection Handler is enabled.
244   *
245   * @return Returns the "enabled" property definition.
246   */
247  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
248    return PD_ENABLED;
249  }
250
251
252
253  /**
254   * Get the "java-class" property definition.
255   * <p>
256   * Specifies the fully-qualified name of the Java class that
257   * provides the Connection Handler implementation.
258   *
259   * @return Returns the "java-class" property definition.
260   */
261  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
262    return PD_JAVA_CLASS;
263  }
264
265
266
267  /**
268   * Managed object client implementation.
269   */
270  private static class ConnectionHandlerCfgClientImpl implements
271    ConnectionHandlerCfgClient {
272
273    // Private implementation.
274    private ManagedObject<? extends ConnectionHandlerCfgClient> impl;
275
276
277
278    // Private constructor.
279    private ConnectionHandlerCfgClientImpl(
280        ManagedObject<? extends ConnectionHandlerCfgClient> impl) {
281      this.impl = impl;
282    }
283
284
285
286    /**
287     * {@inheritDoc}
288     */
289    public SortedSet<AddressMask> getAllowedClient() {
290      return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition());
291    }
292
293
294
295    /**
296     * {@inheritDoc}
297     */
298    public void setAllowedClient(Collection<AddressMask> values) {
299      impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values);
300    }
301
302
303
304    /**
305     * {@inheritDoc}
306     */
307    public SortedSet<AddressMask> getDeniedClient() {
308      return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition());
309    }
310
311
312
313    /**
314     * {@inheritDoc}
315     */
316    public void setDeniedClient(Collection<AddressMask> values) {
317      impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values);
318    }
319
320
321
322    /**
323     * {@inheritDoc}
324     */
325    public Boolean isEnabled() {
326      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
327    }
328
329
330
331    /**
332     * {@inheritDoc}
333     */
334    public void setEnabled(boolean value) {
335      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
336    }
337
338
339
340    /**
341     * {@inheritDoc}
342     */
343    public String getJavaClass() {
344      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
345    }
346
347
348
349    /**
350     * {@inheritDoc}
351     */
352    public void setJavaClass(String value) {
353      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
354    }
355
356
357
358    /**
359     * {@inheritDoc}
360     */
361    public ManagedObjectDefinition<? extends ConnectionHandlerCfgClient, ? extends ConnectionHandlerCfg> definition() {
362      return INSTANCE;
363    }
364
365
366
367    /**
368     * {@inheritDoc}
369     */
370    public PropertyProvider properties() {
371      return impl;
372    }
373
374
375
376    /**
377     * {@inheritDoc}
378     */
379    public void commit() throws ManagedObjectAlreadyExistsException,
380        MissingMandatoryPropertiesException, ConcurrentModificationException,
381        OperationRejectedException, LdapException {
382      impl.commit();
383    }
384
385  }
386
387
388
389  /**
390   * Managed object server implementation.
391   */
392  private static class ConnectionHandlerCfgServerImpl implements
393    ConnectionHandlerCfg {
394
395    // Private implementation.
396    private ServerManagedObject<? extends ConnectionHandlerCfg> impl;
397
398    // The value of the "allowed-client" property.
399    private final SortedSet<AddressMask> pAllowedClient;
400
401    // The value of the "denied-client" property.
402    private final SortedSet<AddressMask> pDeniedClient;
403
404    // The value of the "enabled" property.
405    private final boolean pEnabled;
406
407    // The value of the "java-class" property.
408    private final String pJavaClass;
409
410
411
412    // Private constructor.
413    private ConnectionHandlerCfgServerImpl(ServerManagedObject<? extends ConnectionHandlerCfg> impl) {
414      this.impl = impl;
415      this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition());
416      this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition());
417      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
418      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
419    }
420
421
422
423    /**
424     * {@inheritDoc}
425     */
426    public void addChangeListener(
427        ConfigurationChangeListener<ConnectionHandlerCfg> listener) {
428      impl.registerChangeListener(listener);
429    }
430
431
432
433    /**
434     * {@inheritDoc}
435     */
436    public void removeChangeListener(
437        ConfigurationChangeListener<ConnectionHandlerCfg> listener) {
438      impl.deregisterChangeListener(listener);
439    }
440
441
442
443    /**
444     * {@inheritDoc}
445     */
446    public SortedSet<AddressMask> getAllowedClient() {
447      return pAllowedClient;
448    }
449
450
451
452    /**
453     * {@inheritDoc}
454     */
455    public SortedSet<AddressMask> getDeniedClient() {
456      return pDeniedClient;
457    }
458
459
460
461    /**
462     * {@inheritDoc}
463     */
464    public boolean isEnabled() {
465      return pEnabled;
466    }
467
468
469
470    /**
471     * {@inheritDoc}
472     */
473    public String getJavaClass() {
474      return pJavaClass;
475    }
476
477
478
479    /**
480     * {@inheritDoc}
481     */
482    public Class<? extends ConnectionHandlerCfg> configurationClass() {
483      return ConnectionHandlerCfg.class;
484    }
485
486
487
488    /**
489     * {@inheritDoc}
490     */
491    public DN dn() {
492      return impl.getDN();
493    }
494
495  }
496}