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