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  /**
115   * {@inheritDoc}
116   */
117  public RootDNUserCfgClient createClientConfiguration(
118      ManagedObject<? extends RootDNUserCfgClient> impl) {
119    return new RootDNUserCfgClientImpl(impl);
120  }
121
122
123
124  /**
125   * {@inheritDoc}
126   */
127  public RootDNUserCfg createServerConfiguration(
128      ServerManagedObject<? extends RootDNUserCfg> impl) {
129    return new RootDNUserCfgServerImpl(impl);
130  }
131
132
133
134  /**
135   * {@inheritDoc}
136   */
137  public Class<RootDNUserCfg> getServerConfigurationClass() {
138    return RootDNUserCfg.class;
139  }
140
141
142
143  /**
144   * Get the "alternate-bind-dn" property definition.
145   * <p>
146   * Specifies one or more alternate DNs that can be used to bind to
147   * the server as this root user.
148   *
149   * @return Returns the "alternate-bind-dn" property definition.
150   */
151  public DNPropertyDefinition getAlternateBindDNPropertyDefinition() {
152    return PD_ALTERNATE_BIND_DN;
153  }
154
155
156
157  /**
158   * Managed object client implementation.
159   */
160  private static class RootDNUserCfgClientImpl implements
161    RootDNUserCfgClient {
162
163    // Private implementation.
164    private ManagedObject<? extends RootDNUserCfgClient> impl;
165
166
167
168    // Private constructor.
169    private RootDNUserCfgClientImpl(
170        ManagedObject<? extends RootDNUserCfgClient> impl) {
171      this.impl = impl;
172    }
173
174
175
176    /**
177     * {@inheritDoc}
178     */
179    public SortedSet<DN> getAlternateBindDN() {
180      return impl.getPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition());
181    }
182
183
184
185    /**
186     * {@inheritDoc}
187     */
188    public void setAlternateBindDN(Collection<DN> values) {
189      impl.setPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition(), values);
190    }
191
192
193
194    /**
195     * {@inheritDoc}
196     */
197    public ManagedObjectDefinition<? extends RootDNUserCfgClient, ? extends RootDNUserCfg> definition() {
198      return INSTANCE;
199    }
200
201
202
203    /**
204     * {@inheritDoc}
205     */
206    public PropertyProvider properties() {
207      return impl;
208    }
209
210
211
212    /**
213     * {@inheritDoc}
214     */
215    public void commit() throws ManagedObjectAlreadyExistsException,
216        MissingMandatoryPropertiesException, ConcurrentModificationException,
217        OperationRejectedException, LdapException {
218      impl.commit();
219    }
220
221  }
222
223
224
225  /**
226   * Managed object server implementation.
227   */
228  private static class RootDNUserCfgServerImpl implements
229    RootDNUserCfg {
230
231    // Private implementation.
232    private ServerManagedObject<? extends RootDNUserCfg> impl;
233
234    // The value of the "alternate-bind-dn" property.
235    private final SortedSet<DN> pAlternateBindDN;
236
237
238
239    // Private constructor.
240    private RootDNUserCfgServerImpl(ServerManagedObject<? extends RootDNUserCfg> impl) {
241      this.impl = impl;
242      this.pAlternateBindDN = impl.getPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition());
243    }
244
245
246
247    /**
248     * {@inheritDoc}
249     */
250    public void addChangeListener(
251        ConfigurationChangeListener<RootDNUserCfg> listener) {
252      impl.registerChangeListener(listener);
253    }
254
255
256
257    /**
258     * {@inheritDoc}
259     */
260    public void removeChangeListener(
261        ConfigurationChangeListener<RootDNUserCfg> listener) {
262      impl.deregisterChangeListener(listener);
263    }
264
265
266
267    /**
268     * {@inheritDoc}
269     */
270    public SortedSet<DN> getAlternateBindDN() {
271      return pAlternateBindDN;
272    }
273
274
275
276    /**
277     * {@inheritDoc}
278     */
279    public Class<? extends RootDNUserCfg> configurationClass() {
280      return RootDNUserCfg.class;
281    }
282
283
284
285    /**
286     * {@inheritDoc}
287     */
288    public DN dn() {
289      return impl.getDN();
290    }
291
292  }
293}