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.client.ConcurrentModificationException; 035import org.forgerock.opendj.config.client.ManagedObject; 036import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 037import org.forgerock.opendj.config.client.OperationRejectedException; 038import org.forgerock.opendj.config.DNPropertyDefinition; 039import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 040import org.forgerock.opendj.config.ManagedObjectDefinition; 041import org.forgerock.opendj.config.PropertyOption; 042import org.forgerock.opendj.config.PropertyProvider; 043import org.forgerock.opendj.config.server.ConfigurationChangeListener; 044import org.forgerock.opendj.config.server.ServerManagedObject; 045import org.forgerock.opendj.config.Tag; 046import org.forgerock.opendj.config.TopCfgDefn; 047import org.forgerock.opendj.ldap.DN; 048import org.forgerock.opendj.ldap.LdapException; 049import org.forgerock.opendj.server.config.client.RootDNUserCfgClient; 050import org.forgerock.opendj.server.config.server.RootDNUserCfg; 051 052 053 054/** 055 * An interface for querying the Root DN User managed object 056 * definition meta information. 057 * <p> 058 * A Root DN User are administrative users who can granted special 059 * privileges that are not available to non-root users (for example, 060 * the ability to bind to the server in lockdown mode). 061 */ 062public final class RootDNUserCfgDefn extends ManagedObjectDefinition<RootDNUserCfgClient, RootDNUserCfg> { 063 064 /** The singleton configuration definition instance. */ 065 private static final RootDNUserCfgDefn INSTANCE = new RootDNUserCfgDefn(); 066 067 068 069 /** The "alternate-bind-dn" property definition. */ 070 private static final DNPropertyDefinition PD_ALTERNATE_BIND_DN; 071 072 073 074 /** Build the "alternate-bind-dn" property definition. */ 075 static { 076 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "alternate-bind-dn"); 077 builder.setOption(PropertyOption.MULTI_VALUED); 078 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "alternate-bind-dn")); 079 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "alternate-bind-dn")); 080 PD_ALTERNATE_BIND_DN = builder.getInstance(); 081 INSTANCE.registerPropertyDefinition(PD_ALTERNATE_BIND_DN); 082 } 083 084 085 086 // Register the tags associated with this managed object definition. 087 static { 088 INSTANCE.registerTag(Tag.valueOf("core-server")); 089 } 090 091 092 093 /** 094 * Get the Root DN User configuration definition singleton. 095 * 096 * @return Returns the Root DN User configuration definition 097 * singleton. 098 */ 099 public static RootDNUserCfgDefn getInstance() { 100 return INSTANCE; 101 } 102 103 104 105 /** 106 * Private constructor. 107 */ 108 private RootDNUserCfgDefn() { 109 super("root-dn-user", TopCfgDefn.getInstance()); 110 } 111 112 113 114 /** {@inheritDoc} */ 115 public RootDNUserCfgClient createClientConfiguration( 116 ManagedObject<? extends RootDNUserCfgClient> impl) { 117 return new RootDNUserCfgClientImpl(impl); 118 } 119 120 121 122 /** {@inheritDoc} */ 123 public RootDNUserCfg createServerConfiguration( 124 ServerManagedObject<? extends RootDNUserCfg> impl) { 125 return new RootDNUserCfgServerImpl(impl); 126 } 127 128 129 130 /** {@inheritDoc} */ 131 public Class<RootDNUserCfg> getServerConfigurationClass() { 132 return RootDNUserCfg.class; 133 } 134 135 136 137 /** 138 * Get the "alternate-bind-dn" property definition. 139 * <p> 140 * Specifies one or more alternate DNs that can be used to bind to 141 * the server as this root user. 142 * 143 * @return Returns the "alternate-bind-dn" property definition. 144 */ 145 public DNPropertyDefinition getAlternateBindDNPropertyDefinition() { 146 return PD_ALTERNATE_BIND_DN; 147 } 148 149 150 151 /** 152 * Managed object client implementation. 153 */ 154 private static class RootDNUserCfgClientImpl implements 155 RootDNUserCfgClient { 156 157 /** Private implementation. */ 158 private ManagedObject<? extends RootDNUserCfgClient> impl; 159 160 161 162 /** Private constructor. */ 163 private RootDNUserCfgClientImpl( 164 ManagedObject<? extends RootDNUserCfgClient> impl) { 165 this.impl = impl; 166 } 167 168 169 170 /** {@inheritDoc} */ 171 public SortedSet<DN> getAlternateBindDN() { 172 return impl.getPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition()); 173 } 174 175 176 177 /** {@inheritDoc} */ 178 public void setAlternateBindDN(Collection<DN> values) { 179 impl.setPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition(), values); 180 } 181 182 183 184 /** {@inheritDoc} */ 185 public ManagedObjectDefinition<? extends RootDNUserCfgClient, ? extends RootDNUserCfg> definition() { 186 return INSTANCE; 187 } 188 189 190 191 /** {@inheritDoc} */ 192 public PropertyProvider properties() { 193 return impl; 194 } 195 196 197 198 /** {@inheritDoc} */ 199 public void commit() throws ManagedObjectAlreadyExistsException, 200 MissingMandatoryPropertiesException, ConcurrentModificationException, 201 OperationRejectedException, LdapException { 202 impl.commit(); 203 } 204 205 206 207 /** {@inheritDoc} */ 208 public String toString() { 209 return impl.toString(); 210 } 211 } 212 213 214 215 /** 216 * Managed object server implementation. 217 */ 218 private static class RootDNUserCfgServerImpl implements 219 RootDNUserCfg { 220 221 /** Private implementation. */ 222 private ServerManagedObject<? extends RootDNUserCfg> impl; 223 224 /** The value of the "alternate-bind-dn" property. */ 225 private final SortedSet<DN> pAlternateBindDN; 226 227 228 229 /** Private constructor. */ 230 private RootDNUserCfgServerImpl(ServerManagedObject<? extends RootDNUserCfg> impl) { 231 this.impl = impl; 232 this.pAlternateBindDN = impl.getPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition()); 233 } 234 235 236 237 /** {@inheritDoc} */ 238 public void addChangeListener( 239 ConfigurationChangeListener<RootDNUserCfg> listener) { 240 impl.registerChangeListener(listener); 241 } 242 243 244 245 /** {@inheritDoc} */ 246 public void removeChangeListener( 247 ConfigurationChangeListener<RootDNUserCfg> listener) { 248 impl.deregisterChangeListener(listener); 249 } 250 251 252 253 /** {@inheritDoc} */ 254 public SortedSet<DN> getAlternateBindDN() { 255 return pAlternateBindDN; 256 } 257 258 259 260 /** {@inheritDoc} */ 261 public Class<? extends RootDNUserCfg> configurationClass() { 262 return RootDNUserCfg.class; 263 } 264 265 266 267 /** {@inheritDoc} */ 268 public DN dn() { 269 return impl.getDN(); 270 } 271 272 273 274 /** {@inheritDoc} */ 275 public String toString() { 276 return impl.toString(); 277 } 278 } 279}