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