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