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.AliasDefaultBehaviorProvider; 022import org.forgerock.opendj.config.BooleanPropertyDefinition; 023import org.forgerock.opendj.config.ClassPropertyDefinition; 024import org.forgerock.opendj.config.client.ConcurrentModificationException; 025import org.forgerock.opendj.config.client.ManagedObject; 026import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 027import org.forgerock.opendj.config.client.OperationRejectedException; 028import org.forgerock.opendj.config.DefaultBehaviorProvider; 029import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 030import org.forgerock.opendj.config.DNPropertyDefinition; 031import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 032import org.forgerock.opendj.config.ManagedObjectDefinition; 033import org.forgerock.opendj.config.PropertyOption; 034import org.forgerock.opendj.config.PropertyProvider; 035import org.forgerock.opendj.config.server.ConfigurationChangeListener; 036import org.forgerock.opendj.config.server.ServerManagedObject; 037import org.forgerock.opendj.ldap.DN; 038import org.forgerock.opendj.ldap.LdapException; 039import org.forgerock.opendj.server.config.client.HTTPAnonymousAuthorizationMechanismCfgClient; 040import org.forgerock.opendj.server.config.server.HTTPAnonymousAuthorizationMechanismCfg; 041import org.forgerock.opendj.server.config.server.HTTPAuthorizationMechanismCfg; 042 043 044 045/** 046 * An interface for querying the HTTP Anonymous Authorization 047 * Mechanism managed object definition meta information. 048 * <p> 049 * The HTTP Anonymous Authorization Mechanism is used to define static 050 * authorization. 051 */ 052public final class HTTPAnonymousAuthorizationMechanismCfgDefn extends ManagedObjectDefinition<HTTPAnonymousAuthorizationMechanismCfgClient, HTTPAnonymousAuthorizationMechanismCfg> { 053 054 /** The singleton configuration definition instance. */ 055 private static final HTTPAnonymousAuthorizationMechanismCfgDefn INSTANCE = new HTTPAnonymousAuthorizationMechanismCfgDefn(); 056 057 058 059 /** The "java-class" property definition. */ 060 private static final ClassPropertyDefinition PD_JAVA_CLASS; 061 062 063 064 /** The "user-dn" property definition. */ 065 private static final DNPropertyDefinition PD_USER_DN; 066 067 068 069 /** Build the "java-class" property definition. */ 070 static { 071 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 072 builder.setOption(PropertyOption.MANDATORY); 073 builder.setOption(PropertyOption.ADVANCED); 074 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 075 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.protocols.http.authz.HttpAnonymousAuthorizationMechanism"); 076 builder.setDefaultBehaviorProvider(provider); 077 builder.addInstanceOf("org.opends.server.protocols.http.authz.HttpAuthorizationMechanism"); 078 PD_JAVA_CLASS = builder.getInstance(); 079 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 080 } 081 082 083 084 /** Build the "user-dn" property definition. */ 085 static { 086 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "user-dn"); 087 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "user-dn")); 088 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "user-dn")); 089 PD_USER_DN = builder.getInstance(); 090 INSTANCE.registerPropertyDefinition(PD_USER_DN); 091 } 092 093 094 095 /** 096 * Get the HTTP Anonymous Authorization Mechanism configuration 097 * definition singleton. 098 * 099 * @return Returns the HTTP Anonymous Authorization Mechanism 100 * configuration definition singleton. 101 */ 102 public static HTTPAnonymousAuthorizationMechanismCfgDefn getInstance() { 103 return INSTANCE; 104 } 105 106 107 108 /** 109 * Private constructor. 110 */ 111 private HTTPAnonymousAuthorizationMechanismCfgDefn() { 112 super("http-anonymous-authorization-mechanism", HTTPAuthorizationMechanismCfgDefn.getInstance()); 113 } 114 115 116 117 /** {@inheritDoc} */ 118 public HTTPAnonymousAuthorizationMechanismCfgClient createClientConfiguration( 119 ManagedObject<? extends HTTPAnonymousAuthorizationMechanismCfgClient> impl) { 120 return new HTTPAnonymousAuthorizationMechanismCfgClientImpl(impl); 121 } 122 123 124 125 /** {@inheritDoc} */ 126 public HTTPAnonymousAuthorizationMechanismCfg createServerConfiguration( 127 ServerManagedObject<? extends HTTPAnonymousAuthorizationMechanismCfg> impl) { 128 return new HTTPAnonymousAuthorizationMechanismCfgServerImpl(impl); 129 } 130 131 132 133 /** {@inheritDoc} */ 134 public Class<HTTPAnonymousAuthorizationMechanismCfg> getServerConfigurationClass() { 135 return HTTPAnonymousAuthorizationMechanismCfg.class; 136 } 137 138 139 140 /** 141 * Get the "enabled" property definition. 142 * <p> 143 * Indicates whether the HTTP Anonymous Authorization Mechanism is 144 * enabled. 145 * 146 * @return Returns the "enabled" property definition. 147 */ 148 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 149 return HTTPAuthorizationMechanismCfgDefn.getInstance().getEnabledPropertyDefinition(); 150 } 151 152 153 154 /** 155 * Get the "java-class" property definition. 156 * <p> 157 * Specifies the fully-qualified name of the Java class that 158 * provides the HTTP Anonymous Authorization Mechanism 159 * implementation. 160 * 161 * @return Returns the "java-class" property definition. 162 */ 163 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 164 return PD_JAVA_CLASS; 165 } 166 167 168 169 /** 170 * Get the "user-dn" property definition. 171 * <p> 172 * The authorization DN which will be used for performing anonymous 173 * operations. 174 * 175 * @return Returns the "user-dn" property definition. 176 */ 177 public DNPropertyDefinition getUserDNPropertyDefinition() { 178 return PD_USER_DN; 179 } 180 181 182 183 /** 184 * Managed object client implementation. 185 */ 186 private static class HTTPAnonymousAuthorizationMechanismCfgClientImpl implements 187 HTTPAnonymousAuthorizationMechanismCfgClient { 188 189 /** Private implementation. */ 190 private ManagedObject<? extends HTTPAnonymousAuthorizationMechanismCfgClient> impl; 191 192 193 194 /** Private constructor. */ 195 private HTTPAnonymousAuthorizationMechanismCfgClientImpl( 196 ManagedObject<? extends HTTPAnonymousAuthorizationMechanismCfgClient> impl) { 197 this.impl = impl; 198 } 199 200 201 202 /** {@inheritDoc} */ 203 public Boolean isEnabled() { 204 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 205 } 206 207 208 209 /** {@inheritDoc} */ 210 public void setEnabled(boolean value) { 211 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 212 } 213 214 215 216 /** {@inheritDoc} */ 217 public String getJavaClass() { 218 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 219 } 220 221 222 223 /** {@inheritDoc} */ 224 public void setJavaClass(String value) { 225 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 226 } 227 228 229 230 /** {@inheritDoc} */ 231 public DN getUserDN() { 232 return impl.getPropertyValue(INSTANCE.getUserDNPropertyDefinition()); 233 } 234 235 236 237 /** {@inheritDoc} */ 238 public void setUserDN(DN value) { 239 impl.setPropertyValue(INSTANCE.getUserDNPropertyDefinition(), value); 240 } 241 242 243 244 /** {@inheritDoc} */ 245 public ManagedObjectDefinition<? extends HTTPAnonymousAuthorizationMechanismCfgClient, ? extends HTTPAnonymousAuthorizationMechanismCfg> definition() { 246 return INSTANCE; 247 } 248 249 250 251 /** {@inheritDoc} */ 252 public PropertyProvider properties() { 253 return impl; 254 } 255 256 257 258 /** {@inheritDoc} */ 259 public void commit() throws ManagedObjectAlreadyExistsException, 260 MissingMandatoryPropertiesException, ConcurrentModificationException, 261 OperationRejectedException, LdapException { 262 impl.commit(); 263 } 264 265 266 267 /** {@inheritDoc} */ 268 public String toString() { 269 return impl.toString(); 270 } 271 } 272 273 274 275 /** 276 * Managed object server implementation. 277 */ 278 private static class HTTPAnonymousAuthorizationMechanismCfgServerImpl implements 279 HTTPAnonymousAuthorizationMechanismCfg { 280 281 /** Private implementation. */ 282 private ServerManagedObject<? extends HTTPAnonymousAuthorizationMechanismCfg> impl; 283 284 /** The value of the "enabled" property. */ 285 private final boolean pEnabled; 286 287 /** The value of the "java-class" property. */ 288 private final String pJavaClass; 289 290 /** The value of the "user-dn" property. */ 291 private final DN pUserDN; 292 293 294 295 /** Private constructor. */ 296 private HTTPAnonymousAuthorizationMechanismCfgServerImpl(ServerManagedObject<? extends HTTPAnonymousAuthorizationMechanismCfg> impl) { 297 this.impl = impl; 298 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 299 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 300 this.pUserDN = impl.getPropertyValue(INSTANCE.getUserDNPropertyDefinition()); 301 } 302 303 304 305 /** {@inheritDoc} */ 306 public void addHTTPAnonymousAuthorizationMechanismChangeListener( 307 ConfigurationChangeListener<HTTPAnonymousAuthorizationMechanismCfg> listener) { 308 impl.registerChangeListener(listener); 309 } 310 311 312 313 /** {@inheritDoc} */ 314 public void removeHTTPAnonymousAuthorizationMechanismChangeListener( 315 ConfigurationChangeListener<HTTPAnonymousAuthorizationMechanismCfg> listener) { 316 impl.deregisterChangeListener(listener); 317 } 318 /** {@inheritDoc} */ 319 public void addChangeListener( 320 ConfigurationChangeListener<HTTPAuthorizationMechanismCfg> listener) { 321 impl.registerChangeListener(listener); 322 } 323 324 325 326 /** {@inheritDoc} */ 327 public void removeChangeListener( 328 ConfigurationChangeListener<HTTPAuthorizationMechanismCfg> listener) { 329 impl.deregisterChangeListener(listener); 330 } 331 332 333 334 /** {@inheritDoc} */ 335 public boolean isEnabled() { 336 return pEnabled; 337 } 338 339 340 341 /** {@inheritDoc} */ 342 public String getJavaClass() { 343 return pJavaClass; 344 } 345 346 347 348 /** {@inheritDoc} */ 349 public DN getUserDN() { 350 return pUserDN; 351 } 352 353 354 355 /** {@inheritDoc} */ 356 public Class<? extends HTTPAnonymousAuthorizationMechanismCfg> configurationClass() { 357 return HTTPAnonymousAuthorizationMechanismCfg.class; 358 } 359 360 361 362 /** {@inheritDoc} */ 363 public DN dn() { 364 return impl.getDN(); 365 } 366 367 368 369 /** {@inheritDoc} */ 370 public String toString() { 371 return impl.toString(); 372 } 373 } 374}