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 java.util.TreeSet;
023import org.forgerock.opendj.config.AdministratorAction;
024import org.forgerock.opendj.config.AggregationPropertyDefinition;
025import org.forgerock.opendj.config.BooleanPropertyDefinition;
026import org.forgerock.opendj.config.ClassPropertyDefinition;
027import org.forgerock.opendj.config.client.ConcurrentModificationException;
028import org.forgerock.opendj.config.client.ManagedObject;
029import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
030import org.forgerock.opendj.config.client.OperationRejectedException;
031import org.forgerock.opendj.config.conditions.Conditions;
032import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
033import org.forgerock.opendj.config.ManagedObjectDefinition;
034import org.forgerock.opendj.config.PropertyException;
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.TopCfgDefn;
041import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
042import org.forgerock.opendj.ldap.DN;
043import org.forgerock.opendj.ldap.LdapException;
044import org.forgerock.opendj.server.config.client.HTTPAuthorizationMechanismCfgClient;
045import org.forgerock.opendj.server.config.client.HTTPEndpointCfgClient;
046import org.forgerock.opendj.server.config.server.HTTPAuthorizationMechanismCfg;
047import org.forgerock.opendj.server.config.server.HTTPEndpointCfg;
048
049
050
051/**
052 * An interface for querying the HTTP Endpoint managed object
053 * definition meta information.
054 * <p>
055 * The HTTP Endpoint is used to define HTTP endpoint.
056 */
057public final class HTTPEndpointCfgDefn extends ManagedObjectDefinition<HTTPEndpointCfgClient, HTTPEndpointCfg> {
058
059  /** The singleton configuration definition instance. */
060  private static final HTTPEndpointCfgDefn INSTANCE = new HTTPEndpointCfgDefn();
061
062
063
064  /** The "authorization-mechanism" property definition. */
065  private static final AggregationPropertyDefinition<HTTPAuthorizationMechanismCfgClient, HTTPAuthorizationMechanismCfg> PD_AUTHORIZATION_MECHANISM;
066
067
068
069  /** The "base-path" property definition. */
070  private static final StringPropertyDefinition PD_BASE_PATH;
071
072
073
074  /** The "enabled" property definition. */
075  private static final BooleanPropertyDefinition PD_ENABLED;
076
077
078
079  /** The "java-class" property definition. */
080  private static final ClassPropertyDefinition PD_JAVA_CLASS;
081
082
083
084  /** Build the "authorization-mechanism" property definition. */
085  static {
086      AggregationPropertyDefinition.Builder<HTTPAuthorizationMechanismCfgClient, HTTPAuthorizationMechanismCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "authorization-mechanism");
087      builder.setOption(PropertyOption.MULTI_VALUED);
088      builder.setOption(PropertyOption.MANDATORY);
089      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "authorization-mechanism"));
090      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
091      builder.setParentPath("/");
092      builder.setRelationDefinition("http-authorization-mechanism");
093      builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true"));
094      builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true"));
095      PD_AUTHORIZATION_MECHANISM = builder.getInstance();
096      INSTANCE.registerPropertyDefinition(PD_AUTHORIZATION_MECHANISM);
097      INSTANCE.registerConstraint(PD_AUTHORIZATION_MECHANISM.getSourceConstraint());
098  }
099
100
101
102  /** Build the "base-path" property definition. */
103  static {
104      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "base-path");
105      builder.setOption(PropertyOption.READ_ONLY);
106      builder.setOption(PropertyOption.MANDATORY);
107      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "base-path"));
108      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
109      PD_BASE_PATH = builder.getInstance();
110      INSTANCE.registerPropertyDefinition(PD_BASE_PATH);
111  }
112
113
114
115  /** Build the "enabled" property definition. */
116  static {
117      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
118      builder.setOption(PropertyOption.MANDATORY);
119      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
120      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
121      PD_ENABLED = builder.getInstance();
122      INSTANCE.registerPropertyDefinition(PD_ENABLED);
123  }
124
125
126
127  /** Build the "java-class" property definition. */
128  static {
129      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
130      builder.setOption(PropertyOption.MANDATORY);
131      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
132      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
133      builder.addInstanceOf("org.opends.server.api.HttpEndpoint");
134      PD_JAVA_CLASS = builder.getInstance();
135      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
136  }
137
138
139
140  /**
141   * Get the HTTP Endpoint configuration definition singleton.
142   *
143   * @return Returns the HTTP Endpoint configuration definition
144   *         singleton.
145   */
146  public static HTTPEndpointCfgDefn getInstance() {
147    return INSTANCE;
148  }
149
150
151
152  /**
153   * Private constructor.
154   */
155  private HTTPEndpointCfgDefn() {
156    super("http-endpoint", TopCfgDefn.getInstance());
157  }
158
159
160
161  /** {@inheritDoc} */
162  public HTTPEndpointCfgClient createClientConfiguration(
163      ManagedObject<? extends HTTPEndpointCfgClient> impl) {
164    return new HTTPEndpointCfgClientImpl(impl);
165  }
166
167
168
169  /** {@inheritDoc} */
170  public HTTPEndpointCfg createServerConfiguration(
171      ServerManagedObject<? extends HTTPEndpointCfg> impl) {
172    return new HTTPEndpointCfgServerImpl(impl);
173  }
174
175
176
177  /** {@inheritDoc} */
178  public Class<HTTPEndpointCfg> getServerConfigurationClass() {
179    return HTTPEndpointCfg.class;
180  }
181
182
183
184  /**
185   * Get the "authorization-mechanism" property definition.
186   * <p>
187   * The HTTP authorization mechanisms supported by this HTTP
188   * Endpoint.
189   *
190   * @return Returns the "authorization-mechanism" property definition.
191   */
192  public AggregationPropertyDefinition<HTTPAuthorizationMechanismCfgClient, HTTPAuthorizationMechanismCfg> getAuthorizationMechanismPropertyDefinition() {
193    return PD_AUTHORIZATION_MECHANISM;
194  }
195
196
197
198  /**
199   * Get the "base-path" property definition.
200   * <p>
201   * All HTTP requests matching the base path or subordinate to it
202   * will be routed to the HTTP endpoint unless a more specific HTTP
203   * endpoint is found.
204   *
205   * @return Returns the "base-path" property definition.
206   */
207  public StringPropertyDefinition getBasePathPropertyDefinition() {
208    return PD_BASE_PATH;
209  }
210
211
212
213  /**
214   * Get the "enabled" property definition.
215   * <p>
216   * Indicates whether the HTTP Endpoint is enabled.
217   *
218   * @return Returns the "enabled" property definition.
219   */
220  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
221    return PD_ENABLED;
222  }
223
224
225
226  /**
227   * Get the "java-class" property definition.
228   * <p>
229   * Specifies the fully-qualified name of the Java class that
230   * provides the HTTP Endpoint implementation.
231   *
232   * @return Returns the "java-class" property definition.
233   */
234  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
235    return PD_JAVA_CLASS;
236  }
237
238
239
240  /**
241   * Managed object client implementation.
242   */
243  private static class HTTPEndpointCfgClientImpl implements
244    HTTPEndpointCfgClient {
245
246    /** Private implementation. */
247    private ManagedObject<? extends HTTPEndpointCfgClient> impl;
248
249
250
251    /** Private constructor. */
252    private HTTPEndpointCfgClientImpl(
253        ManagedObject<? extends HTTPEndpointCfgClient> impl) {
254      this.impl = impl;
255    }
256
257
258
259    /** {@inheritDoc} */
260    public SortedSet<String> getAuthorizationMechanism() {
261      return impl.getPropertyValues(INSTANCE.getAuthorizationMechanismPropertyDefinition());
262    }
263
264
265
266    /** {@inheritDoc} */
267    public void setAuthorizationMechanism(Collection<String> values) {
268      impl.setPropertyValues(INSTANCE.getAuthorizationMechanismPropertyDefinition(), values);
269    }
270
271
272
273    /** {@inheritDoc} */
274    public String getBasePath() {
275      return impl.getPropertyValue(INSTANCE.getBasePathPropertyDefinition());
276    }
277
278
279
280    /** {@inheritDoc} */
281    public void setBasePath(String value) throws PropertyException {
282      impl.setPropertyValue(INSTANCE.getBasePathPropertyDefinition(), value);
283    }
284
285
286
287    /** {@inheritDoc} */
288    public Boolean isEnabled() {
289      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
290    }
291
292
293
294    /** {@inheritDoc} */
295    public void setEnabled(boolean value) {
296      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
297    }
298
299
300
301    /** {@inheritDoc} */
302    public String getJavaClass() {
303      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
304    }
305
306
307
308    /** {@inheritDoc} */
309    public void setJavaClass(String value) {
310      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
311    }
312
313
314
315    /** {@inheritDoc} */
316    public ManagedObjectDefinition<? extends HTTPEndpointCfgClient, ? extends HTTPEndpointCfg> definition() {
317      return INSTANCE;
318    }
319
320
321
322    /** {@inheritDoc} */
323    public PropertyProvider properties() {
324      return impl;
325    }
326
327
328
329    /** {@inheritDoc} */
330    public void commit() throws ManagedObjectAlreadyExistsException,
331        MissingMandatoryPropertiesException, ConcurrentModificationException,
332        OperationRejectedException, LdapException {
333      impl.commit();
334    }
335
336
337
338    /** {@inheritDoc} */
339    public String toString() {
340      return impl.toString();
341    }
342  }
343
344
345
346  /**
347   * Managed object server implementation.
348   */
349  private static class HTTPEndpointCfgServerImpl implements
350    HTTPEndpointCfg {
351
352    /** Private implementation. */
353    private ServerManagedObject<? extends HTTPEndpointCfg> impl;
354
355    /** The value of the "authorization-mechanism" property. */
356    private final SortedSet<String> pAuthorizationMechanism;
357
358    /** The value of the "base-path" property. */
359    private final String pBasePath;
360
361    /** The value of the "enabled" property. */
362    private final boolean pEnabled;
363
364    /** The value of the "java-class" property. */
365    private final String pJavaClass;
366
367
368
369    /** Private constructor. */
370    private HTTPEndpointCfgServerImpl(ServerManagedObject<? extends HTTPEndpointCfg> impl) {
371      this.impl = impl;
372      this.pAuthorizationMechanism = impl.getPropertyValues(INSTANCE.getAuthorizationMechanismPropertyDefinition());
373      this.pBasePath = impl.getPropertyValue(INSTANCE.getBasePathPropertyDefinition());
374      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
375      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
376    }
377
378
379
380    /** {@inheritDoc} */
381    public void addChangeListener(
382        ConfigurationChangeListener<HTTPEndpointCfg> listener) {
383      impl.registerChangeListener(listener);
384    }
385
386
387
388    /** {@inheritDoc} */
389    public void removeChangeListener(
390        ConfigurationChangeListener<HTTPEndpointCfg> listener) {
391      impl.deregisterChangeListener(listener);
392    }
393
394
395
396    /** {@inheritDoc} */
397    public SortedSet<String> getAuthorizationMechanism() {
398      return pAuthorizationMechanism;
399    }
400
401
402
403    /**
404     * {@inheritDoc}
405     */
406    public SortedSet<DN> getAuthorizationMechanismDNs() {
407      SortedSet<String> values = getAuthorizationMechanism();
408      SortedSet<DN> dnValues = new TreeSet<DN>();
409      for (String value : values) {
410        DN dn = INSTANCE.getAuthorizationMechanismPropertyDefinition().getChildDN(value);
411        dnValues.add(dn);
412      }
413      return dnValues;
414    }
415
416
417
418    /** {@inheritDoc} */
419    public String getBasePath() {
420      return pBasePath;
421    }
422
423
424
425    /** {@inheritDoc} */
426    public boolean isEnabled() {
427      return pEnabled;
428    }
429
430
431
432    /** {@inheritDoc} */
433    public String getJavaClass() {
434      return pJavaClass;
435    }
436
437
438
439    /** {@inheritDoc} */
440    public Class<? extends HTTPEndpointCfg> configurationClass() {
441      return HTTPEndpointCfg.class;
442    }
443
444
445
446    /** {@inheritDoc} */
447    public DN dn() {
448      return impl.getDN();
449    }
450
451
452
453    /** {@inheritDoc} */
454    public String toString() {
455      return impl.toString();
456    }
457  }
458}