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 org.forgerock.opendj.config.AdministratorAction;
032import org.forgerock.opendj.config.BooleanPropertyDefinition;
033import org.forgerock.opendj.config.ClassPropertyDefinition;
034import org.forgerock.opendj.config.client.ConcurrentModificationException;
035import org.forgerock.opendj.config.client.IllegalManagedObjectNameException;
036import org.forgerock.opendj.config.client.ManagedObject;
037import org.forgerock.opendj.config.client.ManagedObjectDecodingException;
038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
039import org.forgerock.opendj.config.client.OperationRejectedException;
040import org.forgerock.opendj.config.DefaultBehaviorProvider;
041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
042import org.forgerock.opendj.config.DefinitionDecodingException;
043import org.forgerock.opendj.config.EnumPropertyDefinition;
044import org.forgerock.opendj.config.InstantiableRelationDefinition;
045import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
046import org.forgerock.opendj.config.ManagedObjectDefinition;
047import org.forgerock.opendj.config.ManagedObjectNotFoundException;
048import org.forgerock.opendj.config.PropertyException;
049import org.forgerock.opendj.config.PropertyOption;
050import org.forgerock.opendj.config.PropertyProvider;
051import org.forgerock.opendj.config.server.ConfigException;
052import org.forgerock.opendj.config.server.ConfigurationAddListener;
053import org.forgerock.opendj.config.server.ConfigurationChangeListener;
054import org.forgerock.opendj.config.server.ConfigurationDeleteListener;
055import org.forgerock.opendj.config.server.ServerManagedObject;
056import org.forgerock.opendj.config.StringPropertyDefinition;
057import org.forgerock.opendj.config.Tag;
058import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
059import org.forgerock.opendj.ldap.DN;
060import org.forgerock.opendj.ldap.LdapException;
061import org.forgerock.opendj.server.config.client.AccessLogFilteringCriteriaCfgClient;
062import org.forgerock.opendj.server.config.client.ExternalAccessLogPublisherCfgClient;
063import org.forgerock.opendj.server.config.meta.AccessLogPublisherCfgDefn.FilteringPolicy;
064import org.forgerock.opendj.server.config.server.AccessLogFilteringCriteriaCfg;
065import org.forgerock.opendj.server.config.server.AccessLogPublisherCfg;
066import org.forgerock.opendj.server.config.server.ExternalAccessLogPublisherCfg;
067import org.forgerock.opendj.server.config.server.LogPublisherCfg;
068
069
070
071/**
072 * An interface for querying the External Access Log Publisher managed
073 * object definition meta information.
074 * <p>
075 * External Access Log Publishers publish access messages to an
076 * external handler.
077 */
078public final class ExternalAccessLogPublisherCfgDefn extends ManagedObjectDefinition<ExternalAccessLogPublisherCfgClient, ExternalAccessLogPublisherCfg> {
079
080  /** The singleton configuration definition instance. */
081  private static final ExternalAccessLogPublisherCfgDefn INSTANCE = new ExternalAccessLogPublisherCfgDefn();
082
083
084
085  /** The "config-file" property definition. */
086  private static final StringPropertyDefinition PD_CONFIG_FILE;
087
088
089
090  /** The "java-class" property definition. */
091  private static final ClassPropertyDefinition PD_JAVA_CLASS;
092
093
094
095  /** The "log-control-oids" property definition. */
096  private static final BooleanPropertyDefinition PD_LOG_CONTROL_OIDS;
097
098
099
100  /** Build the "config-file" property definition. */
101  static {
102      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "config-file");
103      builder.setOption(PropertyOption.MANDATORY);
104      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "config-file"));
105      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
106      builder.setPattern(".*", "FILE");
107      PD_CONFIG_FILE = builder.getInstance();
108      INSTANCE.registerPropertyDefinition(PD_CONFIG_FILE);
109  }
110
111
112
113  /** Build the "java-class" property definition. */
114  static {
115      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
116      builder.setOption(PropertyOption.MANDATORY);
117      builder.setOption(PropertyOption.ADVANCED);
118      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
119      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.ExternalAccessLogPublisher");
120      builder.setDefaultBehaviorProvider(provider);
121      builder.addInstanceOf("org.opends.server.loggers.LogPublisher");
122      PD_JAVA_CLASS = builder.getInstance();
123      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
124  }
125
126
127
128  /** Build the "log-control-oids" property definition. */
129  static {
130      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "log-control-oids");
131      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "log-control-oids"));
132      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false");
133      builder.setDefaultBehaviorProvider(provider);
134      PD_LOG_CONTROL_OIDS = builder.getInstance();
135      INSTANCE.registerPropertyDefinition(PD_LOG_CONTROL_OIDS);
136  }
137
138
139
140  // Register the tags associated with this managed object definition.
141  static {
142    INSTANCE.registerTag(Tag.valueOf("logging"));
143  }
144
145
146
147  /**
148   * Get the External Access Log Publisher configuration definition
149   * singleton.
150   *
151   * @return Returns the External Access Log Publisher configuration
152   *         definition singleton.
153   */
154  public static ExternalAccessLogPublisherCfgDefn getInstance() {
155    return INSTANCE;
156  }
157
158
159
160  /**
161   * Private constructor.
162   */
163  private ExternalAccessLogPublisherCfgDefn() {
164    super("external-access-log-publisher", AccessLogPublisherCfgDefn.getInstance());
165  }
166
167
168
169  /** {@inheritDoc} */
170  public ExternalAccessLogPublisherCfgClient createClientConfiguration(
171      ManagedObject<? extends ExternalAccessLogPublisherCfgClient> impl) {
172    return new ExternalAccessLogPublisherCfgClientImpl(impl);
173  }
174
175
176
177  /** {@inheritDoc} */
178  public ExternalAccessLogPublisherCfg createServerConfiguration(
179      ServerManagedObject<? extends ExternalAccessLogPublisherCfg> impl) {
180    return new ExternalAccessLogPublisherCfgServerImpl(impl);
181  }
182
183
184
185  /** {@inheritDoc} */
186  public Class<ExternalAccessLogPublisherCfg> getServerConfigurationClass() {
187    return ExternalAccessLogPublisherCfg.class;
188  }
189
190
191
192  /**
193   * Get the "config-file" property definition.
194   * <p>
195   * The JSON configuration file that defines the External Access Log
196   * Publisher. The content of the JSON configuration file depends on
197   * the type of external audit event handler. The path to the file is
198   * relative to the server root.
199   *
200   * @return Returns the "config-file" property definition.
201   */
202  public StringPropertyDefinition getConfigFilePropertyDefinition() {
203    return PD_CONFIG_FILE;
204  }
205
206
207
208  /**
209   * Get the "enabled" property definition.
210   * <p>
211   * Indicates whether the External Access Log Publisher is enabled
212   * for use.
213   *
214   * @return Returns the "enabled" property definition.
215   */
216  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
217    return AccessLogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition();
218  }
219
220
221
222  /**
223   * Get the "filtering-policy" property definition.
224   * <p>
225   * Specifies how filtering criteria should be applied to log
226   * records.
227   *
228   * @return Returns the "filtering-policy" property definition.
229   */
230  public EnumPropertyDefinition<FilteringPolicy> getFilteringPolicyPropertyDefinition() {
231    return AccessLogPublisherCfgDefn.getInstance().getFilteringPolicyPropertyDefinition();
232  }
233
234
235
236  /**
237   * Get the "java-class" property definition.
238   * <p>
239   * The fully-qualified name of the Java class that provides the
240   * External Access Log Publisher implementation.
241   *
242   * @return Returns the "java-class" property definition.
243   */
244  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
245    return PD_JAVA_CLASS;
246  }
247
248
249
250  /**
251   * Get the "log-control-oids" property definition.
252   * <p>
253   * Specifies whether control OIDs will be included in operation log
254   * records.
255   *
256   * @return Returns the "log-control-oids" property definition.
257   */
258  public BooleanPropertyDefinition getLogControlOidsPropertyDefinition() {
259    return PD_LOG_CONTROL_OIDS;
260  }
261
262
263
264  /**
265   * Get the "suppress-internal-operations" property definition.
266   * <p>
267   * Indicates whether internal operations (for example, operations
268   * that are initiated by plugins) should be logged along with the
269   * operations that are requested by users.
270   *
271   * @return Returns the "suppress-internal-operations" property definition.
272   */
273  public BooleanPropertyDefinition getSuppressInternalOperationsPropertyDefinition() {
274    return AccessLogPublisherCfgDefn.getInstance().getSuppressInternalOperationsPropertyDefinition();
275  }
276
277
278
279  /**
280   * Get the "suppress-synchronization-operations" property definition.
281   * <p>
282   * Indicates whether access messages that are generated by
283   * synchronization operations should be suppressed.
284   *
285   * @return Returns the "suppress-synchronization-operations" property definition.
286   */
287  public BooleanPropertyDefinition getSuppressSynchronizationOperationsPropertyDefinition() {
288    return AccessLogPublisherCfgDefn.getInstance().getSuppressSynchronizationOperationsPropertyDefinition();
289  }
290
291
292
293  /**
294   * Get the "access-log-filtering-criteria" relation definition.
295   *
296   * @return Returns the "access-log-filtering-criteria" relation definition.
297   */
298  public InstantiableRelationDefinition<AccessLogFilteringCriteriaCfgClient,AccessLogFilteringCriteriaCfg> getAccessLogFilteringCriteriaRelationDefinition() {
299    return AccessLogPublisherCfgDefn.getInstance().getAccessLogFilteringCriteriaRelationDefinition();
300  }
301
302
303
304  /**
305   * Managed object client implementation.
306   */
307  private static class ExternalAccessLogPublisherCfgClientImpl implements
308    ExternalAccessLogPublisherCfgClient {
309
310    /** Private implementation. */
311    private ManagedObject<? extends ExternalAccessLogPublisherCfgClient> impl;
312
313
314
315    /** Private constructor. */
316    private ExternalAccessLogPublisherCfgClientImpl(
317        ManagedObject<? extends ExternalAccessLogPublisherCfgClient> impl) {
318      this.impl = impl;
319    }
320
321
322
323    /** {@inheritDoc} */
324    public String getConfigFile() {
325      return impl.getPropertyValue(INSTANCE.getConfigFilePropertyDefinition());
326    }
327
328
329
330    /** {@inheritDoc} */
331    public void setConfigFile(String value) {
332      impl.setPropertyValue(INSTANCE.getConfigFilePropertyDefinition(), value);
333    }
334
335
336
337    /** {@inheritDoc} */
338    public Boolean isEnabled() {
339      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
340    }
341
342
343
344    /** {@inheritDoc} */
345    public void setEnabled(boolean value) {
346      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
347    }
348
349
350
351    /** {@inheritDoc} */
352    public FilteringPolicy getFilteringPolicy() {
353      return impl.getPropertyValue(INSTANCE.getFilteringPolicyPropertyDefinition());
354    }
355
356
357
358    /** {@inheritDoc} */
359    public void setFilteringPolicy(FilteringPolicy value) {
360      impl.setPropertyValue(INSTANCE.getFilteringPolicyPropertyDefinition(), value);
361    }
362
363
364
365    /** {@inheritDoc} */
366    public String getJavaClass() {
367      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
368    }
369
370
371
372    /** {@inheritDoc} */
373    public void setJavaClass(String value) {
374      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
375    }
376
377
378
379    /** {@inheritDoc} */
380    public boolean isLogControlOids() {
381      return impl.getPropertyValue(INSTANCE.getLogControlOidsPropertyDefinition());
382    }
383
384
385
386    /** {@inheritDoc} */
387    public void setLogControlOids(Boolean value) {
388      impl.setPropertyValue(INSTANCE.getLogControlOidsPropertyDefinition(), value);
389    }
390
391
392
393    /** {@inheritDoc} */
394    public boolean isSuppressInternalOperations() {
395      return impl.getPropertyValue(INSTANCE.getSuppressInternalOperationsPropertyDefinition());
396    }
397
398
399
400    /** {@inheritDoc} */
401    public void setSuppressInternalOperations(Boolean value) {
402      impl.setPropertyValue(INSTANCE.getSuppressInternalOperationsPropertyDefinition(), value);
403    }
404
405
406
407    /** {@inheritDoc} */
408    public boolean isSuppressSynchronizationOperations() {
409      return impl.getPropertyValue(INSTANCE.getSuppressSynchronizationOperationsPropertyDefinition());
410    }
411
412
413
414    /** {@inheritDoc} */
415    public void setSuppressSynchronizationOperations(Boolean value) {
416      impl.setPropertyValue(INSTANCE.getSuppressSynchronizationOperationsPropertyDefinition(), value);
417    }
418
419
420
421    /** {@inheritDoc} */
422    public String[] listAccessLogFilteringCriteria() throws ConcurrentModificationException,
423        LdapException {
424      return impl.listChildren(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition());
425    }
426
427
428
429    /** {@inheritDoc} */
430    public AccessLogFilteringCriteriaCfgClient getAccessLogFilteringCriteria(String name)
431        throws DefinitionDecodingException, ManagedObjectDecodingException,
432        ManagedObjectNotFoundException, ConcurrentModificationException,
433        LdapException {
434      return impl.getChild(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), name).getConfiguration();
435    }
436
437
438
439    /** {@inheritDoc} */
440    public <M extends AccessLogFilteringCriteriaCfgClient> M createAccessLogFilteringCriteria(
441        ManagedObjectDefinition<M, ? extends AccessLogFilteringCriteriaCfg> d, String name, Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException {
442      return impl.createChild(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), d, name, exceptions).getConfiguration();
443    }
444
445
446
447    /** {@inheritDoc} */
448    public void removeAccessLogFilteringCriteria(String name)
449        throws ManagedObjectNotFoundException, ConcurrentModificationException,
450        OperationRejectedException, LdapException {
451      impl.removeChild(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), name);
452    }
453
454
455
456    /** {@inheritDoc} */
457    public ManagedObjectDefinition<? extends ExternalAccessLogPublisherCfgClient, ? extends ExternalAccessLogPublisherCfg> definition() {
458      return INSTANCE;
459    }
460
461
462
463    /** {@inheritDoc} */
464    public PropertyProvider properties() {
465      return impl;
466    }
467
468
469
470    /** {@inheritDoc} */
471    public void commit() throws ManagedObjectAlreadyExistsException,
472        MissingMandatoryPropertiesException, ConcurrentModificationException,
473        OperationRejectedException, LdapException {
474      impl.commit();
475    }
476
477
478
479    /** {@inheritDoc} */
480    public String toString() {
481      return impl.toString();
482    }
483  }
484
485
486
487  /**
488   * Managed object server implementation.
489   */
490  private static class ExternalAccessLogPublisherCfgServerImpl implements
491    ExternalAccessLogPublisherCfg {
492
493    /** Private implementation. */
494    private ServerManagedObject<? extends ExternalAccessLogPublisherCfg> impl;
495
496    /** The value of the "config-file" property. */
497    private final String pConfigFile;
498
499    /** The value of the "enabled" property. */
500    private final boolean pEnabled;
501
502    /** The value of the "filtering-policy" property. */
503    private final FilteringPolicy pFilteringPolicy;
504
505    /** The value of the "java-class" property. */
506    private final String pJavaClass;
507
508    /** The value of the "log-control-oids" property. */
509    private final boolean pLogControlOids;
510
511    /** The value of the "suppress-internal-operations" property. */
512    private final boolean pSuppressInternalOperations;
513
514    /** The value of the "suppress-synchronization-operations" property. */
515    private final boolean pSuppressSynchronizationOperations;
516
517
518
519    /** Private constructor. */
520    private ExternalAccessLogPublisherCfgServerImpl(ServerManagedObject<? extends ExternalAccessLogPublisherCfg> impl) {
521      this.impl = impl;
522      this.pConfigFile = impl.getPropertyValue(INSTANCE.getConfigFilePropertyDefinition());
523      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
524      this.pFilteringPolicy = impl.getPropertyValue(INSTANCE.getFilteringPolicyPropertyDefinition());
525      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
526      this.pLogControlOids = impl.getPropertyValue(INSTANCE.getLogControlOidsPropertyDefinition());
527      this.pSuppressInternalOperations = impl.getPropertyValue(INSTANCE.getSuppressInternalOperationsPropertyDefinition());
528      this.pSuppressSynchronizationOperations = impl.getPropertyValue(INSTANCE.getSuppressSynchronizationOperationsPropertyDefinition());
529    }
530
531
532
533    /** {@inheritDoc} */
534    public void addExternalAccessChangeListener(
535        ConfigurationChangeListener<ExternalAccessLogPublisherCfg> listener) {
536      impl.registerChangeListener(listener);
537    }
538
539
540
541    /** {@inheritDoc} */
542    public void removeExternalAccessChangeListener(
543        ConfigurationChangeListener<ExternalAccessLogPublisherCfg> listener) {
544      impl.deregisterChangeListener(listener);
545    }
546    /** {@inheritDoc} */
547    public void addAccessChangeListener(
548        ConfigurationChangeListener<AccessLogPublisherCfg> listener) {
549      impl.registerChangeListener(listener);
550    }
551
552
553
554    /** {@inheritDoc} */
555    public void removeAccessChangeListener(
556        ConfigurationChangeListener<AccessLogPublisherCfg> listener) {
557      impl.deregisterChangeListener(listener);
558    }
559    /** {@inheritDoc} */
560    public void addChangeListener(
561        ConfigurationChangeListener<LogPublisherCfg> listener) {
562      impl.registerChangeListener(listener);
563    }
564
565
566
567    /** {@inheritDoc} */
568    public void removeChangeListener(
569        ConfigurationChangeListener<LogPublisherCfg> listener) {
570      impl.deregisterChangeListener(listener);
571    }
572
573
574
575    /** {@inheritDoc} */
576    public String getConfigFile() {
577      return pConfigFile;
578    }
579
580
581
582    /** {@inheritDoc} */
583    public boolean isEnabled() {
584      return pEnabled;
585    }
586
587
588
589    /** {@inheritDoc} */
590    public FilteringPolicy getFilteringPolicy() {
591      return pFilteringPolicy;
592    }
593
594
595
596    /** {@inheritDoc} */
597    public String getJavaClass() {
598      return pJavaClass;
599    }
600
601
602
603    /** {@inheritDoc} */
604    public boolean isLogControlOids() {
605      return pLogControlOids;
606    }
607
608
609
610    /** {@inheritDoc} */
611    public boolean isSuppressInternalOperations() {
612      return pSuppressInternalOperations;
613    }
614
615
616
617    /** {@inheritDoc} */
618    public boolean isSuppressSynchronizationOperations() {
619      return pSuppressSynchronizationOperations;
620    }
621
622
623
624    /** {@inheritDoc} */
625    public String[] listAccessLogFilteringCriteria() {
626      return impl.listChildren(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition());
627    }
628
629
630
631    /** {@inheritDoc} */
632    public AccessLogFilteringCriteriaCfg getAccessLogFilteringCriteria(String name) throws ConfigException {
633      return impl.getChild(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), name).getConfiguration();
634    }
635
636
637
638    /** {@inheritDoc} */
639    public void addAccessLogFilteringCriteriaAddListener(
640        ConfigurationAddListener<AccessLogFilteringCriteriaCfg> listener) throws ConfigException {
641      impl.registerAddListener(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), listener);
642    }
643
644
645
646    /** {@inheritDoc} */
647    public void removeAccessLogFilteringCriteriaAddListener(
648        ConfigurationAddListener<AccessLogFilteringCriteriaCfg> listener) {
649      impl.deregisterAddListener(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), listener);
650    }
651
652
653
654    /** {@inheritDoc} */
655    public void addAccessLogFilteringCriteriaDeleteListener(
656        ConfigurationDeleteListener<AccessLogFilteringCriteriaCfg> listener) throws ConfigException {
657      impl.registerDeleteListener(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), listener);
658    }
659
660
661
662    /** {@inheritDoc} */
663    public void removeAccessLogFilteringCriteriaDeleteListener(
664        ConfigurationDeleteListener<AccessLogFilteringCriteriaCfg> listener) {
665      impl.deregisterDeleteListener(INSTANCE.getAccessLogFilteringCriteriaRelationDefinition(), listener);
666    }
667
668
669
670    /** {@inheritDoc} */
671    public Class<? extends ExternalAccessLogPublisherCfg> configurationClass() {
672      return ExternalAccessLogPublisherCfg.class;
673    }
674
675
676
677    /** {@inheritDoc} */
678    public DN dn() {
679      return impl.getDN();
680    }
681
682
683
684    /** {@inheritDoc} */
685    public String toString() {
686      return impl.toString();
687    }
688  }
689}