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