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