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