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 org.forgerock.opendj.config.AdministratorAction; 021import org.forgerock.opendj.config.AggregationPropertyDefinition; 022import org.forgerock.opendj.config.BooleanPropertyDefinition; 023import org.forgerock.opendj.config.ClassPropertyDefinition; 024import org.forgerock.opendj.config.client.ConcurrentModificationException; 025import org.forgerock.opendj.config.client.ManagedObject; 026import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 027import org.forgerock.opendj.config.client.OperationRejectedException; 028import org.forgerock.opendj.config.conditions.Conditions; 029import org.forgerock.opendj.config.DefaultBehaviorProvider; 030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 031import org.forgerock.opendj.config.GenericConstraint; 032import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 033import org.forgerock.opendj.config.ManagedObjectDefinition; 034import org.forgerock.opendj.config.PropertyOption; 035import org.forgerock.opendj.config.PropertyProvider; 036import org.forgerock.opendj.config.server.ConfigurationChangeListener; 037import org.forgerock.opendj.config.server.ServerManagedObject; 038import org.forgerock.opendj.config.StringPropertyDefinition; 039import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 040import org.forgerock.opendj.ldap.DN; 041import org.forgerock.opendj.ldap.LdapException; 042import org.forgerock.opendj.server.config.client.HTTPBasicAuthorizationMechanismCfgClient; 043import org.forgerock.opendj.server.config.client.IdentityMapperCfgClient; 044import org.forgerock.opendj.server.config.server.HTTPAuthorizationMechanismCfg; 045import org.forgerock.opendj.server.config.server.HTTPBasicAuthorizationMechanismCfg; 046import org.forgerock.opendj.server.config.server.IdentityMapperCfg; 047 048 049 050/** 051 * An interface for querying the HTTP Basic Authorization Mechanism 052 * managed object definition meta information. 053 * <p> 054 * The HTTP Basic Authorization Mechanism authenticates the end-user 055 * using credentials extracted from the HTTP Basic 'Authorization' 056 * header. 057 */ 058public final class HTTPBasicAuthorizationMechanismCfgDefn extends ManagedObjectDefinition<HTTPBasicAuthorizationMechanismCfgClient, HTTPBasicAuthorizationMechanismCfg> { 059 060 /** The singleton configuration definition instance. */ 061 private static final HTTPBasicAuthorizationMechanismCfgDefn INSTANCE = new HTTPBasicAuthorizationMechanismCfgDefn(); 062 063 064 065 /** The "alt-authentication-enabled" property definition. */ 066 private static final BooleanPropertyDefinition PD_ALT_AUTHENTICATION_ENABLED; 067 068 069 070 /** The "alt-password-header" property definition. */ 071 private static final StringPropertyDefinition PD_ALT_PASSWORD_HEADER; 072 073 074 075 /** The "alt-username-header" property definition. */ 076 private static final StringPropertyDefinition PD_ALT_USERNAME_HEADER; 077 078 079 080 /** The "identity-mapper" property definition. */ 081 private static final AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> PD_IDENTITY_MAPPER; 082 083 084 085 /** The "java-class" property definition. */ 086 private static final ClassPropertyDefinition PD_JAVA_CLASS; 087 088 089 090 /** Build the "alt-authentication-enabled" property definition. */ 091 static { 092 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "alt-authentication-enabled"); 093 builder.setOption(PropertyOption.MANDATORY); 094 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "alt-authentication-enabled")); 095 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 096 builder.setDefaultBehaviorProvider(provider); 097 PD_ALT_AUTHENTICATION_ENABLED = builder.getInstance(); 098 INSTANCE.registerPropertyDefinition(PD_ALT_AUTHENTICATION_ENABLED); 099 } 100 101 102 103 /** Build the "alt-password-header" property definition. */ 104 static { 105 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "alt-password-header"); 106 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "alt-password-header")); 107 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 108 PD_ALT_PASSWORD_HEADER = builder.getInstance(); 109 INSTANCE.registerPropertyDefinition(PD_ALT_PASSWORD_HEADER); 110 } 111 112 113 114 /** Build the "alt-username-header" property definition. */ 115 static { 116 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "alt-username-header"); 117 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "alt-username-header")); 118 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 119 PD_ALT_USERNAME_HEADER = builder.getInstance(); 120 INSTANCE.registerPropertyDefinition(PD_ALT_USERNAME_HEADER); 121 } 122 123 124 125 /** Build the "identity-mapper" property definition. */ 126 static { 127 AggregationPropertyDefinition.Builder<IdentityMapperCfgClient, IdentityMapperCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "identity-mapper"); 128 builder.setOption(PropertyOption.MANDATORY); 129 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "identity-mapper")); 130 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 131 builder.setParentPath("/"); 132 builder.setRelationDefinition("identity-mapper"); 133 builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true")); 134 PD_IDENTITY_MAPPER = builder.getInstance(); 135 INSTANCE.registerPropertyDefinition(PD_IDENTITY_MAPPER); 136 INSTANCE.registerConstraint(PD_IDENTITY_MAPPER.getSourceConstraint()); 137 } 138 139 140 141 /** Build the "java-class" property definition. */ 142 static { 143 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 144 builder.setOption(PropertyOption.MANDATORY); 145 builder.setOption(PropertyOption.ADVANCED); 146 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 147 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.protocols.http.authz.HttpBasicAuthorizationMechanism"); 148 builder.setDefaultBehaviorProvider(provider); 149 builder.addInstanceOf("org.opends.server.protocols.http.authz.HttpAuthorizationMechanism"); 150 PD_JAVA_CLASS = builder.getInstance(); 151 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 152 } 153 154 155 156 // Register the constraints associated with this managed object definition. 157 static { 158 INSTANCE.registerConstraint(new GenericConstraint(INSTANCE, 1, Conditions.implies(Conditions.contains("alt-authentication-enabled", "true"), Conditions.implies(Conditions.isPresent("alt-username-header"), Conditions.isPresent("alt-password-header"))))); 159 } 160 161 162 163 /** 164 * Get the HTTP Basic Authorization Mechanism configuration 165 * definition singleton. 166 * 167 * @return Returns the HTTP Basic Authorization Mechanism 168 * configuration definition singleton. 169 */ 170 public static HTTPBasicAuthorizationMechanismCfgDefn getInstance() { 171 return INSTANCE; 172 } 173 174 175 176 /** 177 * Private constructor. 178 */ 179 private HTTPBasicAuthorizationMechanismCfgDefn() { 180 super("http-basic-authorization-mechanism", HTTPAuthorizationMechanismCfgDefn.getInstance()); 181 } 182 183 184 185 /** {@inheritDoc} */ 186 public HTTPBasicAuthorizationMechanismCfgClient createClientConfiguration( 187 ManagedObject<? extends HTTPBasicAuthorizationMechanismCfgClient> impl) { 188 return new HTTPBasicAuthorizationMechanismCfgClientImpl(impl); 189 } 190 191 192 193 /** {@inheritDoc} */ 194 public HTTPBasicAuthorizationMechanismCfg createServerConfiguration( 195 ServerManagedObject<? extends HTTPBasicAuthorizationMechanismCfg> impl) { 196 return new HTTPBasicAuthorizationMechanismCfgServerImpl(impl); 197 } 198 199 200 201 /** {@inheritDoc} */ 202 public Class<HTTPBasicAuthorizationMechanismCfg> getServerConfigurationClass() { 203 return HTTPBasicAuthorizationMechanismCfg.class; 204 } 205 206 207 208 /** 209 * Get the "alt-authentication-enabled" property definition. 210 * <p> 211 * Specifies whether user credentials may be provided using 212 * alternative headers to the standard 'Authorize' header. 213 * 214 * @return Returns the "alt-authentication-enabled" property definition. 215 */ 216 public BooleanPropertyDefinition getAltAuthenticationEnabledPropertyDefinition() { 217 return PD_ALT_AUTHENTICATION_ENABLED; 218 } 219 220 221 222 /** 223 * Get the "alt-password-header" property definition. 224 * <p> 225 * Alternate HTTP headers to get the user's password from. 226 * 227 * @return Returns the "alt-password-header" property definition. 228 */ 229 public StringPropertyDefinition getAltPasswordHeaderPropertyDefinition() { 230 return PD_ALT_PASSWORD_HEADER; 231 } 232 233 234 235 /** 236 * Get the "alt-username-header" property definition. 237 * <p> 238 * Alternate HTTP headers to get the user's name from. 239 * 240 * @return Returns the "alt-username-header" property definition. 241 */ 242 public StringPropertyDefinition getAltUsernameHeaderPropertyDefinition() { 243 return PD_ALT_USERNAME_HEADER; 244 } 245 246 247 248 /** 249 * Get the "enabled" property definition. 250 * <p> 251 * Indicates whether the HTTP Basic Authorization Mechanism is 252 * enabled. 253 * 254 * @return Returns the "enabled" property definition. 255 */ 256 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 257 return HTTPAuthorizationMechanismCfgDefn.getInstance().getEnabledPropertyDefinition(); 258 } 259 260 261 262 /** 263 * Get the "identity-mapper" property definition. 264 * <p> 265 * > Specifies the name of the identity mapper used to get the 266 * user's entry corresponding to the user-id provided in the HTTP 267 * authentication header. 268 * 269 * @return Returns the "identity-mapper" property definition. 270 */ 271 public AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> getIdentityMapperPropertyDefinition() { 272 return PD_IDENTITY_MAPPER; 273 } 274 275 276 277 /** 278 * Get the "java-class" property definition. 279 * <p> 280 * Specifies the fully-qualified name of the Java class that 281 * provides the HTTP Basic Authorization Mechanism implementation. 282 * 283 * @return Returns the "java-class" property definition. 284 */ 285 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 286 return PD_JAVA_CLASS; 287 } 288 289 290 291 /** 292 * Managed object client implementation. 293 */ 294 private static class HTTPBasicAuthorizationMechanismCfgClientImpl implements 295 HTTPBasicAuthorizationMechanismCfgClient { 296 297 /** Private implementation. */ 298 private ManagedObject<? extends HTTPBasicAuthorizationMechanismCfgClient> impl; 299 300 301 302 /** Private constructor. */ 303 private HTTPBasicAuthorizationMechanismCfgClientImpl( 304 ManagedObject<? extends HTTPBasicAuthorizationMechanismCfgClient> impl) { 305 this.impl = impl; 306 } 307 308 309 310 /** {@inheritDoc} */ 311 public boolean isAltAuthenticationEnabled() { 312 return impl.getPropertyValue(INSTANCE.getAltAuthenticationEnabledPropertyDefinition()); 313 } 314 315 316 317 /** {@inheritDoc} */ 318 public void setAltAuthenticationEnabled(boolean value) { 319 impl.setPropertyValue(INSTANCE.getAltAuthenticationEnabledPropertyDefinition(), value); 320 } 321 322 323 324 /** {@inheritDoc} */ 325 public String getAltPasswordHeader() { 326 return impl.getPropertyValue(INSTANCE.getAltPasswordHeaderPropertyDefinition()); 327 } 328 329 330 331 /** {@inheritDoc} */ 332 public void setAltPasswordHeader(String value) { 333 impl.setPropertyValue(INSTANCE.getAltPasswordHeaderPropertyDefinition(), value); 334 } 335 336 337 338 /** {@inheritDoc} */ 339 public String getAltUsernameHeader() { 340 return impl.getPropertyValue(INSTANCE.getAltUsernameHeaderPropertyDefinition()); 341 } 342 343 344 345 /** {@inheritDoc} */ 346 public void setAltUsernameHeader(String value) { 347 impl.setPropertyValue(INSTANCE.getAltUsernameHeaderPropertyDefinition(), value); 348 } 349 350 351 352 /** {@inheritDoc} */ 353 public Boolean isEnabled() { 354 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 355 } 356 357 358 359 /** {@inheritDoc} */ 360 public void setEnabled(boolean value) { 361 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 362 } 363 364 365 366 /** {@inheritDoc} */ 367 public String getIdentityMapper() { 368 return impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition()); 369 } 370 371 372 373 /** {@inheritDoc} */ 374 public void setIdentityMapper(String value) { 375 impl.setPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition(), value); 376 } 377 378 379 380 /** {@inheritDoc} */ 381 public String getJavaClass() { 382 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 383 } 384 385 386 387 /** {@inheritDoc} */ 388 public void setJavaClass(String value) { 389 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 390 } 391 392 393 394 /** {@inheritDoc} */ 395 public ManagedObjectDefinition<? extends HTTPBasicAuthorizationMechanismCfgClient, ? extends HTTPBasicAuthorizationMechanismCfg> definition() { 396 return INSTANCE; 397 } 398 399 400 401 /** {@inheritDoc} */ 402 public PropertyProvider properties() { 403 return impl; 404 } 405 406 407 408 /** {@inheritDoc} */ 409 public void commit() throws ManagedObjectAlreadyExistsException, 410 MissingMandatoryPropertiesException, ConcurrentModificationException, 411 OperationRejectedException, LdapException { 412 impl.commit(); 413 } 414 415 416 417 /** {@inheritDoc} */ 418 public String toString() { 419 return impl.toString(); 420 } 421 } 422 423 424 425 /** 426 * Managed object server implementation. 427 */ 428 private static class HTTPBasicAuthorizationMechanismCfgServerImpl implements 429 HTTPBasicAuthorizationMechanismCfg { 430 431 /** Private implementation. */ 432 private ServerManagedObject<? extends HTTPBasicAuthorizationMechanismCfg> impl; 433 434 /** The value of the "alt-authentication-enabled" property. */ 435 private final boolean pAltAuthenticationEnabled; 436 437 /** The value of the "alt-password-header" property. */ 438 private final String pAltPasswordHeader; 439 440 /** The value of the "alt-username-header" property. */ 441 private final String pAltUsernameHeader; 442 443 /** The value of the "enabled" property. */ 444 private final boolean pEnabled; 445 446 /** The value of the "identity-mapper" property. */ 447 private final String pIdentityMapper; 448 449 /** The value of the "java-class" property. */ 450 private final String pJavaClass; 451 452 453 454 /** Private constructor. */ 455 private HTTPBasicAuthorizationMechanismCfgServerImpl(ServerManagedObject<? extends HTTPBasicAuthorizationMechanismCfg> impl) { 456 this.impl = impl; 457 this.pAltAuthenticationEnabled = impl.getPropertyValue(INSTANCE.getAltAuthenticationEnabledPropertyDefinition()); 458 this.pAltPasswordHeader = impl.getPropertyValue(INSTANCE.getAltPasswordHeaderPropertyDefinition()); 459 this.pAltUsernameHeader = impl.getPropertyValue(INSTANCE.getAltUsernameHeaderPropertyDefinition()); 460 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 461 this.pIdentityMapper = impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition()); 462 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 463 } 464 465 466 467 /** {@inheritDoc} */ 468 public void addHTTPBasicAuthorizationMechanismChangeListener( 469 ConfigurationChangeListener<HTTPBasicAuthorizationMechanismCfg> listener) { 470 impl.registerChangeListener(listener); 471 } 472 473 474 475 /** {@inheritDoc} */ 476 public void removeHTTPBasicAuthorizationMechanismChangeListener( 477 ConfigurationChangeListener<HTTPBasicAuthorizationMechanismCfg> listener) { 478 impl.deregisterChangeListener(listener); 479 } 480 /** {@inheritDoc} */ 481 public void addChangeListener( 482 ConfigurationChangeListener<HTTPAuthorizationMechanismCfg> listener) { 483 impl.registerChangeListener(listener); 484 } 485 486 487 488 /** {@inheritDoc} */ 489 public void removeChangeListener( 490 ConfigurationChangeListener<HTTPAuthorizationMechanismCfg> listener) { 491 impl.deregisterChangeListener(listener); 492 } 493 494 495 496 /** {@inheritDoc} */ 497 public boolean isAltAuthenticationEnabled() { 498 return pAltAuthenticationEnabled; 499 } 500 501 502 503 /** {@inheritDoc} */ 504 public String getAltPasswordHeader() { 505 return pAltPasswordHeader; 506 } 507 508 509 510 /** {@inheritDoc} */ 511 public String getAltUsernameHeader() { 512 return pAltUsernameHeader; 513 } 514 515 516 517 /** {@inheritDoc} */ 518 public boolean isEnabled() { 519 return pEnabled; 520 } 521 522 523 524 /** {@inheritDoc} */ 525 public String getIdentityMapper() { 526 return pIdentityMapper; 527 } 528 529 530 531 /** 532 * {@inheritDoc} 533 */ 534 public DN getIdentityMapperDN() { 535 String value = getIdentityMapper(); 536 if (value == null) return null; 537 return INSTANCE.getIdentityMapperPropertyDefinition().getChildDN(value); 538 } 539 540 541 542 /** {@inheritDoc} */ 543 public String getJavaClass() { 544 return pJavaClass; 545 } 546 547 548 549 /** {@inheritDoc} */ 550 public Class<? extends HTTPBasicAuthorizationMechanismCfg> configurationClass() { 551 return HTTPBasicAuthorizationMechanismCfg.class; 552 } 553 554 555 556 /** {@inheritDoc} */ 557 public DN dn() { 558 return impl.getDN(); 559 } 560 561 562 563 /** {@inheritDoc} */ 564 public String toString() { 565 return impl.toString(); 566 } 567 } 568}