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