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