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 /** {@inheritDoc} */ 481 public String toString() { return name; } 482 483 } 484 485 486 487 /** The "enabled" property definition. */ 488 private static final BooleanPropertyDefinition PD_ENABLED; 489 490 491 492 /** The "invoke-for-internal-operations" property definition. */ 493 private static final BooleanPropertyDefinition PD_INVOKE_FOR_INTERNAL_OPERATIONS; 494 495 496 497 /** The "java-class" property definition. */ 498 private static final ClassPropertyDefinition PD_JAVA_CLASS; 499 500 501 502 /** The "plugin-type" property definition. */ 503 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE; 504 505 506 507 /** Build the "enabled" property definition. */ 508 static { 509 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 510 builder.setOption(PropertyOption.MANDATORY); 511 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 512 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 513 PD_ENABLED = builder.getInstance(); 514 INSTANCE.registerPropertyDefinition(PD_ENABLED); 515 } 516 517 518 519 /** Build the "invoke-for-internal-operations" property definition. */ 520 static { 521 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "invoke-for-internal-operations"); 522 builder.setOption(PropertyOption.ADVANCED); 523 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "invoke-for-internal-operations")); 524 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true"); 525 builder.setDefaultBehaviorProvider(provider); 526 PD_INVOKE_FOR_INTERNAL_OPERATIONS = builder.getInstance(); 527 INSTANCE.registerPropertyDefinition(PD_INVOKE_FOR_INTERNAL_OPERATIONS); 528 } 529 530 531 532 /** Build the "java-class" property definition. */ 533 static { 534 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 535 builder.setOption(PropertyOption.MANDATORY); 536 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 537 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 538 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin"); 539 PD_JAVA_CLASS = builder.getInstance(); 540 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 541 } 542 543 544 545 /** Build the "plugin-type" property definition. */ 546 static { 547 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type"); 548 builder.setOption(PropertyOption.MULTI_VALUED); 549 builder.setOption(PropertyOption.MANDATORY); 550 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type")); 551 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<PluginType>()); 552 builder.setEnumClass(PluginType.class); 553 PD_PLUGIN_TYPE = builder.getInstance(); 554 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE); 555 } 556 557 558 559 // Register the tags associated with this managed object definition. 560 static { 561 INSTANCE.registerTag(Tag.valueOf("core-server")); 562 } 563 564 565 566 /** 567 * Get the Plugin configuration definition singleton. 568 * 569 * @return Returns the Plugin configuration definition singleton. 570 */ 571 public static PluginCfgDefn getInstance() { 572 return INSTANCE; 573 } 574 575 576 577 /** 578 * Private constructor. 579 */ 580 private PluginCfgDefn() { 581 super("plugin", TopCfgDefn.getInstance()); 582 } 583 584 585 586 /** {@inheritDoc} */ 587 public PluginCfgClient createClientConfiguration( 588 ManagedObject<? extends PluginCfgClient> impl) { 589 return new PluginCfgClientImpl(impl); 590 } 591 592 593 594 /** {@inheritDoc} */ 595 public PluginCfg createServerConfiguration( 596 ServerManagedObject<? extends PluginCfg> impl) { 597 return new PluginCfgServerImpl(impl); 598 } 599 600 601 602 /** {@inheritDoc} */ 603 public Class<PluginCfg> getServerConfigurationClass() { 604 return PluginCfg.class; 605 } 606 607 608 609 /** 610 * Get the "enabled" property definition. 611 * <p> 612 * Indicates whether the plug-in is enabled for use. 613 * 614 * @return Returns the "enabled" property definition. 615 */ 616 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 617 return PD_ENABLED; 618 } 619 620 621 622 /** 623 * Get the "invoke-for-internal-operations" property definition. 624 * <p> 625 * Indicates whether the plug-in should be invoked for internal 626 * operations. 627 * <p> 628 * Any plug-in that can be invoked for internal operations must 629 * ensure that it does not create any new internal operatons that can 630 * cause the same plug-in to be re-invoked. 631 * 632 * @return Returns the "invoke-for-internal-operations" property definition. 633 */ 634 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 635 return PD_INVOKE_FOR_INTERNAL_OPERATIONS; 636 } 637 638 639 640 /** 641 * Get the "java-class" property definition. 642 * <p> 643 * Specifies the fully-qualified name of the Java class that 644 * provides the plug-in implementation. 645 * 646 * @return Returns the "java-class" property definition. 647 */ 648 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 649 return PD_JAVA_CLASS; 650 } 651 652 653 654 /** 655 * Get the "plugin-type" property definition. 656 * <p> 657 * Specifies the set of plug-in types for the plug-in, which 658 * specifies the times at which the plug-in is invoked. 659 * 660 * @return Returns the "plugin-type" property definition. 661 */ 662 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 663 return PD_PLUGIN_TYPE; 664 } 665 666 667 668 /** 669 * Managed object client implementation. 670 */ 671 private static class PluginCfgClientImpl implements 672 PluginCfgClient { 673 674 /** Private implementation. */ 675 private ManagedObject<? extends PluginCfgClient> impl; 676 677 678 679 /** Private constructor. */ 680 private PluginCfgClientImpl( 681 ManagedObject<? extends PluginCfgClient> impl) { 682 this.impl = impl; 683 } 684 685 686 687 /** {@inheritDoc} */ 688 public Boolean isEnabled() { 689 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 690 } 691 692 693 694 /** {@inheritDoc} */ 695 public void setEnabled(boolean value) { 696 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 697 } 698 699 700 701 /** {@inheritDoc} */ 702 public boolean isInvokeForInternalOperations() { 703 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 704 } 705 706 707 708 /** {@inheritDoc} */ 709 public void setInvokeForInternalOperations(Boolean value) { 710 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 711 } 712 713 714 715 /** {@inheritDoc} */ 716 public String getJavaClass() { 717 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 718 } 719 720 721 722 /** {@inheritDoc} */ 723 public void setJavaClass(String value) { 724 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 725 } 726 727 728 729 /** {@inheritDoc} */ 730 public SortedSet<PluginType> getPluginType() { 731 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 732 } 733 734 735 736 /** {@inheritDoc} */ 737 public void setPluginType(Collection<PluginType> values) { 738 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 739 } 740 741 742 743 /** {@inheritDoc} */ 744 public ManagedObjectDefinition<? extends PluginCfgClient, ? extends PluginCfg> definition() { 745 return INSTANCE; 746 } 747 748 749 750 /** {@inheritDoc} */ 751 public PropertyProvider properties() { 752 return impl; 753 } 754 755 756 757 /** {@inheritDoc} */ 758 public void commit() throws ManagedObjectAlreadyExistsException, 759 MissingMandatoryPropertiesException, ConcurrentModificationException, 760 OperationRejectedException, LdapException { 761 impl.commit(); 762 } 763 764 765 766 /** {@inheritDoc} */ 767 public String toString() { 768 return impl.toString(); 769 } 770 } 771 772 773 774 /** 775 * Managed object server implementation. 776 */ 777 private static class PluginCfgServerImpl implements 778 PluginCfg { 779 780 /** Private implementation. */ 781 private ServerManagedObject<? extends PluginCfg> impl; 782 783 /** The value of the "enabled" property. */ 784 private final boolean pEnabled; 785 786 /** The value of the "invoke-for-internal-operations" property. */ 787 private final boolean pInvokeForInternalOperations; 788 789 /** The value of the "java-class" property. */ 790 private final String pJavaClass; 791 792 /** The value of the "plugin-type" property. */ 793 private final SortedSet<PluginType> pPluginType; 794 795 796 797 /** Private constructor. */ 798 private PluginCfgServerImpl(ServerManagedObject<? extends PluginCfg> impl) { 799 this.impl = impl; 800 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 801 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 802 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 803 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 804 } 805 806 807 808 /** {@inheritDoc} */ 809 public void addChangeListener( 810 ConfigurationChangeListener<PluginCfg> listener) { 811 impl.registerChangeListener(listener); 812 } 813 814 815 816 /** {@inheritDoc} */ 817 public void removeChangeListener( 818 ConfigurationChangeListener<PluginCfg> listener) { 819 impl.deregisterChangeListener(listener); 820 } 821 822 823 824 /** {@inheritDoc} */ 825 public boolean isEnabled() { 826 return pEnabled; 827 } 828 829 830 831 /** {@inheritDoc} */ 832 public boolean isInvokeForInternalOperations() { 833 return pInvokeForInternalOperations; 834 } 835 836 837 838 /** {@inheritDoc} */ 839 public String getJavaClass() { 840 return pJavaClass; 841 } 842 843 844 845 /** {@inheritDoc} */ 846 public SortedSet<PluginType> getPluginType() { 847 return pPluginType; 848 } 849 850 851 852 /** {@inheritDoc} */ 853 public Class<? extends PluginCfg> configurationClass() { 854 return PluginCfg.class; 855 } 856 857 858 859 /** {@inheritDoc} */ 860 public DN dn() { 861 return impl.getDN(); 862 } 863 864 865 866 /** {@inheritDoc} */ 867 public String toString() { 868 return impl.toString(); 869 } 870 } 871}