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