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