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