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 org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.DefaultBehaviorProvider;
038import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
039import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
040import org.forgerock.opendj.config.ManagedObjectDefinition;
041import org.forgerock.opendj.config.PropertyOption;
042import org.forgerock.opendj.config.PropertyProvider;
043import org.forgerock.opendj.config.server.ConfigurationChangeListener;
044import org.forgerock.opendj.config.server.ServerManagedObject;
045import org.forgerock.opendj.config.StringPropertyDefinition;
046import org.forgerock.opendj.config.Tag;
047import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
048import org.forgerock.opendj.ldap.DN;
049import org.forgerock.opendj.ldap.LdapException;
050import org.forgerock.opendj.server.config.client.ExternalHTTPAccessLogPublisherCfgClient;
051import org.forgerock.opendj.server.config.server.ExternalHTTPAccessLogPublisherCfg;
052import org.forgerock.opendj.server.config.server.HTTPAccessLogPublisherCfg;
053import org.forgerock.opendj.server.config.server.LogPublisherCfg;
054
055
056
057/**
058 * An interface for querying the External HTTP Access Log Publisher
059 * managed object definition meta information.
060 * <p>
061 * External HTTP Access Log Publishers publish HTTP access messages to
062 * an external handler.
063 */
064public final class ExternalHTTPAccessLogPublisherCfgDefn extends ManagedObjectDefinition<ExternalHTTPAccessLogPublisherCfgClient, ExternalHTTPAccessLogPublisherCfg> {
065
066  /** The singleton configuration definition instance. */
067  private static final ExternalHTTPAccessLogPublisherCfgDefn INSTANCE = new ExternalHTTPAccessLogPublisherCfgDefn();
068
069
070
071  /** The "config-file" property definition. */
072  private static final StringPropertyDefinition PD_CONFIG_FILE;
073
074
075
076  /** The "java-class" property definition. */
077  private static final ClassPropertyDefinition PD_JAVA_CLASS;
078
079
080
081  /** Build the "config-file" property definition. */
082  static {
083      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "config-file");
084      builder.setOption(PropertyOption.MANDATORY);
085      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "config-file"));
086      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
087      builder.setPattern(".*", "FILE");
088      PD_CONFIG_FILE = builder.getInstance();
089      INSTANCE.registerPropertyDefinition(PD_CONFIG_FILE);
090  }
091
092
093
094  /** Build the "java-class" property definition. */
095  static {
096      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
097      builder.setOption(PropertyOption.MANDATORY);
098      builder.setOption(PropertyOption.ADVANCED);
099      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
100      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.CommonAuditHTTPAccessLogPublisher");
101      builder.setDefaultBehaviorProvider(provider);
102      builder.addInstanceOf("org.opends.server.loggers.LogPublisher");
103      PD_JAVA_CLASS = builder.getInstance();
104      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
105  }
106
107
108
109  // Register the tags associated with this managed object definition.
110  static {
111    INSTANCE.registerTag(Tag.valueOf("logging"));
112  }
113
114
115
116  /**
117   * Get the External HTTP Access Log Publisher configuration
118   * definition singleton.
119   *
120   * @return Returns the External HTTP Access Log Publisher
121   *         configuration definition singleton.
122   */
123  public static ExternalHTTPAccessLogPublisherCfgDefn getInstance() {
124    return INSTANCE;
125  }
126
127
128
129  /**
130   * Private constructor.
131   */
132  private ExternalHTTPAccessLogPublisherCfgDefn() {
133    super("external-http-access-log-publisher", HTTPAccessLogPublisherCfgDefn.getInstance());
134  }
135
136
137
138  /** {@inheritDoc} */
139  public ExternalHTTPAccessLogPublisherCfgClient createClientConfiguration(
140      ManagedObject<? extends ExternalHTTPAccessLogPublisherCfgClient> impl) {
141    return new ExternalHTTPAccessLogPublisherCfgClientImpl(impl);
142  }
143
144
145
146  /** {@inheritDoc} */
147  public ExternalHTTPAccessLogPublisherCfg createServerConfiguration(
148      ServerManagedObject<? extends ExternalHTTPAccessLogPublisherCfg> impl) {
149    return new ExternalHTTPAccessLogPublisherCfgServerImpl(impl);
150  }
151
152
153
154  /** {@inheritDoc} */
155  public Class<ExternalHTTPAccessLogPublisherCfg> getServerConfigurationClass() {
156    return ExternalHTTPAccessLogPublisherCfg.class;
157  }
158
159
160
161  /**
162   * Get the "config-file" property definition.
163   * <p>
164   * The JSON configuration file that defines the External HTTP Access
165   * Log Publisher. The content of the JSON configuration file depends
166   * on the type of external audit event handler. The path to the file
167   * is relative to the server root.
168   *
169   * @return Returns the "config-file" property definition.
170   */
171  public StringPropertyDefinition getConfigFilePropertyDefinition() {
172    return PD_CONFIG_FILE;
173  }
174
175
176
177  /**
178   * Get the "enabled" property definition.
179   * <p>
180   * Indicates whether the External HTTP Access Log Publisher is
181   * enabled for use.
182   *
183   * @return Returns the "enabled" property definition.
184   */
185  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
186    return HTTPAccessLogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition();
187  }
188
189
190
191  /**
192   * Get the "java-class" property definition.
193   * <p>
194   * The fully-qualified name of the Java class that provides the
195   * External HTTP Access Log Publisher implementation.
196   *
197   * @return Returns the "java-class" property definition.
198   */
199  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
200    return PD_JAVA_CLASS;
201  }
202
203
204
205  /**
206   * Managed object client implementation.
207   */
208  private static class ExternalHTTPAccessLogPublisherCfgClientImpl implements
209    ExternalHTTPAccessLogPublisherCfgClient {
210
211    /** Private implementation. */
212    private ManagedObject<? extends ExternalHTTPAccessLogPublisherCfgClient> impl;
213
214
215
216    /** Private constructor. */
217    private ExternalHTTPAccessLogPublisherCfgClientImpl(
218        ManagedObject<? extends ExternalHTTPAccessLogPublisherCfgClient> impl) {
219      this.impl = impl;
220    }
221
222
223
224    /** {@inheritDoc} */
225    public String getConfigFile() {
226      return impl.getPropertyValue(INSTANCE.getConfigFilePropertyDefinition());
227    }
228
229
230
231    /** {@inheritDoc} */
232    public void setConfigFile(String value) {
233      impl.setPropertyValue(INSTANCE.getConfigFilePropertyDefinition(), value);
234    }
235
236
237
238    /** {@inheritDoc} */
239    public Boolean isEnabled() {
240      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
241    }
242
243
244
245    /** {@inheritDoc} */
246    public void setEnabled(boolean value) {
247      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
248    }
249
250
251
252    /** {@inheritDoc} */
253    public String getJavaClass() {
254      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
255    }
256
257
258
259    /** {@inheritDoc} */
260    public void setJavaClass(String value) {
261      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
262    }
263
264
265
266    /** {@inheritDoc} */
267    public ManagedObjectDefinition<? extends ExternalHTTPAccessLogPublisherCfgClient, ? extends ExternalHTTPAccessLogPublisherCfg> definition() {
268      return INSTANCE;
269    }
270
271
272
273    /** {@inheritDoc} */
274    public PropertyProvider properties() {
275      return impl;
276    }
277
278
279
280    /** {@inheritDoc} */
281    public void commit() throws ManagedObjectAlreadyExistsException,
282        MissingMandatoryPropertiesException, ConcurrentModificationException,
283        OperationRejectedException, LdapException {
284      impl.commit();
285    }
286
287
288
289    /** {@inheritDoc} */
290    public String toString() {
291      return impl.toString();
292    }
293  }
294
295
296
297  /**
298   * Managed object server implementation.
299   */
300  private static class ExternalHTTPAccessLogPublisherCfgServerImpl implements
301    ExternalHTTPAccessLogPublisherCfg {
302
303    /** Private implementation. */
304    private ServerManagedObject<? extends ExternalHTTPAccessLogPublisherCfg> impl;
305
306    /** The value of the "config-file" property. */
307    private final String pConfigFile;
308
309    /** The value of the "enabled" property. */
310    private final boolean pEnabled;
311
312    /** The value of the "java-class" property. */
313    private final String pJavaClass;
314
315
316
317    /** Private constructor. */
318    private ExternalHTTPAccessLogPublisherCfgServerImpl(ServerManagedObject<? extends ExternalHTTPAccessLogPublisherCfg> impl) {
319      this.impl = impl;
320      this.pConfigFile = impl.getPropertyValue(INSTANCE.getConfigFilePropertyDefinition());
321      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
322      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
323    }
324
325
326
327    /** {@inheritDoc} */
328    public void addExternalHTTPAccessChangeListener(
329        ConfigurationChangeListener<ExternalHTTPAccessLogPublisherCfg> listener) {
330      impl.registerChangeListener(listener);
331    }
332
333
334
335    /** {@inheritDoc} */
336    public void removeExternalHTTPAccessChangeListener(
337        ConfigurationChangeListener<ExternalHTTPAccessLogPublisherCfg> listener) {
338      impl.deregisterChangeListener(listener);
339    }
340    /** {@inheritDoc} */
341    public void addHTTPAccessChangeListener(
342        ConfigurationChangeListener<HTTPAccessLogPublisherCfg> listener) {
343      impl.registerChangeListener(listener);
344    }
345
346
347
348    /** {@inheritDoc} */
349    public void removeHTTPAccessChangeListener(
350        ConfigurationChangeListener<HTTPAccessLogPublisherCfg> listener) {
351      impl.deregisterChangeListener(listener);
352    }
353    /** {@inheritDoc} */
354    public void addChangeListener(
355        ConfigurationChangeListener<LogPublisherCfg> listener) {
356      impl.registerChangeListener(listener);
357    }
358
359
360
361    /** {@inheritDoc} */
362    public void removeChangeListener(
363        ConfigurationChangeListener<LogPublisherCfg> listener) {
364      impl.deregisterChangeListener(listener);
365    }
366
367
368
369    /** {@inheritDoc} */
370    public String getConfigFile() {
371      return pConfigFile;
372    }
373
374
375
376    /** {@inheritDoc} */
377    public boolean isEnabled() {
378      return pEnabled;
379    }
380
381
382
383    /** {@inheritDoc} */
384    public String getJavaClass() {
385      return pJavaClass;
386    }
387
388
389
390    /** {@inheritDoc} */
391    public Class<? extends ExternalHTTPAccessLogPublisherCfg> configurationClass() {
392      return ExternalHTTPAccessLogPublisherCfg.class;
393    }
394
395
396
397    /** {@inheritDoc} */
398    public DN dn() {
399      return impl.getDN();
400    }
401
402
403
404    /** {@inheritDoc} */
405    public String toString() {
406      return impl.toString();
407    }
408  }
409}