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 org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
038import org.forgerock.opendj.config.ManagedObjectDefinition;
039import org.forgerock.opendj.config.PropertyOption;
040import org.forgerock.opendj.config.PropertyProvider;
041import org.forgerock.opendj.config.server.ConfigurationChangeListener;
042import org.forgerock.opendj.config.server.ServerManagedObject;
043import org.forgerock.opendj.config.Tag;
044import org.forgerock.opendj.config.TopCfgDefn;
045import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
046import org.forgerock.opendj.ldap.DN;
047import org.forgerock.opendj.ldap.LdapException;
048import org.forgerock.opendj.server.config.client.AccessControlHandlerCfgClient;
049import org.forgerock.opendj.server.config.server.AccessControlHandlerCfg;
050
051
052
053/**
054 * An interface for querying the Access Control Handler managed object
055 * definition meta information.
056 * <p>
057 * Access Control Handlers manage the application-wide access control.
058 * The OpenDJ access control handler is defined through an extensible
059 * interface, so that alternate implementations can be created. Only
060 * one access control handler may be active in the server at any given
061 * time.
062 */
063public final class AccessControlHandlerCfgDefn extends ManagedObjectDefinition<AccessControlHandlerCfgClient, AccessControlHandlerCfg> {
064
065  /** The singleton configuration definition instance. */
066  private static final AccessControlHandlerCfgDefn INSTANCE = new AccessControlHandlerCfgDefn();
067
068
069
070  /** The "enabled" property definition. */
071  private static final BooleanPropertyDefinition PD_ENABLED;
072
073
074
075  /** The "java-class" property definition. */
076  private static final ClassPropertyDefinition PD_JAVA_CLASS;
077
078
079
080  /** Build the "enabled" property definition. */
081  static {
082      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
083      builder.setOption(PropertyOption.MANDATORY);
084      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
085      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
086      PD_ENABLED = builder.getInstance();
087      INSTANCE.registerPropertyDefinition(PD_ENABLED);
088  }
089
090
091
092  /** Build the "java-class" property definition. */
093  static {
094      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
095      builder.setOption(PropertyOption.MANDATORY);
096      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
097      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
098      builder.addInstanceOf("org.opends.server.api.AccessControlHandler");
099      PD_JAVA_CLASS = builder.getInstance();
100      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
101  }
102
103
104
105  // Register the tags associated with this managed object definition.
106  static {
107    INSTANCE.registerTag(Tag.valueOf("security"));
108  }
109
110
111
112  /**
113   * Get the Access Control Handler configuration definition
114   * singleton.
115   *
116   * @return Returns the Access Control Handler configuration
117   *         definition singleton.
118   */
119  public static AccessControlHandlerCfgDefn getInstance() {
120    return INSTANCE;
121  }
122
123
124
125  /**
126   * Private constructor.
127   */
128  private AccessControlHandlerCfgDefn() {
129    super("access-control-handler", TopCfgDefn.getInstance());
130  }
131
132
133
134  /** {@inheritDoc} */
135  public AccessControlHandlerCfgClient createClientConfiguration(
136      ManagedObject<? extends AccessControlHandlerCfgClient> impl) {
137    return new AccessControlHandlerCfgClientImpl(impl);
138  }
139
140
141
142  /** {@inheritDoc} */
143  public AccessControlHandlerCfg createServerConfiguration(
144      ServerManagedObject<? extends AccessControlHandlerCfg> impl) {
145    return new AccessControlHandlerCfgServerImpl(impl);
146  }
147
148
149
150  /** {@inheritDoc} */
151  public Class<AccessControlHandlerCfg> getServerConfigurationClass() {
152    return AccessControlHandlerCfg.class;
153  }
154
155
156
157  /**
158   * Get the "enabled" property definition.
159   * <p>
160   * Indicates whether the Access Control Handler is enabled. If set
161   * to FALSE, then no access control is enforced, and any client
162   * (including unauthenticated or anonymous clients) could be allowed
163   * to perform any operation if not subject to other restrictions,
164   * such as those enforced by the privilege subsystem.
165   *
166   * @return Returns the "enabled" property definition.
167   */
168  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
169    return PD_ENABLED;
170  }
171
172
173
174  /**
175   * Get the "java-class" property definition.
176   * <p>
177   * Specifies the fully-qualified name of the Java class that
178   * provides the Access Control Handler implementation.
179   *
180   * @return Returns the "java-class" property definition.
181   */
182  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
183    return PD_JAVA_CLASS;
184  }
185
186
187
188  /**
189   * Managed object client implementation.
190   */
191  private static class AccessControlHandlerCfgClientImpl implements
192    AccessControlHandlerCfgClient {
193
194    /** Private implementation. */
195    private ManagedObject<? extends AccessControlHandlerCfgClient> impl;
196
197
198
199    /** Private constructor. */
200    private AccessControlHandlerCfgClientImpl(
201        ManagedObject<? extends AccessControlHandlerCfgClient> impl) {
202      this.impl = impl;
203    }
204
205
206
207    /** {@inheritDoc} */
208    public Boolean isEnabled() {
209      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
210    }
211
212
213
214    /** {@inheritDoc} */
215    public void setEnabled(boolean value) {
216      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
217    }
218
219
220
221    /** {@inheritDoc} */
222    public String getJavaClass() {
223      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
224    }
225
226
227
228    /** {@inheritDoc} */
229    public void setJavaClass(String value) {
230      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
231    }
232
233
234
235    /** {@inheritDoc} */
236    public ManagedObjectDefinition<? extends AccessControlHandlerCfgClient, ? extends AccessControlHandlerCfg> definition() {
237      return INSTANCE;
238    }
239
240
241
242    /** {@inheritDoc} */
243    public PropertyProvider properties() {
244      return impl;
245    }
246
247
248
249    /** {@inheritDoc} */
250    public void commit() throws ManagedObjectAlreadyExistsException,
251        MissingMandatoryPropertiesException, ConcurrentModificationException,
252        OperationRejectedException, LdapException {
253      impl.commit();
254    }
255
256
257
258    /** {@inheritDoc} */
259    public String toString() {
260      return impl.toString();
261    }
262  }
263
264
265
266  /**
267   * Managed object server implementation.
268   */
269  private static class AccessControlHandlerCfgServerImpl implements
270    AccessControlHandlerCfg {
271
272    /** Private implementation. */
273    private ServerManagedObject<? extends AccessControlHandlerCfg> impl;
274
275    /** The value of the "enabled" property. */
276    private final boolean pEnabled;
277
278    /** The value of the "java-class" property. */
279    private final String pJavaClass;
280
281
282
283    /** Private constructor. */
284    private AccessControlHandlerCfgServerImpl(ServerManagedObject<? extends AccessControlHandlerCfg> impl) {
285      this.impl = impl;
286      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
287      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
288    }
289
290
291
292    /** {@inheritDoc} */
293    public void addChangeListener(
294        ConfigurationChangeListener<AccessControlHandlerCfg> listener) {
295      impl.registerChangeListener(listener);
296    }
297
298
299
300    /** {@inheritDoc} */
301    public void removeChangeListener(
302        ConfigurationChangeListener<AccessControlHandlerCfg> listener) {
303      impl.deregisterChangeListener(listener);
304    }
305
306
307
308    /** {@inheritDoc} */
309    public boolean isEnabled() {
310      return pEnabled;
311    }
312
313
314
315    /** {@inheritDoc} */
316    public String getJavaClass() {
317      return pJavaClass;
318    }
319
320
321
322    /** {@inheritDoc} */
323    public Class<? extends AccessControlHandlerCfg> configurationClass() {
324      return AccessControlHandlerCfg.class;
325    }
326
327
328
329    /** {@inheritDoc} */
330    public DN dn() {
331      return impl.getDN();
332    }
333
334
335
336    /** {@inheritDoc} */
337    public String toString() {
338      return impl.toString();
339    }
340  }
341}