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