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