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 java.util.Collection; 031import java.util.SortedSet; 032import org.forgerock.opendj.config.AdministratorAction; 033import org.forgerock.opendj.config.AliasDefaultBehaviorProvider; 034import org.forgerock.opendj.config.AttributeTypePropertyDefinition; 035import org.forgerock.opendj.config.BooleanPropertyDefinition; 036import org.forgerock.opendj.config.ClassPropertyDefinition; 037import org.forgerock.opendj.config.client.ConcurrentModificationException; 038import org.forgerock.opendj.config.client.ManagedObject; 039import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 040import org.forgerock.opendj.config.client.OperationRejectedException; 041import org.forgerock.opendj.config.DefaultBehaviorProvider; 042import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 043import org.forgerock.opendj.config.DNPropertyDefinition; 044import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 045import org.forgerock.opendj.config.ManagedObjectDefinition; 046import org.forgerock.opendj.config.PropertyOption; 047import org.forgerock.opendj.config.PropertyProvider; 048import org.forgerock.opendj.config.server.ConfigurationChangeListener; 049import org.forgerock.opendj.config.server.ServerManagedObject; 050import org.forgerock.opendj.config.Tag; 051import org.forgerock.opendj.ldap.DN; 052import org.forgerock.opendj.ldap.LdapException; 053import org.forgerock.opendj.ldap.schema.AttributeType; 054import org.forgerock.opendj.server.config.client.ExactMatchIdentityMapperCfgClient; 055import org.forgerock.opendj.server.config.server.ExactMatchIdentityMapperCfg; 056import org.forgerock.opendj.server.config.server.IdentityMapperCfg; 057 058 059 060/** 061 * An interface for querying the Exact Match Identity Mapper managed 062 * object definition meta information. 063 * <p> 064 * The Exact Match Identity Mapper maps an identifier string to user 065 * entries by searching for the entry containing a specified attribute 066 * whose value is the provided identifier. For example, the username 067 * provided by the client for DIGEST-MD5 authentication must match the 068 * value of the uid attribute 069 */ 070public final class ExactMatchIdentityMapperCfgDefn extends ManagedObjectDefinition<ExactMatchIdentityMapperCfgClient, ExactMatchIdentityMapperCfg> { 071 072 // The singleton configuration definition instance. 073 private static final ExactMatchIdentityMapperCfgDefn INSTANCE = new ExactMatchIdentityMapperCfgDefn(); 074 075 076 077 // The "java-class" property definition. 078 private static final ClassPropertyDefinition PD_JAVA_CLASS; 079 080 081 082 // The "match-attribute" property definition. 083 private static final AttributeTypePropertyDefinition PD_MATCH_ATTRIBUTE; 084 085 086 087 // The "match-base-dn" property definition. 088 private static final DNPropertyDefinition PD_MATCH_BASE_DN; 089 090 091 092 // Build the "java-class" property definition. 093 static { 094 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 095 builder.setOption(PropertyOption.MANDATORY); 096 builder.setOption(PropertyOption.ADVANCED); 097 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 098 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.ExactMatchIdentityMapper"); 099 builder.setDefaultBehaviorProvider(provider); 100 builder.addInstanceOf("org.opends.server.api.IdentityMapper"); 101 PD_JAVA_CLASS = builder.getInstance(); 102 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 103 } 104 105 106 107 // Build the "match-attribute" property definition. 108 static { 109 AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "match-attribute"); 110 builder.setOption(PropertyOption.MULTI_VALUED); 111 builder.setOption(PropertyOption.MANDATORY); 112 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-attribute")); 113 DefaultBehaviorProvider<AttributeType> provider = new DefinedDefaultBehaviorProvider<AttributeType>("uid"); 114 builder.setDefaultBehaviorProvider(provider); 115 PD_MATCH_ATTRIBUTE = builder.getInstance(); 116 INSTANCE.registerPropertyDefinition(PD_MATCH_ATTRIBUTE); 117 } 118 119 120 121 // Build the "match-base-dn" property definition. 122 static { 123 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "match-base-dn"); 124 builder.setOption(PropertyOption.MULTI_VALUED); 125 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-base-dn")); 126 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "match-base-dn")); 127 PD_MATCH_BASE_DN = builder.getInstance(); 128 INSTANCE.registerPropertyDefinition(PD_MATCH_BASE_DN); 129 } 130 131 132 133 // Register the tags associated with this managed object definition. 134 static { 135 INSTANCE.registerTag(Tag.valueOf("security")); 136 INSTANCE.registerTag(Tag.valueOf("user-management")); 137 } 138 139 140 141 /** 142 * Get the Exact Match Identity Mapper configuration definition 143 * singleton. 144 * 145 * @return Returns the Exact Match Identity Mapper configuration 146 * definition singleton. 147 */ 148 public static ExactMatchIdentityMapperCfgDefn getInstance() { 149 return INSTANCE; 150 } 151 152 153 154 /** 155 * Private constructor. 156 */ 157 private ExactMatchIdentityMapperCfgDefn() { 158 super("exact-match-identity-mapper", IdentityMapperCfgDefn.getInstance()); 159 } 160 161 162 163 /** 164 * {@inheritDoc} 165 */ 166 public ExactMatchIdentityMapperCfgClient createClientConfiguration( 167 ManagedObject<? extends ExactMatchIdentityMapperCfgClient> impl) { 168 return new ExactMatchIdentityMapperCfgClientImpl(impl); 169 } 170 171 172 173 /** 174 * {@inheritDoc} 175 */ 176 public ExactMatchIdentityMapperCfg createServerConfiguration( 177 ServerManagedObject<? extends ExactMatchIdentityMapperCfg> impl) { 178 return new ExactMatchIdentityMapperCfgServerImpl(impl); 179 } 180 181 182 183 /** 184 * {@inheritDoc} 185 */ 186 public Class<ExactMatchIdentityMapperCfg> getServerConfigurationClass() { 187 return ExactMatchIdentityMapperCfg.class; 188 } 189 190 191 192 /** 193 * Get the "enabled" property definition. 194 * <p> 195 * Indicates whether the Exact Match Identity Mapper is enabled for 196 * use. 197 * 198 * @return Returns the "enabled" property definition. 199 */ 200 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 201 return IdentityMapperCfgDefn.getInstance().getEnabledPropertyDefinition(); 202 } 203 204 205 206 /** 207 * Get the "java-class" property definition. 208 * <p> 209 * Specifies the fully-qualified name of the Java class that 210 * provides the Exact Match Identity Mapper implementation. 211 * 212 * @return Returns the "java-class" property definition. 213 */ 214 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 215 return PD_JAVA_CLASS; 216 } 217 218 219 220 /** 221 * Get the "match-attribute" property definition. 222 * <p> 223 * Specifies the attribute whose value should exactly match the ID 224 * string provided to this identity mapper. 225 * <p> 226 * At least one value must be provided. All values must refer to the 227 * name or OID of an attribute type defined in the directory server 228 * schema. If multiple attributes or OIDs are provided, at least one 229 * of those attributes must contain the provided ID string value in 230 * exactly one entry. The internal search performed includes a 231 * logical OR across all of these values. 232 * 233 * @return Returns the "match-attribute" property definition. 234 */ 235 public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() { 236 return PD_MATCH_ATTRIBUTE; 237 } 238 239 240 241 /** 242 * Get the "match-base-dn" property definition. 243 * <p> 244 * Specifies the set of base DNs below which to search for users. 245 * <p> 246 * The base DNs will be used when performing searches to map the 247 * provided ID string to a user entry. If multiple values are given, 248 * searches are performed below all specified base DNs. 249 * 250 * @return Returns the "match-base-dn" property definition. 251 */ 252 public DNPropertyDefinition getMatchBaseDNPropertyDefinition() { 253 return PD_MATCH_BASE_DN; 254 } 255 256 257 258 /** 259 * Managed object client implementation. 260 */ 261 private static class ExactMatchIdentityMapperCfgClientImpl implements 262 ExactMatchIdentityMapperCfgClient { 263 264 // Private implementation. 265 private ManagedObject<? extends ExactMatchIdentityMapperCfgClient> impl; 266 267 268 269 // Private constructor. 270 private ExactMatchIdentityMapperCfgClientImpl( 271 ManagedObject<? extends ExactMatchIdentityMapperCfgClient> impl) { 272 this.impl = impl; 273 } 274 275 276 277 /** 278 * {@inheritDoc} 279 */ 280 public Boolean isEnabled() { 281 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 282 } 283 284 285 286 /** 287 * {@inheritDoc} 288 */ 289 public void setEnabled(boolean value) { 290 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 291 } 292 293 294 295 /** 296 * {@inheritDoc} 297 */ 298 public String getJavaClass() { 299 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 300 } 301 302 303 304 /** 305 * {@inheritDoc} 306 */ 307 public void setJavaClass(String value) { 308 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 309 } 310 311 312 313 /** 314 * {@inheritDoc} 315 */ 316 public SortedSet<AttributeType> getMatchAttribute() { 317 return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition()); 318 } 319 320 321 322 /** 323 * {@inheritDoc} 324 */ 325 public void setMatchAttribute(Collection<AttributeType> values) { 326 impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values); 327 } 328 329 330 331 /** 332 * {@inheritDoc} 333 */ 334 public SortedSet<DN> getMatchBaseDN() { 335 return impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition()); 336 } 337 338 339 340 /** 341 * {@inheritDoc} 342 */ 343 public void setMatchBaseDN(Collection<DN> values) { 344 impl.setPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition(), values); 345 } 346 347 348 349 /** 350 * {@inheritDoc} 351 */ 352 public ManagedObjectDefinition<? extends ExactMatchIdentityMapperCfgClient, ? extends ExactMatchIdentityMapperCfg> definition() { 353 return INSTANCE; 354 } 355 356 357 358 /** 359 * {@inheritDoc} 360 */ 361 public PropertyProvider properties() { 362 return impl; 363 } 364 365 366 367 /** 368 * {@inheritDoc} 369 */ 370 public void commit() throws ManagedObjectAlreadyExistsException, 371 MissingMandatoryPropertiesException, ConcurrentModificationException, 372 OperationRejectedException, LdapException { 373 impl.commit(); 374 } 375 376 } 377 378 379 380 /** 381 * Managed object server implementation. 382 */ 383 private static class ExactMatchIdentityMapperCfgServerImpl implements 384 ExactMatchIdentityMapperCfg { 385 386 // Private implementation. 387 private ServerManagedObject<? extends ExactMatchIdentityMapperCfg> impl; 388 389 // The value of the "enabled" property. 390 private final boolean pEnabled; 391 392 // The value of the "java-class" property. 393 private final String pJavaClass; 394 395 // The value of the "match-attribute" property. 396 private final SortedSet<AttributeType> pMatchAttribute; 397 398 // The value of the "match-base-dn" property. 399 private final SortedSet<DN> pMatchBaseDN; 400 401 402 403 // Private constructor. 404 private ExactMatchIdentityMapperCfgServerImpl(ServerManagedObject<? extends ExactMatchIdentityMapperCfg> impl) { 405 this.impl = impl; 406 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 407 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 408 this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition()); 409 this.pMatchBaseDN = impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition()); 410 } 411 412 413 414 /** 415 * {@inheritDoc} 416 */ 417 public void addExactMatchChangeListener( 418 ConfigurationChangeListener<ExactMatchIdentityMapperCfg> listener) { 419 impl.registerChangeListener(listener); 420 } 421 422 423 424 /** 425 * {@inheritDoc} 426 */ 427 public void removeExactMatchChangeListener( 428 ConfigurationChangeListener<ExactMatchIdentityMapperCfg> listener) { 429 impl.deregisterChangeListener(listener); 430 } 431 /** 432 * {@inheritDoc} 433 */ 434 public void addChangeListener( 435 ConfigurationChangeListener<IdentityMapperCfg> listener) { 436 impl.registerChangeListener(listener); 437 } 438 439 440 441 /** 442 * {@inheritDoc} 443 */ 444 public void removeChangeListener( 445 ConfigurationChangeListener<IdentityMapperCfg> listener) { 446 impl.deregisterChangeListener(listener); 447 } 448 449 450 451 /** 452 * {@inheritDoc} 453 */ 454 public boolean isEnabled() { 455 return pEnabled; 456 } 457 458 459 460 /** 461 * {@inheritDoc} 462 */ 463 public String getJavaClass() { 464 return pJavaClass; 465 } 466 467 468 469 /** 470 * {@inheritDoc} 471 */ 472 public SortedSet<AttributeType> getMatchAttribute() { 473 return pMatchAttribute; 474 } 475 476 477 478 /** 479 * {@inheritDoc} 480 */ 481 public SortedSet<DN> getMatchBaseDN() { 482 return pMatchBaseDN; 483 } 484 485 486 487 /** 488 * {@inheritDoc} 489 */ 490 public Class<? extends ExactMatchIdentityMapperCfg> configurationClass() { 491 return ExactMatchIdentityMapperCfg.class; 492 } 493 494 495 496 /** 497 * {@inheritDoc} 498 */ 499 public DN dn() { 500 return impl.getDN(); 501 } 502 503 } 504}