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