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 /** {@inheritDoc} */ 183 public UniqueAttributePluginCfgClient createClientConfiguration( 184 ManagedObject<? extends UniqueAttributePluginCfgClient> impl) { 185 return new UniqueAttributePluginCfgClientImpl(impl); 186 } 187 188 189 190 /** {@inheritDoc} */ 191 public UniqueAttributePluginCfg createServerConfiguration( 192 ServerManagedObject<? extends UniqueAttributePluginCfg> impl) { 193 return new UniqueAttributePluginCfgServerImpl(impl); 194 } 195 196 197 198 /** {@inheritDoc} */ 199 public Class<UniqueAttributePluginCfg> getServerConfigurationClass() { 200 return UniqueAttributePluginCfg.class; 201 } 202 203 204 205 /** 206 * Get the "base-dn" property definition. 207 * <p> 208 * Specifies a base DN within which the attribute must be unique. 209 * 210 * @return Returns the "base-dn" property definition. 211 */ 212 public DNPropertyDefinition getBaseDNPropertyDefinition() { 213 return PD_BASE_DN; 214 } 215 216 217 218 /** 219 * Get the "enabled" property definition. 220 * <p> 221 * Indicates whether the plug-in is enabled for use. 222 * 223 * @return Returns the "enabled" property definition. 224 */ 225 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 226 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition(); 227 } 228 229 230 231 /** 232 * Get the "invoke-for-internal-operations" property definition. 233 * <p> 234 * Indicates whether the plug-in should be invoked for internal 235 * operations. 236 * <p> 237 * Any plug-in that can be invoked for internal operations must 238 * ensure that it does not create any new internal operatons that can 239 * cause the same plug-in to be re-invoked. 240 * 241 * @return Returns the "invoke-for-internal-operations" property definition. 242 */ 243 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 244 return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition(); 245 } 246 247 248 249 /** 250 * Get the "java-class" property definition. 251 * <p> 252 * Specifies the fully-qualified name of the Java class that 253 * provides the plug-in implementation. 254 * 255 * @return Returns the "java-class" property definition. 256 */ 257 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 258 return PD_JAVA_CLASS; 259 } 260 261 262 263 /** 264 * Get the "plugin-type" property definition. 265 * <p> 266 * Specifies the set of plug-in types for the plug-in, which 267 * specifies the times at which the plug-in is invoked. 268 * 269 * @return Returns the "plugin-type" property definition. 270 */ 271 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 272 return PD_PLUGIN_TYPE; 273 } 274 275 276 277 /** 278 * Get the "type" property definition. 279 * <p> 280 * Specifies the type of attributes to check for value uniqueness. 281 * 282 * @return Returns the "type" property definition. 283 */ 284 public AttributeTypePropertyDefinition getTypePropertyDefinition() { 285 return PD_TYPE; 286 } 287 288 289 290 /** 291 * Managed object client implementation. 292 */ 293 private static class UniqueAttributePluginCfgClientImpl implements 294 UniqueAttributePluginCfgClient { 295 296 /** Private implementation. */ 297 private ManagedObject<? extends UniqueAttributePluginCfgClient> impl; 298 299 300 301 /** Private constructor. */ 302 private UniqueAttributePluginCfgClientImpl( 303 ManagedObject<? extends UniqueAttributePluginCfgClient> impl) { 304 this.impl = impl; 305 } 306 307 308 309 /** {@inheritDoc} */ 310 public SortedSet<DN> getBaseDN() { 311 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 312 } 313 314 315 316 /** {@inheritDoc} */ 317 public void setBaseDN(Collection<DN> values) { 318 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 319 } 320 321 322 323 /** {@inheritDoc} */ 324 public Boolean isEnabled() { 325 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 326 } 327 328 329 330 /** {@inheritDoc} */ 331 public void setEnabled(boolean value) { 332 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 333 } 334 335 336 337 /** {@inheritDoc} */ 338 public boolean isInvokeForInternalOperations() { 339 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 340 } 341 342 343 344 /** {@inheritDoc} */ 345 public void setInvokeForInternalOperations(Boolean value) { 346 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 347 } 348 349 350 351 /** {@inheritDoc} */ 352 public String getJavaClass() { 353 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 354 } 355 356 357 358 /** {@inheritDoc} */ 359 public void setJavaClass(String value) { 360 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 361 } 362 363 364 365 /** {@inheritDoc} */ 366 public SortedSet<PluginType> getPluginType() { 367 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 368 } 369 370 371 372 /** {@inheritDoc} */ 373 public void setPluginType(Collection<PluginType> values) { 374 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 375 } 376 377 378 379 /** {@inheritDoc} */ 380 public SortedSet<AttributeType> getType() { 381 return impl.getPropertyValues(INSTANCE.getTypePropertyDefinition()); 382 } 383 384 385 386 /** {@inheritDoc} */ 387 public void setType(Collection<AttributeType> values) { 388 impl.setPropertyValues(INSTANCE.getTypePropertyDefinition(), values); 389 } 390 391 392 393 /** {@inheritDoc} */ 394 public ManagedObjectDefinition<? extends UniqueAttributePluginCfgClient, ? extends UniqueAttributePluginCfg> definition() { 395 return INSTANCE; 396 } 397 398 399 400 /** {@inheritDoc} */ 401 public PropertyProvider properties() { 402 return impl; 403 } 404 405 406 407 /** {@inheritDoc} */ 408 public void commit() throws ManagedObjectAlreadyExistsException, 409 MissingMandatoryPropertiesException, ConcurrentModificationException, 410 OperationRejectedException, LdapException { 411 impl.commit(); 412 } 413 414 415 416 /** {@inheritDoc} */ 417 public String toString() { 418 return impl.toString(); 419 } 420 } 421 422 423 424 /** 425 * Managed object server implementation. 426 */ 427 private static class UniqueAttributePluginCfgServerImpl implements 428 UniqueAttributePluginCfg { 429 430 /** Private implementation. */ 431 private ServerManagedObject<? extends UniqueAttributePluginCfg> impl; 432 433 /** The value of the "base-dn" property. */ 434 private final SortedSet<DN> pBaseDN; 435 436 /** The value of the "enabled" property. */ 437 private final boolean pEnabled; 438 439 /** The value of the "invoke-for-internal-operations" property. */ 440 private final boolean pInvokeForInternalOperations; 441 442 /** The value of the "java-class" property. */ 443 private final String pJavaClass; 444 445 /** The value of the "plugin-type" property. */ 446 private final SortedSet<PluginType> pPluginType; 447 448 /** The value of the "type" property. */ 449 private final SortedSet<AttributeType> pType; 450 451 452 453 /** Private constructor. */ 454 private UniqueAttributePluginCfgServerImpl(ServerManagedObject<? extends UniqueAttributePluginCfg> impl) { 455 this.impl = impl; 456 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 457 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 458 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 459 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 460 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 461 this.pType = impl.getPropertyValues(INSTANCE.getTypePropertyDefinition()); 462 } 463 464 465 466 /** {@inheritDoc} */ 467 public void addUniqueAttributeChangeListener( 468 ConfigurationChangeListener<UniqueAttributePluginCfg> listener) { 469 impl.registerChangeListener(listener); 470 } 471 472 473 474 /** {@inheritDoc} */ 475 public void removeUniqueAttributeChangeListener( 476 ConfigurationChangeListener<UniqueAttributePluginCfg> listener) { 477 impl.deregisterChangeListener(listener); 478 } 479 /** {@inheritDoc} */ 480 public void addChangeListener( 481 ConfigurationChangeListener<PluginCfg> listener) { 482 impl.registerChangeListener(listener); 483 } 484 485 486 487 /** {@inheritDoc} */ 488 public void removeChangeListener( 489 ConfigurationChangeListener<PluginCfg> listener) { 490 impl.deregisterChangeListener(listener); 491 } 492 493 494 495 /** {@inheritDoc} */ 496 public SortedSet<DN> getBaseDN() { 497 return pBaseDN; 498 } 499 500 501 502 /** {@inheritDoc} */ 503 public boolean isEnabled() { 504 return pEnabled; 505 } 506 507 508 509 /** {@inheritDoc} */ 510 public boolean isInvokeForInternalOperations() { 511 return pInvokeForInternalOperations; 512 } 513 514 515 516 /** {@inheritDoc} */ 517 public String getJavaClass() { 518 return pJavaClass; 519 } 520 521 522 523 /** {@inheritDoc} */ 524 public SortedSet<PluginType> getPluginType() { 525 return pPluginType; 526 } 527 528 529 530 /** {@inheritDoc} */ 531 public SortedSet<AttributeType> getType() { 532 return pType; 533 } 534 535 536 537 /** {@inheritDoc} */ 538 public Class<? extends UniqueAttributePluginCfg> configurationClass() { 539 return UniqueAttributePluginCfg.class; 540 } 541 542 543 544 /** {@inheritDoc} */ 545 public DN dn() { 546 return impl.getDN(); 547 } 548 549 550 551 /** {@inheritDoc} */ 552 public String toString() { 553 return impl.toString(); 554 } 555 } 556}