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.StringPropertyDefinition; 051import org.forgerock.opendj.config.Tag; 052import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 053import org.forgerock.opendj.ldap.DN; 054import org.forgerock.opendj.ldap.LdapException; 055import org.forgerock.opendj.ldap.schema.AttributeType; 056import org.forgerock.opendj.server.config.client.RegularExpressionIdentityMapperCfgClient; 057import org.forgerock.opendj.server.config.server.IdentityMapperCfg; 058import org.forgerock.opendj.server.config.server.RegularExpressionIdentityMapperCfg; 059 060 061 062/** 063 * An interface for querying the Regular Expression Identity Mapper 064 * managed object definition meta information. 065 * <p> 066 * The Regular Expression Identity Mapper provides a way to use a 067 * regular expression to translate the provided identifier when 068 * searching for the appropriate user entry. 069 */ 070public final class RegularExpressionIdentityMapperCfgDefn extends ManagedObjectDefinition<RegularExpressionIdentityMapperCfgClient, RegularExpressionIdentityMapperCfg> { 071 072 /** The singleton configuration definition instance. */ 073 private static final RegularExpressionIdentityMapperCfgDefn INSTANCE = new RegularExpressionIdentityMapperCfgDefn(); 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 /** The "match-pattern" property definition. */ 093 private static final StringPropertyDefinition PD_MATCH_PATTERN; 094 095 096 097 /** The "replace-pattern" property definition. */ 098 private static final StringPropertyDefinition PD_REPLACE_PATTERN; 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.RegularExpressionIdentityMapper"); 109 builder.setDefaultBehaviorProvider(provider); 110 builder.addInstanceOf("org.opends.server.api.IdentityMapper"); 111 PD_JAVA_CLASS = builder.getInstance(); 112 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 113 } 114 115 116 117 /** Build the "match-attribute" property definition. */ 118 static { 119 AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "match-attribute"); 120 builder.setOption(PropertyOption.MULTI_VALUED); 121 builder.setOption(PropertyOption.MANDATORY); 122 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-attribute")); 123 DefaultBehaviorProvider<AttributeType> provider = new DefinedDefaultBehaviorProvider<AttributeType>("uid"); 124 builder.setDefaultBehaviorProvider(provider); 125 PD_MATCH_ATTRIBUTE = builder.getInstance(); 126 INSTANCE.registerPropertyDefinition(PD_MATCH_ATTRIBUTE); 127 } 128 129 130 131 /** Build the "match-base-dn" property definition. */ 132 static { 133 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "match-base-dn"); 134 builder.setOption(PropertyOption.MULTI_VALUED); 135 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-base-dn")); 136 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "match-base-dn")); 137 PD_MATCH_BASE_DN = builder.getInstance(); 138 INSTANCE.registerPropertyDefinition(PD_MATCH_BASE_DN); 139 } 140 141 142 143 /** Build the "match-pattern" property definition. */ 144 static { 145 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "match-pattern"); 146 builder.setOption(PropertyOption.MANDATORY); 147 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-pattern")); 148 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 149 builder.setPattern(".*", "REGEXP"); 150 PD_MATCH_PATTERN = builder.getInstance(); 151 INSTANCE.registerPropertyDefinition(PD_MATCH_PATTERN); 152 } 153 154 155 156 /** Build the "replace-pattern" property definition. */ 157 static { 158 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "replace-pattern"); 159 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replace-pattern")); 160 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "replace-pattern")); 161 builder.setPattern(".*", "REGEXP"); 162 PD_REPLACE_PATTERN = builder.getInstance(); 163 INSTANCE.registerPropertyDefinition(PD_REPLACE_PATTERN); 164 } 165 166 167 168 // Register the tags associated with this managed object definition. 169 static { 170 INSTANCE.registerTag(Tag.valueOf("security")); 171 INSTANCE.registerTag(Tag.valueOf("user-management")); 172 } 173 174 175 176 /** 177 * Get the Regular Expression Identity Mapper configuration 178 * definition singleton. 179 * 180 * @return Returns the Regular Expression Identity Mapper 181 * configuration definition singleton. 182 */ 183 public static RegularExpressionIdentityMapperCfgDefn getInstance() { 184 return INSTANCE; 185 } 186 187 188 189 /** 190 * Private constructor. 191 */ 192 private RegularExpressionIdentityMapperCfgDefn() { 193 super("regular-expression-identity-mapper", IdentityMapperCfgDefn.getInstance()); 194 } 195 196 197 198 /** {@inheritDoc} */ 199 public RegularExpressionIdentityMapperCfgClient createClientConfiguration( 200 ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl) { 201 return new RegularExpressionIdentityMapperCfgClientImpl(impl); 202 } 203 204 205 206 /** {@inheritDoc} */ 207 public RegularExpressionIdentityMapperCfg createServerConfiguration( 208 ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl) { 209 return new RegularExpressionIdentityMapperCfgServerImpl(impl); 210 } 211 212 213 214 /** {@inheritDoc} */ 215 public Class<RegularExpressionIdentityMapperCfg> getServerConfigurationClass() { 216 return RegularExpressionIdentityMapperCfg.class; 217 } 218 219 220 221 /** 222 * Get the "enabled" property definition. 223 * <p> 224 * Indicates whether the Regular Expression Identity Mapper is 225 * enabled for use. 226 * 227 * @return Returns the "enabled" property definition. 228 */ 229 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 230 return IdentityMapperCfgDefn.getInstance().getEnabledPropertyDefinition(); 231 } 232 233 234 235 /** 236 * Get the "java-class" property definition. 237 * <p> 238 * Specifies the fully-qualified name of the Java class that 239 * provides the Regular Expression Identity Mapper implementation. 240 * 241 * @return Returns the "java-class" property definition. 242 */ 243 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 244 return PD_JAVA_CLASS; 245 } 246 247 248 249 /** 250 * Get the "match-attribute" property definition. 251 * <p> 252 * Specifies the name or OID of the attribute whose value should 253 * match the provided identifier string after it has been processed 254 * by the associated regular expression. 255 * <p> 256 * All values must refer to the name or OID of an attribute type 257 * defined in the directory server schema. If multiple attributes or 258 * OIDs are provided, at least one of those attributes must contain 259 * the provided ID string value in exactly one entry. 260 * 261 * @return Returns the "match-attribute" property definition. 262 */ 263 public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() { 264 return PD_MATCH_ATTRIBUTE; 265 } 266 267 268 269 /** 270 * Get the "match-base-dn" property definition. 271 * <p> 272 * Specifies the base DN(s) that should be used when performing 273 * searches to map the provided ID string to a user entry. If 274 * multiple values are given, searches are performed below all the 275 * specified base DNs. 276 * 277 * @return Returns the "match-base-dn" property definition. 278 */ 279 public DNPropertyDefinition getMatchBaseDNPropertyDefinition() { 280 return PD_MATCH_BASE_DN; 281 } 282 283 284 285 /** 286 * Get the "match-pattern" property definition. 287 * <p> 288 * Specifies the regular expression pattern that is used to identify 289 * portions of the ID string that will be replaced. 290 * <p> 291 * Any portion of the ID string that matches this pattern is 292 * replaced in accordance with the provided replace pattern (or is 293 * removed if no replace pattern is specified). If multiple 294 * substrings within the given ID string match this pattern, all 295 * occurrences are replaced. If no part of the given ID string 296 * matches this pattern, the ID string is not altered. Exactly one 297 * match pattern value must be provided, and it must be a valid 298 * regular expression as described in the API documentation for the 299 * java.util.regex.Pattern class, including support for capturing 300 * groups. 301 * 302 * @return Returns the "match-pattern" property definition. 303 */ 304 public StringPropertyDefinition getMatchPatternPropertyDefinition() { 305 return PD_MATCH_PATTERN; 306 } 307 308 309 310 /** 311 * Get the "replace-pattern" property definition. 312 * <p> 313 * Specifies the replacement pattern that should be used for 314 * substrings in the ID string that match the provided regular 315 * expression pattern. 316 * <p> 317 * If no replacement pattern is provided, then any matching portions 318 * of the ID string will be removed (i.e., replaced with an empty 319 * string). The replacement pattern may include a string from a 320 * capturing group by using a dollar sign ($) followed by an integer 321 * value that indicates which capturing group should be used. 322 * 323 * @return Returns the "replace-pattern" property definition. 324 */ 325 public StringPropertyDefinition getReplacePatternPropertyDefinition() { 326 return PD_REPLACE_PATTERN; 327 } 328 329 330 331 /** 332 * Managed object client implementation. 333 */ 334 private static class RegularExpressionIdentityMapperCfgClientImpl implements 335 RegularExpressionIdentityMapperCfgClient { 336 337 /** Private implementation. */ 338 private ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl; 339 340 341 342 /** Private constructor. */ 343 private RegularExpressionIdentityMapperCfgClientImpl( 344 ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl) { 345 this.impl = impl; 346 } 347 348 349 350 /** {@inheritDoc} */ 351 public Boolean isEnabled() { 352 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public void setEnabled(boolean value) { 359 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 360 } 361 362 363 364 /** {@inheritDoc} */ 365 public String getJavaClass() { 366 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 367 } 368 369 370 371 /** {@inheritDoc} */ 372 public void setJavaClass(String value) { 373 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 374 } 375 376 377 378 /** {@inheritDoc} */ 379 public SortedSet<AttributeType> getMatchAttribute() { 380 return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition()); 381 } 382 383 384 385 /** {@inheritDoc} */ 386 public void setMatchAttribute(Collection<AttributeType> values) { 387 impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values); 388 } 389 390 391 392 /** {@inheritDoc} */ 393 public SortedSet<DN> getMatchBaseDN() { 394 return impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition()); 395 } 396 397 398 399 /** {@inheritDoc} */ 400 public void setMatchBaseDN(Collection<DN> values) { 401 impl.setPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition(), values); 402 } 403 404 405 406 /** {@inheritDoc} */ 407 public String getMatchPattern() { 408 return impl.getPropertyValue(INSTANCE.getMatchPatternPropertyDefinition()); 409 } 410 411 412 413 /** {@inheritDoc} */ 414 public void setMatchPattern(String value) { 415 impl.setPropertyValue(INSTANCE.getMatchPatternPropertyDefinition(), value); 416 } 417 418 419 420 /** {@inheritDoc} */ 421 public String getReplacePattern() { 422 return impl.getPropertyValue(INSTANCE.getReplacePatternPropertyDefinition()); 423 } 424 425 426 427 /** {@inheritDoc} */ 428 public void setReplacePattern(String value) { 429 impl.setPropertyValue(INSTANCE.getReplacePatternPropertyDefinition(), value); 430 } 431 432 433 434 /** {@inheritDoc} */ 435 public ManagedObjectDefinition<? extends RegularExpressionIdentityMapperCfgClient, ? extends RegularExpressionIdentityMapperCfg> definition() { 436 return INSTANCE; 437 } 438 439 440 441 /** {@inheritDoc} */ 442 public PropertyProvider properties() { 443 return impl; 444 } 445 446 447 448 /** {@inheritDoc} */ 449 public void commit() throws ManagedObjectAlreadyExistsException, 450 MissingMandatoryPropertiesException, ConcurrentModificationException, 451 OperationRejectedException, LdapException { 452 impl.commit(); 453 } 454 455 456 457 /** {@inheritDoc} */ 458 public String toString() { 459 return impl.toString(); 460 } 461 } 462 463 464 465 /** 466 * Managed object server implementation. 467 */ 468 private static class RegularExpressionIdentityMapperCfgServerImpl implements 469 RegularExpressionIdentityMapperCfg { 470 471 /** Private implementation. */ 472 private ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl; 473 474 /** The value of the "enabled" property. */ 475 private final boolean pEnabled; 476 477 /** The value of the "java-class" property. */ 478 private final String pJavaClass; 479 480 /** The value of the "match-attribute" property. */ 481 private final SortedSet<AttributeType> pMatchAttribute; 482 483 /** The value of the "match-base-dn" property. */ 484 private final SortedSet<DN> pMatchBaseDN; 485 486 /** The value of the "match-pattern" property. */ 487 private final String pMatchPattern; 488 489 /** The value of the "replace-pattern" property. */ 490 private final String pReplacePattern; 491 492 493 494 /** Private constructor. */ 495 private RegularExpressionIdentityMapperCfgServerImpl(ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl) { 496 this.impl = impl; 497 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 498 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 499 this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition()); 500 this.pMatchBaseDN = impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition()); 501 this.pMatchPattern = impl.getPropertyValue(INSTANCE.getMatchPatternPropertyDefinition()); 502 this.pReplacePattern = impl.getPropertyValue(INSTANCE.getReplacePatternPropertyDefinition()); 503 } 504 505 506 507 /** {@inheritDoc} */ 508 public void addRegularExpressionChangeListener( 509 ConfigurationChangeListener<RegularExpressionIdentityMapperCfg> listener) { 510 impl.registerChangeListener(listener); 511 } 512 513 514 515 /** {@inheritDoc} */ 516 public void removeRegularExpressionChangeListener( 517 ConfigurationChangeListener<RegularExpressionIdentityMapperCfg> listener) { 518 impl.deregisterChangeListener(listener); 519 } 520 /** {@inheritDoc} */ 521 public void addChangeListener( 522 ConfigurationChangeListener<IdentityMapperCfg> listener) { 523 impl.registerChangeListener(listener); 524 } 525 526 527 528 /** {@inheritDoc} */ 529 public void removeChangeListener( 530 ConfigurationChangeListener<IdentityMapperCfg> listener) { 531 impl.deregisterChangeListener(listener); 532 } 533 534 535 536 /** {@inheritDoc} */ 537 public boolean isEnabled() { 538 return pEnabled; 539 } 540 541 542 543 /** {@inheritDoc} */ 544 public String getJavaClass() { 545 return pJavaClass; 546 } 547 548 549 550 /** {@inheritDoc} */ 551 public SortedSet<AttributeType> getMatchAttribute() { 552 return pMatchAttribute; 553 } 554 555 556 557 /** {@inheritDoc} */ 558 public SortedSet<DN> getMatchBaseDN() { 559 return pMatchBaseDN; 560 } 561 562 563 564 /** {@inheritDoc} */ 565 public String getMatchPattern() { 566 return pMatchPattern; 567 } 568 569 570 571 /** {@inheritDoc} */ 572 public String getReplacePattern() { 573 return pReplacePattern; 574 } 575 576 577 578 /** {@inheritDoc} */ 579 public Class<? extends RegularExpressionIdentityMapperCfg> configurationClass() { 580 return RegularExpressionIdentityMapperCfg.class; 581 } 582 583 584 585 /** {@inheritDoc} */ 586 public DN dn() { 587 return impl.getDN(); 588 } 589 590 591 592 /** {@inheritDoc} */ 593 public String toString() { 594 return impl.toString(); 595 } 596 } 597}