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.BooleanPropertyDefinition; 025import org.forgerock.opendj.config.client.ConcurrentModificationException; 026import org.forgerock.opendj.config.client.ManagedObject; 027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 028import org.forgerock.opendj.config.client.OperationRejectedException; 029import org.forgerock.opendj.config.DefaultBehaviorProvider; 030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 031import org.forgerock.opendj.config.DNPropertyDefinition; 032import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 033import org.forgerock.opendj.config.ManagedObjectDefinition; 034import org.forgerock.opendj.config.ManagedObjectOption; 035import org.forgerock.opendj.config.PropertyOption; 036import org.forgerock.opendj.config.PropertyProvider; 037import org.forgerock.opendj.config.server.ConfigurationChangeListener; 038import org.forgerock.opendj.config.server.ServerManagedObject; 039import org.forgerock.opendj.config.Tag; 040import org.forgerock.opendj.config.TopCfgDefn; 041import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.ldap.DN; 043import org.forgerock.opendj.ldap.LdapException; 044import org.forgerock.opendj.server.config.client.RootDSEBackendCfgClient; 045import org.forgerock.opendj.server.config.server.RootDSEBackendCfg; 046 047 048 049/** 050 * An interface for querying the Root DSE Backend managed object 051 * definition meta information. 052 * <p> 053 * The Root DSE Backend contains the directory server root DSE. 054 */ 055public final class RootDSEBackendCfgDefn extends ManagedObjectDefinition<RootDSEBackendCfgClient, RootDSEBackendCfg> { 056 057 /** The singleton configuration definition instance. */ 058 private static final RootDSEBackendCfgDefn INSTANCE = new RootDSEBackendCfgDefn(); 059 060 061 062 /** The "show-all-attributes" property definition. */ 063 private static final BooleanPropertyDefinition PD_SHOW_ALL_ATTRIBUTES; 064 065 066 067 /** The "show-subordinate-naming-contexts" property definition. */ 068 private static final BooleanPropertyDefinition PD_SHOW_SUBORDINATE_NAMING_CONTEXTS; 069 070 071 072 /** The "subordinate-base-dn" property definition. */ 073 private static final DNPropertyDefinition PD_SUBORDINATE_BASE_DN; 074 075 076 077 /** Build the "show-all-attributes" property definition. */ 078 static { 079 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "show-all-attributes"); 080 builder.setOption(PropertyOption.MANDATORY); 081 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "show-all-attributes")); 082 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 083 PD_SHOW_ALL_ATTRIBUTES = builder.getInstance(); 084 INSTANCE.registerPropertyDefinition(PD_SHOW_ALL_ATTRIBUTES); 085 } 086 087 088 089 /** Build the "show-subordinate-naming-contexts" property definition. */ 090 static { 091 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "show-subordinate-naming-contexts"); 092 builder.setOption(PropertyOption.MANDATORY); 093 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "show-subordinate-naming-contexts")); 094 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 095 builder.setDefaultBehaviorProvider(provider); 096 PD_SHOW_SUBORDINATE_NAMING_CONTEXTS = builder.getInstance(); 097 INSTANCE.registerPropertyDefinition(PD_SHOW_SUBORDINATE_NAMING_CONTEXTS); 098 } 099 100 101 102 /** Build the "subordinate-base-dn" property definition. */ 103 static { 104 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "subordinate-base-dn"); 105 builder.setOption(PropertyOption.MULTI_VALUED); 106 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "subordinate-base-dn")); 107 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "subordinate-base-dn")); 108 PD_SUBORDINATE_BASE_DN = builder.getInstance(); 109 INSTANCE.registerPropertyDefinition(PD_SUBORDINATE_BASE_DN); 110 } 111 112 113 114 // Register the options associated with this managed object definition. 115 static { 116 INSTANCE.registerOption(ManagedObjectOption.ADVANCED); 117 } 118 119 120 121 // Register the tags associated with this managed object definition. 122 static { 123 INSTANCE.registerTag(Tag.valueOf("core-server")); 124 INSTANCE.registerTag(Tag.valueOf("database")); 125 } 126 127 128 129 /** 130 * Get the Root DSE Backend configuration definition singleton. 131 * 132 * @return Returns the Root DSE Backend configuration definition 133 * singleton. 134 */ 135 public static RootDSEBackendCfgDefn getInstance() { 136 return INSTANCE; 137 } 138 139 140 141 /** 142 * Private constructor. 143 */ 144 private RootDSEBackendCfgDefn() { 145 super("root-dse-backend", TopCfgDefn.getInstance()); 146 } 147 148 149 150 /** {@inheritDoc} */ 151 public RootDSEBackendCfgClient createClientConfiguration( 152 ManagedObject<? extends RootDSEBackendCfgClient> impl) { 153 return new RootDSEBackendCfgClientImpl(impl); 154 } 155 156 157 158 /** {@inheritDoc} */ 159 public RootDSEBackendCfg createServerConfiguration( 160 ServerManagedObject<? extends RootDSEBackendCfg> impl) { 161 return new RootDSEBackendCfgServerImpl(impl); 162 } 163 164 165 166 /** {@inheritDoc} */ 167 public Class<RootDSEBackendCfg> getServerConfigurationClass() { 168 return RootDSEBackendCfg.class; 169 } 170 171 172 173 /** 174 * Get the "show-all-attributes" property definition. 175 * <p> 176 * Indicates whether all attributes in the root DSE are to be 177 * treated like user attributes (and therefore returned to clients by 178 * default) regardless of the directory server schema configuration. 179 * 180 * @return Returns the "show-all-attributes" property definition. 181 */ 182 public BooleanPropertyDefinition getShowAllAttributesPropertyDefinition() { 183 return PD_SHOW_ALL_ATTRIBUTES; 184 } 185 186 187 188 /** 189 * Get the "show-subordinate-naming-contexts" property definition. 190 * <p> 191 * Indicates whether subordinate naming contexts should be visible 192 * in the namingContexts attribute of the RootDSE. By default only 193 * top level naming contexts are visible 194 * 195 * @return Returns the "show-subordinate-naming-contexts" property definition. 196 */ 197 public BooleanPropertyDefinition getShowSubordinateNamingContextsPropertyDefinition() { 198 return PD_SHOW_SUBORDINATE_NAMING_CONTEXTS; 199 } 200 201 202 203 /** 204 * Get the "subordinate-base-dn" property definition. 205 * <p> 206 * Specifies the set of base DNs used for singleLevel, wholeSubtree, 207 * and subordinateSubtree searches based at the root DSE. 208 * 209 * @return Returns the "subordinate-base-dn" property definition. 210 */ 211 public DNPropertyDefinition getSubordinateBaseDNPropertyDefinition() { 212 return PD_SUBORDINATE_BASE_DN; 213 } 214 215 216 217 /** 218 * Managed object client implementation. 219 */ 220 private static class RootDSEBackendCfgClientImpl implements 221 RootDSEBackendCfgClient { 222 223 /** Private implementation. */ 224 private ManagedObject<? extends RootDSEBackendCfgClient> impl; 225 226 227 228 /** Private constructor. */ 229 private RootDSEBackendCfgClientImpl( 230 ManagedObject<? extends RootDSEBackendCfgClient> impl) { 231 this.impl = impl; 232 } 233 234 235 236 /** {@inheritDoc} */ 237 public Boolean isShowAllAttributes() { 238 return impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition()); 239 } 240 241 242 243 /** {@inheritDoc} */ 244 public void setShowAllAttributes(boolean value) { 245 impl.setPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition(), value); 246 } 247 248 249 250 /** {@inheritDoc} */ 251 public boolean isShowSubordinateNamingContexts() { 252 return impl.getPropertyValue(INSTANCE.getShowSubordinateNamingContextsPropertyDefinition()); 253 } 254 255 256 257 /** {@inheritDoc} */ 258 public void setShowSubordinateNamingContexts(boolean value) { 259 impl.setPropertyValue(INSTANCE.getShowSubordinateNamingContextsPropertyDefinition(), value); 260 } 261 262 263 264 /** {@inheritDoc} */ 265 public SortedSet<DN> getSubordinateBaseDN() { 266 return impl.getPropertyValues(INSTANCE.getSubordinateBaseDNPropertyDefinition()); 267 } 268 269 270 271 /** {@inheritDoc} */ 272 public void setSubordinateBaseDN(Collection<DN> values) { 273 impl.setPropertyValues(INSTANCE.getSubordinateBaseDNPropertyDefinition(), values); 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public ManagedObjectDefinition<? extends RootDSEBackendCfgClient, ? extends RootDSEBackendCfg> definition() { 280 return INSTANCE; 281 } 282 283 284 285 /** {@inheritDoc} */ 286 public PropertyProvider properties() { 287 return impl; 288 } 289 290 291 292 /** {@inheritDoc} */ 293 public void commit() throws ManagedObjectAlreadyExistsException, 294 MissingMandatoryPropertiesException, ConcurrentModificationException, 295 OperationRejectedException, LdapException { 296 impl.commit(); 297 } 298 299 300 301 /** {@inheritDoc} */ 302 public String toString() { 303 return impl.toString(); 304 } 305 } 306 307 308 309 /** 310 * Managed object server implementation. 311 */ 312 private static class RootDSEBackendCfgServerImpl implements 313 RootDSEBackendCfg { 314 315 /** Private implementation. */ 316 private ServerManagedObject<? extends RootDSEBackendCfg> impl; 317 318 /** The value of the "show-all-attributes" property. */ 319 private final boolean pShowAllAttributes; 320 321 /** The value of the "show-subordinate-naming-contexts" property. */ 322 private final boolean pShowSubordinateNamingContexts; 323 324 /** The value of the "subordinate-base-dn" property. */ 325 private final SortedSet<DN> pSubordinateBaseDN; 326 327 328 329 /** Private constructor. */ 330 private RootDSEBackendCfgServerImpl(ServerManagedObject<? extends RootDSEBackendCfg> impl) { 331 this.impl = impl; 332 this.pShowAllAttributes = impl.getPropertyValue(INSTANCE.getShowAllAttributesPropertyDefinition()); 333 this.pShowSubordinateNamingContexts = impl.getPropertyValue(INSTANCE.getShowSubordinateNamingContextsPropertyDefinition()); 334 this.pSubordinateBaseDN = impl.getPropertyValues(INSTANCE.getSubordinateBaseDNPropertyDefinition()); 335 } 336 337 338 339 /** {@inheritDoc} */ 340 public void addChangeListener( 341 ConfigurationChangeListener<RootDSEBackendCfg> listener) { 342 impl.registerChangeListener(listener); 343 } 344 345 346 347 /** {@inheritDoc} */ 348 public void removeChangeListener( 349 ConfigurationChangeListener<RootDSEBackendCfg> listener) { 350 impl.deregisterChangeListener(listener); 351 } 352 353 354 355 /** {@inheritDoc} */ 356 public boolean isShowAllAttributes() { 357 return pShowAllAttributes; 358 } 359 360 361 362 /** {@inheritDoc} */ 363 public boolean isShowSubordinateNamingContexts() { 364 return pShowSubordinateNamingContexts; 365 } 366 367 368 369 /** {@inheritDoc} */ 370 public SortedSet<DN> getSubordinateBaseDN() { 371 return pSubordinateBaseDN; 372 } 373 374 375 376 /** {@inheritDoc} */ 377 public Class<? extends RootDSEBackendCfg> configurationClass() { 378 return RootDSEBackendCfg.class; 379 } 380 381 382 383 /** {@inheritDoc} */ 384 public DN dn() { 385 return impl.getDN(); 386 } 387 388 389 390 /** {@inheritDoc} */ 391 public String toString() { 392 return impl.toString(); 393 } 394 } 395}