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