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