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