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