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