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