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