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.AliasDefaultBehaviorProvider; 034import org.forgerock.opendj.config.BooleanPropertyDefinition; 035import org.forgerock.opendj.config.ClassPropertyDefinition; 036import org.forgerock.opendj.config.client.ConcurrentModificationException; 037import org.forgerock.opendj.config.client.ManagedObject; 038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 039import org.forgerock.opendj.config.client.OperationRejectedException; 040import org.forgerock.opendj.config.DefaultBehaviorProvider; 041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.config.EnumPropertyDefinition; 043import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 044import org.forgerock.opendj.config.ManagedObjectDefinition; 045import org.forgerock.opendj.config.PropertyOption; 046import org.forgerock.opendj.config.PropertyProvider; 047import org.forgerock.opendj.config.server.ConfigurationChangeListener; 048import org.forgerock.opendj.config.server.ServerManagedObject; 049import org.forgerock.opendj.config.StringPropertyDefinition; 050import org.forgerock.opendj.config.Tag; 051import org.forgerock.opendj.ldap.DN; 052import org.forgerock.opendj.ldap.LdapException; 053import org.forgerock.opendj.server.config.client.AttributeCleanupPluginCfgClient; 054import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType; 055import org.forgerock.opendj.server.config.server.AttributeCleanupPluginCfg; 056import org.forgerock.opendj.server.config.server.PluginCfg; 057 058 059 060/** 061 * An interface for querying the Attribute Cleanup Plugin managed 062 * object definition meta information. 063 * <p> 064 * A pre-parse plugin which can be used to remove and rename 065 * attributes in ADD and MODIFY requests before being processed. 066 */ 067public final class AttributeCleanupPluginCfgDefn extends ManagedObjectDefinition<AttributeCleanupPluginCfgClient, AttributeCleanupPluginCfg> { 068 069 // The singleton configuration definition instance. 070 private static final AttributeCleanupPluginCfgDefn INSTANCE = new AttributeCleanupPluginCfgDefn(); 071 072 073 074 // The "invoke-for-internal-operations" property definition. 075 private static final BooleanPropertyDefinition PD_INVOKE_FOR_INTERNAL_OPERATIONS; 076 077 078 079 // The "java-class" property definition. 080 private static final ClassPropertyDefinition PD_JAVA_CLASS; 081 082 083 084 // The "plugin-type" property definition. 085 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE; 086 087 088 089 // The "remove-inbound-attributes" property definition. 090 private static final StringPropertyDefinition PD_REMOVE_INBOUND_ATTRIBUTES; 091 092 093 094 // The "rename-inbound-attributes" property definition. 095 private static final StringPropertyDefinition PD_RENAME_INBOUND_ATTRIBUTES; 096 097 098 099 // Build the "invoke-for-internal-operations" property definition. 100 static { 101 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "invoke-for-internal-operations"); 102 builder.setOption(PropertyOption.ADVANCED); 103 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "invoke-for-internal-operations")); 104 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 105 builder.setDefaultBehaviorProvider(provider); 106 PD_INVOKE_FOR_INTERNAL_OPERATIONS = builder.getInstance(); 107 INSTANCE.registerPropertyDefinition(PD_INVOKE_FOR_INTERNAL_OPERATIONS); 108 } 109 110 111 112 // Build the "java-class" property definition. 113 static { 114 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 115 builder.setOption(PropertyOption.MANDATORY); 116 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 117 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.AttributeCleanupPlugin"); 118 builder.setDefaultBehaviorProvider(provider); 119 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin"); 120 PD_JAVA_CLASS = builder.getInstance(); 121 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 122 } 123 124 125 126 // Build the "plugin-type" property definition. 127 static { 128 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type"); 129 builder.setOption(PropertyOption.MULTI_VALUED); 130 builder.setOption(PropertyOption.MANDATORY); 131 builder.setOption(PropertyOption.ADVANCED); 132 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type")); 133 DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preparseadd", "preparsemodify"); 134 builder.setDefaultBehaviorProvider(provider); 135 builder.setEnumClass(PluginType.class); 136 PD_PLUGIN_TYPE = builder.getInstance(); 137 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE); 138 } 139 140 141 142 // Build the "remove-inbound-attributes" property definition. 143 static { 144 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "remove-inbound-attributes"); 145 builder.setOption(PropertyOption.MULTI_VALUED); 146 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "remove-inbound-attributes")); 147 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "remove-inbound-attributes")); 148 PD_REMOVE_INBOUND_ATTRIBUTES = builder.getInstance(); 149 INSTANCE.registerPropertyDefinition(PD_REMOVE_INBOUND_ATTRIBUTES); 150 } 151 152 153 154 // Build the "rename-inbound-attributes" property definition. 155 static { 156 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "rename-inbound-attributes"); 157 builder.setOption(PropertyOption.MULTI_VALUED); 158 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "rename-inbound-attributes")); 159 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "rename-inbound-attributes")); 160 builder.setPattern("^[^:]+:[^:]+$", "FROM:TO"); 161 PD_RENAME_INBOUND_ATTRIBUTES = builder.getInstance(); 162 INSTANCE.registerPropertyDefinition(PD_RENAME_INBOUND_ATTRIBUTES); 163 } 164 165 166 167 // Register the tags associated with this managed object definition. 168 static { 169 INSTANCE.registerTag(Tag.valueOf("core-server")); 170 } 171 172 173 174 /** 175 * Get the Attribute Cleanup Plugin configuration definition 176 * singleton. 177 * 178 * @return Returns the Attribute Cleanup Plugin configuration 179 * definition singleton. 180 */ 181 public static AttributeCleanupPluginCfgDefn getInstance() { 182 return INSTANCE; 183 } 184 185 186 187 /** 188 * Private constructor. 189 */ 190 private AttributeCleanupPluginCfgDefn() { 191 super("attribute-cleanup-plugin", PluginCfgDefn.getInstance()); 192 } 193 194 195 196 /** 197 * {@inheritDoc} 198 */ 199 public AttributeCleanupPluginCfgClient createClientConfiguration( 200 ManagedObject<? extends AttributeCleanupPluginCfgClient> impl) { 201 return new AttributeCleanupPluginCfgClientImpl(impl); 202 } 203 204 205 206 /** 207 * {@inheritDoc} 208 */ 209 public AttributeCleanupPluginCfg createServerConfiguration( 210 ServerManagedObject<? extends AttributeCleanupPluginCfg> impl) { 211 return new AttributeCleanupPluginCfgServerImpl(impl); 212 } 213 214 215 216 /** 217 * {@inheritDoc} 218 */ 219 public Class<AttributeCleanupPluginCfg> getServerConfigurationClass() { 220 return AttributeCleanupPluginCfg.class; 221 } 222 223 224 225 /** 226 * Get the "enabled" property definition. 227 * <p> 228 * Indicates whether the plug-in is enabled for use. 229 * 230 * @return Returns the "enabled" property definition. 231 */ 232 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 233 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition(); 234 } 235 236 237 238 /** 239 * Get the "invoke-for-internal-operations" property definition. 240 * <p> 241 * Indicates whether the plug-in should be invoked for internal 242 * operations. 243 * <p> 244 * Any plug-in that can be invoked for internal operations must 245 * ensure that it does not create any new internal operatons that can 246 * cause the same plug-in to be re-invoked. 247 * 248 * @return Returns the "invoke-for-internal-operations" property definition. 249 */ 250 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 251 return PD_INVOKE_FOR_INTERNAL_OPERATIONS; 252 } 253 254 255 256 /** 257 * Get the "java-class" property definition. 258 * <p> 259 * Specifies the fully-qualified name of the Java class that 260 * provides the plug-in implementation. 261 * 262 * @return Returns the "java-class" property definition. 263 */ 264 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 265 return PD_JAVA_CLASS; 266 } 267 268 269 270 /** 271 * Get the "plugin-type" property definition. 272 * <p> 273 * Specifies the set of plug-in types for the plug-in, which 274 * specifies the times at which the plug-in is invoked. 275 * 276 * @return Returns the "plugin-type" property definition. 277 */ 278 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 279 return PD_PLUGIN_TYPE; 280 } 281 282 283 284 /** 285 * Get the "remove-inbound-attributes" property definition. 286 * <p> 287 * A list of attributes which should be removed from incoming add or 288 * modify requests. 289 * 290 * @return Returns the "remove-inbound-attributes" property definition. 291 */ 292 public StringPropertyDefinition getRemoveInboundAttributesPropertyDefinition() { 293 return PD_REMOVE_INBOUND_ATTRIBUTES; 294 } 295 296 297 298 /** 299 * Get the "rename-inbound-attributes" property definition. 300 * <p> 301 * A list of attributes which should be renamed in incoming add or 302 * modify requests. 303 * 304 * @return Returns the "rename-inbound-attributes" property definition. 305 */ 306 public StringPropertyDefinition getRenameInboundAttributesPropertyDefinition() { 307 return PD_RENAME_INBOUND_ATTRIBUTES; 308 } 309 310 311 312 /** 313 * Managed object client implementation. 314 */ 315 private static class AttributeCleanupPluginCfgClientImpl implements 316 AttributeCleanupPluginCfgClient { 317 318 // Private implementation. 319 private ManagedObject<? extends AttributeCleanupPluginCfgClient> impl; 320 321 322 323 // Private constructor. 324 private AttributeCleanupPluginCfgClientImpl( 325 ManagedObject<? extends AttributeCleanupPluginCfgClient> impl) { 326 this.impl = impl; 327 } 328 329 330 331 /** 332 * {@inheritDoc} 333 */ 334 public Boolean isEnabled() { 335 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 336 } 337 338 339 340 /** 341 * {@inheritDoc} 342 */ 343 public void setEnabled(boolean value) { 344 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 345 } 346 347 348 349 /** 350 * {@inheritDoc} 351 */ 352 public boolean isInvokeForInternalOperations() { 353 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 354 } 355 356 357 358 /** 359 * {@inheritDoc} 360 */ 361 public void setInvokeForInternalOperations(Boolean value) { 362 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 363 } 364 365 366 367 /** 368 * {@inheritDoc} 369 */ 370 public String getJavaClass() { 371 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 372 } 373 374 375 376 /** 377 * {@inheritDoc} 378 */ 379 public void setJavaClass(String value) { 380 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 381 } 382 383 384 385 /** 386 * {@inheritDoc} 387 */ 388 public SortedSet<PluginType> getPluginType() { 389 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 390 } 391 392 393 394 /** 395 * {@inheritDoc} 396 */ 397 public void setPluginType(Collection<PluginType> values) { 398 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 399 } 400 401 402 403 /** 404 * {@inheritDoc} 405 */ 406 public SortedSet<String> getRemoveInboundAttributes() { 407 return impl.getPropertyValues(INSTANCE.getRemoveInboundAttributesPropertyDefinition()); 408 } 409 410 411 412 /** 413 * {@inheritDoc} 414 */ 415 public void setRemoveInboundAttributes(Collection<String> values) { 416 impl.setPropertyValues(INSTANCE.getRemoveInboundAttributesPropertyDefinition(), values); 417 } 418 419 420 421 /** 422 * {@inheritDoc} 423 */ 424 public SortedSet<String> getRenameInboundAttributes() { 425 return impl.getPropertyValues(INSTANCE.getRenameInboundAttributesPropertyDefinition()); 426 } 427 428 429 430 /** 431 * {@inheritDoc} 432 */ 433 public void setRenameInboundAttributes(Collection<String> values) { 434 impl.setPropertyValues(INSTANCE.getRenameInboundAttributesPropertyDefinition(), values); 435 } 436 437 438 439 /** 440 * {@inheritDoc} 441 */ 442 public ManagedObjectDefinition<? extends AttributeCleanupPluginCfgClient, ? extends AttributeCleanupPluginCfg> definition() { 443 return INSTANCE; 444 } 445 446 447 448 /** 449 * {@inheritDoc} 450 */ 451 public PropertyProvider properties() { 452 return impl; 453 } 454 455 456 457 /** 458 * {@inheritDoc} 459 */ 460 public void commit() throws ManagedObjectAlreadyExistsException, 461 MissingMandatoryPropertiesException, ConcurrentModificationException, 462 OperationRejectedException, LdapException { 463 impl.commit(); 464 } 465 466 } 467 468 469 470 /** 471 * Managed object server implementation. 472 */ 473 private static class AttributeCleanupPluginCfgServerImpl implements 474 AttributeCleanupPluginCfg { 475 476 // Private implementation. 477 private ServerManagedObject<? extends AttributeCleanupPluginCfg> impl; 478 479 // The value of the "enabled" property. 480 private final boolean pEnabled; 481 482 // The value of the "invoke-for-internal-operations" property. 483 private final boolean pInvokeForInternalOperations; 484 485 // The value of the "java-class" property. 486 private final String pJavaClass; 487 488 // The value of the "plugin-type" property. 489 private final SortedSet<PluginType> pPluginType; 490 491 // The value of the "remove-inbound-attributes" property. 492 private final SortedSet<String> pRemoveInboundAttributes; 493 494 // The value of the "rename-inbound-attributes" property. 495 private final SortedSet<String> pRenameInboundAttributes; 496 497 498 499 // Private constructor. 500 private AttributeCleanupPluginCfgServerImpl(ServerManagedObject<? extends AttributeCleanupPluginCfg> impl) { 501 this.impl = impl; 502 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 503 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 504 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 505 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 506 this.pRemoveInboundAttributes = impl.getPropertyValues(INSTANCE.getRemoveInboundAttributesPropertyDefinition()); 507 this.pRenameInboundAttributes = impl.getPropertyValues(INSTANCE.getRenameInboundAttributesPropertyDefinition()); 508 } 509 510 511 512 /** 513 * {@inheritDoc} 514 */ 515 public void addAttributeCleanupChangeListener( 516 ConfigurationChangeListener<AttributeCleanupPluginCfg> listener) { 517 impl.registerChangeListener(listener); 518 } 519 520 521 522 /** 523 * {@inheritDoc} 524 */ 525 public void removeAttributeCleanupChangeListener( 526 ConfigurationChangeListener<AttributeCleanupPluginCfg> listener) { 527 impl.deregisterChangeListener(listener); 528 } 529 /** 530 * {@inheritDoc} 531 */ 532 public void addChangeListener( 533 ConfigurationChangeListener<PluginCfg> listener) { 534 impl.registerChangeListener(listener); 535 } 536 537 538 539 /** 540 * {@inheritDoc} 541 */ 542 public void removeChangeListener( 543 ConfigurationChangeListener<PluginCfg> listener) { 544 impl.deregisterChangeListener(listener); 545 } 546 547 548 549 /** 550 * {@inheritDoc} 551 */ 552 public boolean isEnabled() { 553 return pEnabled; 554 } 555 556 557 558 /** 559 * {@inheritDoc} 560 */ 561 public boolean isInvokeForInternalOperations() { 562 return pInvokeForInternalOperations; 563 } 564 565 566 567 /** 568 * {@inheritDoc} 569 */ 570 public String getJavaClass() { 571 return pJavaClass; 572 } 573 574 575 576 /** 577 * {@inheritDoc} 578 */ 579 public SortedSet<PluginType> getPluginType() { 580 return pPluginType; 581 } 582 583 584 585 /** 586 * {@inheritDoc} 587 */ 588 public SortedSet<String> getRemoveInboundAttributes() { 589 return pRemoveInboundAttributes; 590 } 591 592 593 594 /** 595 * {@inheritDoc} 596 */ 597 public SortedSet<String> getRenameInboundAttributes() { 598 return pRenameInboundAttributes; 599 } 600 601 602 603 /** 604 * {@inheritDoc} 605 */ 606 public Class<? extends AttributeCleanupPluginCfg> configurationClass() { 607 return AttributeCleanupPluginCfg.class; 608 } 609 610 611 612 /** 613 * {@inheritDoc} 614 */ 615 public DN dn() { 616 return impl.getDN(); 617 } 618 619 } 620}