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.AggregationPropertyDefinition; 032import org.forgerock.opendj.config.BooleanPropertyDefinition; 033import org.forgerock.opendj.config.ClassPropertyDefinition; 034import org.forgerock.opendj.config.client.ConcurrentModificationException; 035import org.forgerock.opendj.config.client.ManagedObject; 036import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 037import org.forgerock.opendj.config.client.OperationRejectedException; 038import org.forgerock.opendj.config.conditions.Conditions; 039import org.forgerock.opendj.config.DefaultBehaviorProvider; 040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 041import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 042import org.forgerock.opendj.config.ManagedObjectDefinition; 043import org.forgerock.opendj.config.PropertyOption; 044import org.forgerock.opendj.config.PropertyProvider; 045import org.forgerock.opendj.config.server.ConfigurationChangeListener; 046import org.forgerock.opendj.config.server.ServerManagedObject; 047import org.forgerock.opendj.config.Tag; 048import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 049import org.forgerock.opendj.ldap.DN; 050import org.forgerock.opendj.ldap.LdapException; 051import org.forgerock.opendj.server.config.client.CramMD5SASLMechanismHandlerCfgClient; 052import org.forgerock.opendj.server.config.client.IdentityMapperCfgClient; 053import org.forgerock.opendj.server.config.server.CramMD5SASLMechanismHandlerCfg; 054import org.forgerock.opendj.server.config.server.IdentityMapperCfg; 055import org.forgerock.opendj.server.config.server.SASLMechanismHandlerCfg; 056 057 058 059/** 060 * An interface for querying the Cram MD5 SASL Mechanism Handler 061 * managed object definition meta information. 062 * <p> 063 * The CRAM-MD5 SASL mechanism provides the ability for clients to 064 * perform password-based authentication in a manner that does not 065 * expose their password in the clear. 066 */ 067public final class CramMD5SASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<CramMD5SASLMechanismHandlerCfgClient, CramMD5SASLMechanismHandlerCfg> { 068 069 /** The singleton configuration definition instance. */ 070 private static final CramMD5SASLMechanismHandlerCfgDefn INSTANCE = new CramMD5SASLMechanismHandlerCfgDefn(); 071 072 073 074 /** The "identity-mapper" property definition. */ 075 private static final AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> PD_IDENTITY_MAPPER; 076 077 078 079 /** The "java-class" property definition. */ 080 private static final ClassPropertyDefinition PD_JAVA_CLASS; 081 082 083 084 /** Build the "identity-mapper" property definition. */ 085 static { 086 AggregationPropertyDefinition.Builder<IdentityMapperCfgClient, IdentityMapperCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "identity-mapper"); 087 builder.setOption(PropertyOption.MANDATORY); 088 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "identity-mapper")); 089 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 090 builder.setParentPath("/"); 091 builder.setRelationDefinition("identity-mapper"); 092 builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true")); 093 builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true")); 094 PD_IDENTITY_MAPPER = builder.getInstance(); 095 INSTANCE.registerPropertyDefinition(PD_IDENTITY_MAPPER); 096 INSTANCE.registerConstraint(PD_IDENTITY_MAPPER.getSourceConstraint()); 097 } 098 099 100 101 /** Build the "java-class" property definition. */ 102 static { 103 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 104 builder.setOption(PropertyOption.MANDATORY); 105 builder.setOption(PropertyOption.ADVANCED); 106 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 107 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.CRAMMD5SASLMechanismHandler"); 108 builder.setDefaultBehaviorProvider(provider); 109 builder.addInstanceOf("org.opends.server.api.SASLMechanismHandler"); 110 PD_JAVA_CLASS = builder.getInstance(); 111 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 112 } 113 114 115 116 // Register the tags associated with this managed object definition. 117 static { 118 INSTANCE.registerTag(Tag.valueOf("security")); 119 } 120 121 122 123 /** 124 * Get the Cram MD5 SASL Mechanism Handler configuration definition 125 * singleton. 126 * 127 * @return Returns the Cram MD5 SASL Mechanism Handler configuration 128 * definition singleton. 129 */ 130 public static CramMD5SASLMechanismHandlerCfgDefn getInstance() { 131 return INSTANCE; 132 } 133 134 135 136 /** 137 * Private constructor. 138 */ 139 private CramMD5SASLMechanismHandlerCfgDefn() { 140 super("cram-md5-sasl-mechanism-handler", SASLMechanismHandlerCfgDefn.getInstance()); 141 } 142 143 144 145 /** {@inheritDoc} */ 146 public CramMD5SASLMechanismHandlerCfgClient createClientConfiguration( 147 ManagedObject<? extends CramMD5SASLMechanismHandlerCfgClient> impl) { 148 return new CramMD5SASLMechanismHandlerCfgClientImpl(impl); 149 } 150 151 152 153 /** {@inheritDoc} */ 154 public CramMD5SASLMechanismHandlerCfg createServerConfiguration( 155 ServerManagedObject<? extends CramMD5SASLMechanismHandlerCfg> impl) { 156 return new CramMD5SASLMechanismHandlerCfgServerImpl(impl); 157 } 158 159 160 161 /** {@inheritDoc} */ 162 public Class<CramMD5SASLMechanismHandlerCfg> getServerConfigurationClass() { 163 return CramMD5SASLMechanismHandlerCfg.class; 164 } 165 166 167 168 /** 169 * Get the "enabled" property definition. 170 * <p> 171 * Indicates whether the SASL mechanism handler is enabled for use. 172 * 173 * @return Returns the "enabled" property definition. 174 */ 175 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 176 return SASLMechanismHandlerCfgDefn.getInstance().getEnabledPropertyDefinition(); 177 } 178 179 180 181 /** 182 * Get the "identity-mapper" property definition. 183 * <p> 184 * Specifies the name of the identity mapper used with this SASL 185 * mechanism handler to match the authentication ID included in the 186 * SASL bind request to the corresponding user in the directory. 187 * 188 * @return Returns the "identity-mapper" property definition. 189 */ 190 public AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> getIdentityMapperPropertyDefinition() { 191 return PD_IDENTITY_MAPPER; 192 } 193 194 195 196 /** 197 * Get the "java-class" property definition. 198 * <p> 199 * Specifies the fully-qualified name of the Java class that 200 * provides the SASL mechanism handler implementation. 201 * 202 * @return Returns the "java-class" property definition. 203 */ 204 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 205 return PD_JAVA_CLASS; 206 } 207 208 209 210 /** 211 * Managed object client implementation. 212 */ 213 private static class CramMD5SASLMechanismHandlerCfgClientImpl implements 214 CramMD5SASLMechanismHandlerCfgClient { 215 216 /** Private implementation. */ 217 private ManagedObject<? extends CramMD5SASLMechanismHandlerCfgClient> impl; 218 219 220 221 /** Private constructor. */ 222 private CramMD5SASLMechanismHandlerCfgClientImpl( 223 ManagedObject<? extends CramMD5SASLMechanismHandlerCfgClient> impl) { 224 this.impl = impl; 225 } 226 227 228 229 /** {@inheritDoc} */ 230 public Boolean isEnabled() { 231 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 232 } 233 234 235 236 /** {@inheritDoc} */ 237 public void setEnabled(boolean value) { 238 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 239 } 240 241 242 243 /** {@inheritDoc} */ 244 public String getIdentityMapper() { 245 return impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition()); 246 } 247 248 249 250 /** {@inheritDoc} */ 251 public void setIdentityMapper(String value) { 252 impl.setPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition(), value); 253 } 254 255 256 257 /** {@inheritDoc} */ 258 public String getJavaClass() { 259 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 260 } 261 262 263 264 /** {@inheritDoc} */ 265 public void setJavaClass(String value) { 266 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 267 } 268 269 270 271 /** {@inheritDoc} */ 272 public ManagedObjectDefinition<? extends CramMD5SASLMechanismHandlerCfgClient, ? extends CramMD5SASLMechanismHandlerCfg> definition() { 273 return INSTANCE; 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public PropertyProvider properties() { 280 return impl; 281 } 282 283 284 285 /** {@inheritDoc} */ 286 public void commit() throws ManagedObjectAlreadyExistsException, 287 MissingMandatoryPropertiesException, ConcurrentModificationException, 288 OperationRejectedException, LdapException { 289 impl.commit(); 290 } 291 292 293 294 /** {@inheritDoc} */ 295 public String toString() { 296 return impl.toString(); 297 } 298 } 299 300 301 302 /** 303 * Managed object server implementation. 304 */ 305 private static class CramMD5SASLMechanismHandlerCfgServerImpl implements 306 CramMD5SASLMechanismHandlerCfg { 307 308 /** Private implementation. */ 309 private ServerManagedObject<? extends CramMD5SASLMechanismHandlerCfg> impl; 310 311 /** The value of the "enabled" property. */ 312 private final boolean pEnabled; 313 314 /** The value of the "identity-mapper" property. */ 315 private final String pIdentityMapper; 316 317 /** The value of the "java-class" property. */ 318 private final String pJavaClass; 319 320 321 322 /** Private constructor. */ 323 private CramMD5SASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends CramMD5SASLMechanismHandlerCfg> impl) { 324 this.impl = impl; 325 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 326 this.pIdentityMapper = impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition()); 327 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 328 } 329 330 331 332 /** {@inheritDoc} */ 333 public void addCramMD5ChangeListener( 334 ConfigurationChangeListener<CramMD5SASLMechanismHandlerCfg> listener) { 335 impl.registerChangeListener(listener); 336 } 337 338 339 340 /** {@inheritDoc} */ 341 public void removeCramMD5ChangeListener( 342 ConfigurationChangeListener<CramMD5SASLMechanismHandlerCfg> listener) { 343 impl.deregisterChangeListener(listener); 344 } 345 /** {@inheritDoc} */ 346 public void addChangeListener( 347 ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) { 348 impl.registerChangeListener(listener); 349 } 350 351 352 353 /** {@inheritDoc} */ 354 public void removeChangeListener( 355 ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) { 356 impl.deregisterChangeListener(listener); 357 } 358 359 360 361 /** {@inheritDoc} */ 362 public boolean isEnabled() { 363 return pEnabled; 364 } 365 366 367 368 /** {@inheritDoc} */ 369 public String getIdentityMapper() { 370 return pIdentityMapper; 371 } 372 373 374 375 /** 376 * {@inheritDoc} 377 */ 378 public DN getIdentityMapperDN() { 379 String value = getIdentityMapper(); 380 if (value == null) return null; 381 return INSTANCE.getIdentityMapperPropertyDefinition().getChildDN(value); 382 } 383 384 385 386 /** {@inheritDoc} */ 387 public String getJavaClass() { 388 return pJavaClass; 389 } 390 391 392 393 /** {@inheritDoc} */ 394 public Class<? extends CramMD5SASLMechanismHandlerCfg> configurationClass() { 395 return CramMD5SASLMechanismHandlerCfg.class; 396 } 397 398 399 400 /** {@inheritDoc} */ 401 public DN dn() { 402 return impl.getDN(); 403 } 404 405 406 407 /** {@inheritDoc} */ 408 public String toString() { 409 return impl.toString(); 410 } 411 } 412}