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