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 org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.ManagedObject;
027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
028import org.forgerock.opendj.config.client.OperationRejectedException;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.EnumPropertyDefinition;
032import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
033import org.forgerock.opendj.config.ManagedObjectDefinition;
034import org.forgerock.opendj.config.PropertyOption;
035import org.forgerock.opendj.config.PropertyProvider;
036import org.forgerock.opendj.config.server.ConfigurationChangeListener;
037import org.forgerock.opendj.config.server.ServerManagedObject;
038import org.forgerock.opendj.config.Tag;
039import org.forgerock.opendj.config.TopCfgDefn;
040import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
041import org.forgerock.opendj.ldap.DN;
042import org.forgerock.opendj.ldap.LdapException;
043import org.forgerock.opendj.server.config.client.PluginCfgClient;
044import org.forgerock.opendj.server.config.server.PluginCfg;
045
046
047
048/**
049 * An interface for querying the Plugin managed object definition meta
050 * information.
051 * <p>
052 * Plugins provide a mechanism for executing custom code at specified
053 * points in operation processing and in the course of other events
054 * like connection establishment and termination, server startup and
055 * shutdown, and LDIF import and export.
056 */
057public final class PluginCfgDefn extends ManagedObjectDefinition<PluginCfgClient, PluginCfg> {
058
059  /** The singleton configuration definition instance. */
060  private static final PluginCfgDefn INSTANCE = new PluginCfgDefn();
061
062
063
064  /**
065   * Defines the set of permissable values for the "plugin-type" property.
066   * <p>
067   * Specifies the set of plug-in types for the plug-in, which
068   * specifies the times at which the plug-in is invoked.
069   */
070  public static enum PluginType {
071
072    /**
073     * Invoked before sending an intermediate repsonse message to the
074     * client.
075     */
076    INTERMEDIATERESPONSE("intermediateresponse"),
077
078
079
080    /**
081     * Invoked for each operation to be written during an LDIF export.
082     */
083    LDIFEXPORT("ldifexport"),
084
085
086
087    /**
088     * Invoked for each entry read during an LDIF import.
089     */
090    LDIFIMPORT("ldifimport"),
091
092
093
094    /**
095     * Invoked at the beginning of an LDIF import session.
096     */
097    LDIFIMPORTBEGIN("ldifimportbegin"),
098
099
100
101    /**
102     * Invoked at the end of an LDIF import session.
103     */
104    LDIFIMPORTEND("ldifimportend"),
105
106
107
108    /**
109     * Invoked whenever a new connection is established to the server.
110     */
111    POSTCONNECT("postconnect"),
112
113
114
115    /**
116     * Invoked whenever an existing connection is terminated (by
117     * either the client or the server).
118     */
119    POSTDISCONNECT("postdisconnect"),
120
121
122
123    /**
124     * Invoked after completing the abandon processing.
125     */
126    POSTOPERATIONABANDON("postoperationabandon"),
127
128
129
130    /**
131     * Invoked after completing the core add processing but before
132     * sending the response to the client.
133     */
134    POSTOPERATIONADD("postoperationadd"),
135
136
137
138    /**
139     * Invoked after completing the core bind processing but before
140     * sending the response to the client.
141     */
142    POSTOPERATIONBIND("postoperationbind"),
143
144
145
146    /**
147     * Invoked after completing the core compare processing but before
148     * sending the response to the client.
149     */
150    POSTOPERATIONCOMPARE("postoperationcompare"),
151
152
153
154    /**
155     * Invoked after completing the core delete processing but before
156     * sending the response to the client.
157     */
158    POSTOPERATIONDELETE("postoperationdelete"),
159
160
161
162    /**
163     * Invoked after completing the core extended processing but
164     * before sending the response to the client.
165     */
166    POSTOPERATIONEXTENDED("postoperationextended"),
167
168
169
170    /**
171     * Invoked after completing the core modify processing but before
172     * sending the response to the client.
173     */
174    POSTOPERATIONMODIFY("postoperationmodify"),
175
176
177
178    /**
179     * Invoked after completing the core modify DN processing but
180     * before sending the response to the client.
181     */
182    POSTOPERATIONMODIFYDN("postoperationmodifydn"),
183
184
185
186    /**
187     * Invoked after completing the core search processing but before
188     * sending the response to the client.
189     */
190    POSTOPERATIONSEARCH("postoperationsearch"),
191
192
193
194    /**
195     * Invoked after completing the unbind processing.
196     */
197    POSTOPERATIONUNBIND("postoperationunbind"),
198
199
200
201    /**
202     * Invoked after sending the add response to the client.
203     */
204    POSTRESPONSEADD("postresponseadd"),
205
206
207
208    /**
209     * Invoked after sending the bind response to the client.
210     */
211    POSTRESPONSEBIND("postresponsebind"),
212
213
214
215    /**
216     * Invoked after sending the compare response to the client.
217     */
218    POSTRESPONSECOMPARE("postresponsecompare"),
219
220
221
222    /**
223     * Invoked after sending the delete response to the client.
224     */
225    POSTRESPONSEDELETE("postresponsedelete"),
226
227
228
229    /**
230     * Invoked after sending the extended response to the client.
231     */
232    POSTRESPONSEEXTENDED("postresponseextended"),
233
234
235
236    /**
237     * Invoked after sending the modify response to the client.
238     */
239    POSTRESPONSEMODIFY("postresponsemodify"),
240
241
242
243    /**
244     * Invoked after sending the modify DN response to the client.
245     */
246    POSTRESPONSEMODIFYDN("postresponsemodifydn"),
247
248
249
250    /**
251     * Invoked after sending the search result done message to the
252     * client.
253     */
254    POSTRESPONSESEARCH("postresponsesearch"),
255
256
257
258    /**
259     * Invoked after completing post-synchronization processing for an
260     * add operation.
261     */
262    POSTSYNCHRONIZATIONADD("postsynchronizationadd"),
263
264
265
266    /**
267     * Invoked after completing post-synchronization processing for a
268     * delete operation.
269     */
270    POSTSYNCHRONIZATIONDELETE("postsynchronizationdelete"),
271
272
273
274    /**
275     * Invoked after completing post-synchronization processing for a
276     * modify operation.
277     */
278    POSTSYNCHRONIZATIONMODIFY("postsynchronizationmodify"),
279
280
281
282    /**
283     * Invoked after completing post-synchronization processing for a
284     * modify DN operation.
285     */
286    POSTSYNCHRONIZATIONMODIFYDN("postsynchronizationmodifydn"),
287
288
289
290    /**
291     * Invoked prior to performing the core add processing.
292     */
293    PREOPERATIONADD("preoperationadd"),
294
295
296
297    /**
298     * Invoked prior to performing the core bind processing.
299     */
300    PREOPERATIONBIND("preoperationbind"),
301
302
303
304    /**
305     * Invoked prior to performing the core compare processing.
306     */
307    PREOPERATIONCOMPARE("preoperationcompare"),
308
309
310
311    /**
312     * Invoked prior to performing the core delete processing.
313     */
314    PREOPERATIONDELETE("preoperationdelete"),
315
316
317
318    /**
319     * Invoked prior to performing the core extended processing.
320     */
321    PREOPERATIONEXTENDED("preoperationextended"),
322
323
324
325    /**
326     * Invoked prior to performing the core modify processing.
327     */
328    PREOPERATIONMODIFY("preoperationmodify"),
329
330
331
332    /**
333     * Invoked prior to performing the core modify DN processing.
334     */
335    PREOPERATIONMODIFYDN("preoperationmodifydn"),
336
337
338
339    /**
340     * Invoked prior to performing the core search processing.
341     */
342    PREOPERATIONSEARCH("preoperationsearch"),
343
344
345
346    /**
347     * Invoked prior to parsing an abandon request.
348     */
349    PREPARSEABANDON("preparseabandon"),
350
351
352
353    /**
354     * Invoked prior to parsing an add request.
355     */
356    PREPARSEADD("preparseadd"),
357
358
359
360    /**
361     * Invoked prior to parsing a bind request.
362     */
363    PREPARSEBIND("preparsebind"),
364
365
366
367    /**
368     * Invoked prior to parsing a compare request.
369     */
370    PREPARSECOMPARE("preparsecompare"),
371
372
373
374    /**
375     * Invoked prior to parsing a delete request.
376     */
377    PREPARSEDELETE("preparsedelete"),
378
379
380
381    /**
382     * Invoked prior to parsing an extended request.
383     */
384    PREPARSEEXTENDED("preparseextended"),
385
386
387
388    /**
389     * Invoked prior to parsing a modify request.
390     */
391    PREPARSEMODIFY("preparsemodify"),
392
393
394
395    /**
396     * Invoked prior to parsing a modify DN request.
397     */
398    PREPARSEMODIFYDN("preparsemodifydn"),
399
400
401
402    /**
403     * Invoked prior to parsing a search request.
404     */
405    PREPARSESEARCH("preparsesearch"),
406
407
408
409    /**
410     * Invoked prior to parsing an unbind request.
411     */
412    PREPARSEUNBIND("preparseunbind"),
413
414
415
416    /**
417     * Invoked before sending a search result entry to the client.
418     */
419    SEARCHRESULTENTRY("searchresultentry"),
420
421
422
423    /**
424     * Invoked before sending a search result reference to the client.
425     */
426    SEARCHRESULTREFERENCE("searchresultreference"),
427
428
429
430    /**
431     * Invoked during a graceful directory server shutdown.
432     */
433    SHUTDOWN("shutdown"),
434
435
436
437    /**
438     * Invoked during the directory server startup process.
439     */
440    STARTUP("startup"),
441
442
443
444    /**
445     * Invoked in the course of deleting a subordinate entry of a
446     * delete operation.
447     */
448    SUBORDINATEDELETE("subordinatedelete"),
449
450
451
452    /**
453     * Invoked in the course of moving or renaming an entry
454     * subordinate to the target of a modify DN operation.
455     */
456    SUBORDINATEMODIFYDN("subordinatemodifydn");
457
458
459
460    /** String representation of the value. */
461    private final String name;
462
463
464
465    /** Private constructor. */
466    private PluginType(String name) { this.name = name; }
467
468
469
470    /** {@inheritDoc} */
471    public String toString() { return name; }
472
473  }
474
475
476
477  /** The "enabled" property definition. */
478  private static final BooleanPropertyDefinition PD_ENABLED;
479
480
481
482  /** The "invoke-for-internal-operations" property definition. */
483  private static final BooleanPropertyDefinition PD_INVOKE_FOR_INTERNAL_OPERATIONS;
484
485
486
487  /** The "java-class" property definition. */
488  private static final ClassPropertyDefinition PD_JAVA_CLASS;
489
490
491
492  /** The "plugin-type" property definition. */
493  private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
494
495
496
497  /** Build the "enabled" property definition. */
498  static {
499      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
500      builder.setOption(PropertyOption.MANDATORY);
501      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
502      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
503      PD_ENABLED = builder.getInstance();
504      INSTANCE.registerPropertyDefinition(PD_ENABLED);
505  }
506
507
508
509  /** Build the "invoke-for-internal-operations" property definition. */
510  static {
511      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "invoke-for-internal-operations");
512      builder.setOption(PropertyOption.ADVANCED);
513      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "invoke-for-internal-operations"));
514      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
515      builder.setDefaultBehaviorProvider(provider);
516      PD_INVOKE_FOR_INTERNAL_OPERATIONS = builder.getInstance();
517      INSTANCE.registerPropertyDefinition(PD_INVOKE_FOR_INTERNAL_OPERATIONS);
518  }
519
520
521
522  /** Build the "java-class" property definition. */
523  static {
524      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
525      builder.setOption(PropertyOption.MANDATORY);
526      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
527      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
528      builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
529      PD_JAVA_CLASS = builder.getInstance();
530      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
531  }
532
533
534
535  /** Build the "plugin-type" property definition. */
536  static {
537      EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
538      builder.setOption(PropertyOption.MULTI_VALUED);
539      builder.setOption(PropertyOption.MANDATORY);
540      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
541      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<PluginType>());
542      builder.setEnumClass(PluginType.class);
543      PD_PLUGIN_TYPE = builder.getInstance();
544      INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
545  }
546
547
548
549  // Register the tags associated with this managed object definition.
550  static {
551    INSTANCE.registerTag(Tag.valueOf("core-server"));
552  }
553
554
555
556  /**
557   * Get the Plugin configuration definition singleton.
558   *
559   * @return Returns the Plugin configuration definition singleton.
560   */
561  public static PluginCfgDefn getInstance() {
562    return INSTANCE;
563  }
564
565
566
567  /**
568   * Private constructor.
569   */
570  private PluginCfgDefn() {
571    super("plugin", TopCfgDefn.getInstance());
572  }
573
574
575
576  /** {@inheritDoc} */
577  public PluginCfgClient createClientConfiguration(
578      ManagedObject<? extends PluginCfgClient> impl) {
579    return new PluginCfgClientImpl(impl);
580  }
581
582
583
584  /** {@inheritDoc} */
585  public PluginCfg createServerConfiguration(
586      ServerManagedObject<? extends PluginCfg> impl) {
587    return new PluginCfgServerImpl(impl);
588  }
589
590
591
592  /** {@inheritDoc} */
593  public Class<PluginCfg> getServerConfigurationClass() {
594    return PluginCfg.class;
595  }
596
597
598
599  /**
600   * Get the "enabled" property definition.
601   * <p>
602   * Indicates whether the plug-in is enabled for use.
603   *
604   * @return Returns the "enabled" property definition.
605   */
606  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
607    return PD_ENABLED;
608  }
609
610
611
612  /**
613   * Get the "invoke-for-internal-operations" property definition.
614   * <p>
615   * Indicates whether the plug-in should be invoked for internal
616   * operations.
617   * <p>
618   * Any plug-in that can be invoked for internal operations must
619   * ensure that it does not create any new internal operatons that can
620   * cause the same plug-in to be re-invoked.
621   *
622   * @return Returns the "invoke-for-internal-operations" property definition.
623   */
624  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
625    return PD_INVOKE_FOR_INTERNAL_OPERATIONS;
626  }
627
628
629
630  /**
631   * Get the "java-class" property definition.
632   * <p>
633   * Specifies the fully-qualified name of the Java class that
634   * provides the plug-in implementation.
635   *
636   * @return Returns the "java-class" property definition.
637   */
638  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
639    return PD_JAVA_CLASS;
640  }
641
642
643
644  /**
645   * Get the "plugin-type" property definition.
646   * <p>
647   * Specifies the set of plug-in types for the plug-in, which
648   * specifies the times at which the plug-in is invoked.
649   *
650   * @return Returns the "plugin-type" property definition.
651   */
652  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
653    return PD_PLUGIN_TYPE;
654  }
655
656
657
658  /**
659   * Managed object client implementation.
660   */
661  private static class PluginCfgClientImpl implements
662    PluginCfgClient {
663
664    /** Private implementation. */
665    private ManagedObject<? extends PluginCfgClient> impl;
666
667
668
669    /** Private constructor. */
670    private PluginCfgClientImpl(
671        ManagedObject<? extends PluginCfgClient> impl) {
672      this.impl = impl;
673    }
674
675
676
677    /** {@inheritDoc} */
678    public Boolean isEnabled() {
679      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
680    }
681
682
683
684    /** {@inheritDoc} */
685    public void setEnabled(boolean value) {
686      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
687    }
688
689
690
691    /** {@inheritDoc} */
692    public boolean isInvokeForInternalOperations() {
693      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
694    }
695
696
697
698    /** {@inheritDoc} */
699    public void setInvokeForInternalOperations(Boolean value) {
700      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
701    }
702
703
704
705    /** {@inheritDoc} */
706    public String getJavaClass() {
707      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
708    }
709
710
711
712    /** {@inheritDoc} */
713    public void setJavaClass(String value) {
714      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
715    }
716
717
718
719    /** {@inheritDoc} */
720    public SortedSet<PluginType> getPluginType() {
721      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
722    }
723
724
725
726    /** {@inheritDoc} */
727    public void setPluginType(Collection<PluginType> values) {
728      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
729    }
730
731
732
733    /** {@inheritDoc} */
734    public ManagedObjectDefinition<? extends PluginCfgClient, ? extends PluginCfg> definition() {
735      return INSTANCE;
736    }
737
738
739
740    /** {@inheritDoc} */
741    public PropertyProvider properties() {
742      return impl;
743    }
744
745
746
747    /** {@inheritDoc} */
748    public void commit() throws ManagedObjectAlreadyExistsException,
749        MissingMandatoryPropertiesException, ConcurrentModificationException,
750        OperationRejectedException, LdapException {
751      impl.commit();
752    }
753
754
755
756    /** {@inheritDoc} */
757    public String toString() {
758      return impl.toString();
759    }
760  }
761
762
763
764  /**
765   * Managed object server implementation.
766   */
767  private static class PluginCfgServerImpl implements
768    PluginCfg {
769
770    /** Private implementation. */
771    private ServerManagedObject<? extends PluginCfg> impl;
772
773    /** The value of the "enabled" property. */
774    private final boolean pEnabled;
775
776    /** The value of the "invoke-for-internal-operations" property. */
777    private final boolean pInvokeForInternalOperations;
778
779    /** The value of the "java-class" property. */
780    private final String pJavaClass;
781
782    /** The value of the "plugin-type" property. */
783    private final SortedSet<PluginType> pPluginType;
784
785
786
787    /** Private constructor. */
788    private PluginCfgServerImpl(ServerManagedObject<? extends PluginCfg> impl) {
789      this.impl = impl;
790      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
791      this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
792      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
793      this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
794    }
795
796
797
798    /** {@inheritDoc} */
799    public void addChangeListener(
800        ConfigurationChangeListener<PluginCfg> listener) {
801      impl.registerChangeListener(listener);
802    }
803
804
805
806    /** {@inheritDoc} */
807    public void removeChangeListener(
808        ConfigurationChangeListener<PluginCfg> listener) {
809      impl.deregisterChangeListener(listener);
810    }
811
812
813
814    /** {@inheritDoc} */
815    public boolean isEnabled() {
816      return pEnabled;
817    }
818
819
820
821    /** {@inheritDoc} */
822    public boolean isInvokeForInternalOperations() {
823      return pInvokeForInternalOperations;
824    }
825
826
827
828    /** {@inheritDoc} */
829    public String getJavaClass() {
830      return pJavaClass;
831    }
832
833
834
835    /** {@inheritDoc} */
836    public SortedSet<PluginType> getPluginType() {
837      return pPluginType;
838    }
839
840
841
842    /** {@inheritDoc} */
843    public Class<? extends PluginCfg> configurationClass() {
844      return PluginCfg.class;
845    }
846
847
848
849    /** {@inheritDoc} */
850    public DN dn() {
851      return impl.getDN();
852    }
853
854
855
856    /** {@inheritDoc} */
857    public String toString() {
858      return impl.toString();
859    }
860  }
861}