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