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