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 /** 199 * {@inheritDoc} 200 */ 201 public RegularExpressionIdentityMapperCfgClient createClientConfiguration( 202 ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl) { 203 return new RegularExpressionIdentityMapperCfgClientImpl(impl); 204 } 205 206 207 208 /** 209 * {@inheritDoc} 210 */ 211 public RegularExpressionIdentityMapperCfg createServerConfiguration( 212 ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl) { 213 return new RegularExpressionIdentityMapperCfgServerImpl(impl); 214 } 215 216 217 218 /** 219 * {@inheritDoc} 220 */ 221 public Class<RegularExpressionIdentityMapperCfg> getServerConfigurationClass() { 222 return RegularExpressionIdentityMapperCfg.class; 223 } 224 225 226 227 /** 228 * Get the "enabled" property definition. 229 * <p> 230 * Indicates whether the Regular Expression Identity Mapper is 231 * enabled for use. 232 * 233 * @return Returns the "enabled" property definition. 234 */ 235 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 236 return IdentityMapperCfgDefn.getInstance().getEnabledPropertyDefinition(); 237 } 238 239 240 241 /** 242 * Get the "java-class" property definition. 243 * <p> 244 * Specifies the fully-qualified name of the Java class that 245 * provides the Regular Expression Identity Mapper implementation. 246 * 247 * @return Returns the "java-class" property definition. 248 */ 249 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 250 return PD_JAVA_CLASS; 251 } 252 253 254 255 /** 256 * Get the "match-attribute" property definition. 257 * <p> 258 * Specifies the name or OID of the attribute whose value should 259 * match the provided identifier string after it has been processed 260 * by the associated regular expression. 261 * <p> 262 * All values must refer to the name or OID of an attribute type 263 * defined in the directory server schema. If multiple attributes or 264 * OIDs are provided, at least one of those attributes must contain 265 * the provided ID string value in exactly one entry. 266 * 267 * @return Returns the "match-attribute" property definition. 268 */ 269 public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() { 270 return PD_MATCH_ATTRIBUTE; 271 } 272 273 274 275 /** 276 * Get the "match-base-dn" property definition. 277 * <p> 278 * Specifies the base DN(s) that should be used when performing 279 * searches to map the provided ID string to a user entry. If 280 * multiple values are given, searches are performed below all the 281 * specified base DNs. 282 * 283 * @return Returns the "match-base-dn" property definition. 284 */ 285 public DNPropertyDefinition getMatchBaseDNPropertyDefinition() { 286 return PD_MATCH_BASE_DN; 287 } 288 289 290 291 /** 292 * Get the "match-pattern" property definition. 293 * <p> 294 * Specifies the regular expression pattern that is used to identify 295 * portions of the ID string that will be replaced. 296 * <p> 297 * Any portion of the ID string that matches this pattern is 298 * replaced in accordance with the provided replace pattern (or is 299 * removed if no replace pattern is specified). If multiple 300 * substrings within the given ID string match this pattern, all 301 * occurrences are replaced. If no part of the given ID string 302 * matches this pattern, the ID string is not altered. Exactly one 303 * match pattern value must be provided, and it must be a valid 304 * regular expression as described in the API documentation for the 305 * java.util.regex.Pattern class, including support for capturing 306 * groups. 307 * 308 * @return Returns the "match-pattern" property definition. 309 */ 310 public StringPropertyDefinition getMatchPatternPropertyDefinition() { 311 return PD_MATCH_PATTERN; 312 } 313 314 315 316 /** 317 * Get the "replace-pattern" property definition. 318 * <p> 319 * Specifies the replacement pattern that should be used for 320 * substrings in the ID string that match the provided regular 321 * expression pattern. 322 * <p> 323 * If no replacement pattern is provided, then any matching portions 324 * of the ID string will be removed (i.e., replaced with an empty 325 * string). The replacement pattern may include a string from a 326 * capturing group by using a dollar sign ($) followed by an integer 327 * value that indicates which capturing group should be used. 328 * 329 * @return Returns the "replace-pattern" property definition. 330 */ 331 public StringPropertyDefinition getReplacePatternPropertyDefinition() { 332 return PD_REPLACE_PATTERN; 333 } 334 335 336 337 /** 338 * Managed object client implementation. 339 */ 340 private static class RegularExpressionIdentityMapperCfgClientImpl implements 341 RegularExpressionIdentityMapperCfgClient { 342 343 // Private implementation. 344 private ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl; 345 346 347 348 // Private constructor. 349 private RegularExpressionIdentityMapperCfgClientImpl( 350 ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl) { 351 this.impl = impl; 352 } 353 354 355 356 /** 357 * {@inheritDoc} 358 */ 359 public Boolean isEnabled() { 360 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 361 } 362 363 364 365 /** 366 * {@inheritDoc} 367 */ 368 public void setEnabled(boolean value) { 369 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 370 } 371 372 373 374 /** 375 * {@inheritDoc} 376 */ 377 public String getJavaClass() { 378 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 379 } 380 381 382 383 /** 384 * {@inheritDoc} 385 */ 386 public void setJavaClass(String value) { 387 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 388 } 389 390 391 392 /** 393 * {@inheritDoc} 394 */ 395 public SortedSet<AttributeType> getMatchAttribute() { 396 return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition()); 397 } 398 399 400 401 /** 402 * {@inheritDoc} 403 */ 404 public void setMatchAttribute(Collection<AttributeType> values) { 405 impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values); 406 } 407 408 409 410 /** 411 * {@inheritDoc} 412 */ 413 public SortedSet<DN> getMatchBaseDN() { 414 return impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition()); 415 } 416 417 418 419 /** 420 * {@inheritDoc} 421 */ 422 public void setMatchBaseDN(Collection<DN> values) { 423 impl.setPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition(), values); 424 } 425 426 427 428 /** 429 * {@inheritDoc} 430 */ 431 public String getMatchPattern() { 432 return impl.getPropertyValue(INSTANCE.getMatchPatternPropertyDefinition()); 433 } 434 435 436 437 /** 438 * {@inheritDoc} 439 */ 440 public void setMatchPattern(String value) { 441 impl.setPropertyValue(INSTANCE.getMatchPatternPropertyDefinition(), value); 442 } 443 444 445 446 /** 447 * {@inheritDoc} 448 */ 449 public String getReplacePattern() { 450 return impl.getPropertyValue(INSTANCE.getReplacePatternPropertyDefinition()); 451 } 452 453 454 455 /** 456 * {@inheritDoc} 457 */ 458 public void setReplacePattern(String value) { 459 impl.setPropertyValue(INSTANCE.getReplacePatternPropertyDefinition(), value); 460 } 461 462 463 464 /** 465 * {@inheritDoc} 466 */ 467 public ManagedObjectDefinition<? extends RegularExpressionIdentityMapperCfgClient, ? extends RegularExpressionIdentityMapperCfg> definition() { 468 return INSTANCE; 469 } 470 471 472 473 /** 474 * {@inheritDoc} 475 */ 476 public PropertyProvider properties() { 477 return impl; 478 } 479 480 481 482 /** 483 * {@inheritDoc} 484 */ 485 public void commit() throws ManagedObjectAlreadyExistsException, 486 MissingMandatoryPropertiesException, ConcurrentModificationException, 487 OperationRejectedException, LdapException { 488 impl.commit(); 489 } 490 491 } 492 493 494 495 /** 496 * Managed object server implementation. 497 */ 498 private static class RegularExpressionIdentityMapperCfgServerImpl implements 499 RegularExpressionIdentityMapperCfg { 500 501 // Private implementation. 502 private ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl; 503 504 // The value of the "enabled" property. 505 private final boolean pEnabled; 506 507 // The value of the "java-class" property. 508 private final String pJavaClass; 509 510 // The value of the "match-attribute" property. 511 private final SortedSet<AttributeType> pMatchAttribute; 512 513 // The value of the "match-base-dn" property. 514 private final SortedSet<DN> pMatchBaseDN; 515 516 // The value of the "match-pattern" property. 517 private final String pMatchPattern; 518 519 // The value of the "replace-pattern" property. 520 private final String pReplacePattern; 521 522 523 524 // Private constructor. 525 private RegularExpressionIdentityMapperCfgServerImpl(ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl) { 526 this.impl = impl; 527 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 528 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 529 this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition()); 530 this.pMatchBaseDN = impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition()); 531 this.pMatchPattern = impl.getPropertyValue(INSTANCE.getMatchPatternPropertyDefinition()); 532 this.pReplacePattern = impl.getPropertyValue(INSTANCE.getReplacePatternPropertyDefinition()); 533 } 534 535 536 537 /** 538 * {@inheritDoc} 539 */ 540 public void addRegularExpressionChangeListener( 541 ConfigurationChangeListener<RegularExpressionIdentityMapperCfg> listener) { 542 impl.registerChangeListener(listener); 543 } 544 545 546 547 /** 548 * {@inheritDoc} 549 */ 550 public void removeRegularExpressionChangeListener( 551 ConfigurationChangeListener<RegularExpressionIdentityMapperCfg> listener) { 552 impl.deregisterChangeListener(listener); 553 } 554 /** 555 * {@inheritDoc} 556 */ 557 public void addChangeListener( 558 ConfigurationChangeListener<IdentityMapperCfg> listener) { 559 impl.registerChangeListener(listener); 560 } 561 562 563 564 /** 565 * {@inheritDoc} 566 */ 567 public void removeChangeListener( 568 ConfigurationChangeListener<IdentityMapperCfg> listener) { 569 impl.deregisterChangeListener(listener); 570 } 571 572 573 574 /** 575 * {@inheritDoc} 576 */ 577 public boolean isEnabled() { 578 return pEnabled; 579 } 580 581 582 583 /** 584 * {@inheritDoc} 585 */ 586 public String getJavaClass() { 587 return pJavaClass; 588 } 589 590 591 592 /** 593 * {@inheritDoc} 594 */ 595 public SortedSet<AttributeType> getMatchAttribute() { 596 return pMatchAttribute; 597 } 598 599 600 601 /** 602 * {@inheritDoc} 603 */ 604 public SortedSet<DN> getMatchBaseDN() { 605 return pMatchBaseDN; 606 } 607 608 609 610 /** 611 * {@inheritDoc} 612 */ 613 public String getMatchPattern() { 614 return pMatchPattern; 615 } 616 617 618 619 /** 620 * {@inheritDoc} 621 */ 622 public String getReplacePattern() { 623 return pReplacePattern; 624 } 625 626 627 628 /** 629 * {@inheritDoc} 630 */ 631 public Class<? extends RegularExpressionIdentityMapperCfg> configurationClass() { 632 return RegularExpressionIdentityMapperCfg.class; 633 } 634 635 636 637 /** 638 * {@inheritDoc} 639 */ 640 public DN dn() { 641 return impl.getDN(); 642 } 643 644 } 645}