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 java.util.TreeSet; 023import org.forgerock.opendj.config.AdministratorAction; 024import org.forgerock.opendj.config.AggregationPropertyDefinition; 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.conditions.Conditions; 032import org.forgerock.opendj.config.DefaultBehaviorProvider; 033import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 034import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 035import org.forgerock.opendj.config.ManagedObjectDefinition; 036import org.forgerock.opendj.config.PropertyException; 037import org.forgerock.opendj.config.PropertyOption; 038import org.forgerock.opendj.config.PropertyProvider; 039import org.forgerock.opendj.config.server.ConfigurationChangeListener; 040import org.forgerock.opendj.config.server.ServerManagedObject; 041import org.forgerock.opendj.config.StringPropertyDefinition; 042import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 043import org.forgerock.opendj.ldap.DN; 044import org.forgerock.opendj.ldap.LdapException; 045import org.forgerock.opendj.server.config.client.HTTPAuthorizationMechanismCfgClient; 046import org.forgerock.opendj.server.config.client.Rest2ldapEndpointCfgClient; 047import org.forgerock.opendj.server.config.server.HTTPAuthorizationMechanismCfg; 048import org.forgerock.opendj.server.config.server.HTTPEndpointCfg; 049import org.forgerock.opendj.server.config.server.Rest2ldapEndpointCfg; 050 051 052 053/** 054 * An interface for querying the Rest2ldap Endpoint managed object 055 * definition meta information. 056 * <p> 057 * The Rest2ldap Endpoint provides RESTful access to LDAP application 058 * data using a set of customizable data transformations. 059 */ 060public final class Rest2ldapEndpointCfgDefn extends ManagedObjectDefinition<Rest2ldapEndpointCfgClient, Rest2ldapEndpointCfg> { 061 062 /** The singleton configuration definition instance. */ 063 private static final Rest2ldapEndpointCfgDefn INSTANCE = new Rest2ldapEndpointCfgDefn(); 064 065 066 067 /** The "config-directory" property definition. */ 068 private static final StringPropertyDefinition PD_CONFIG_DIRECTORY; 069 070 071 072 /** The "java-class" property definition. */ 073 private static final ClassPropertyDefinition PD_JAVA_CLASS; 074 075 076 077 /** Build the "config-directory" property definition. */ 078 static { 079 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "config-directory"); 080 builder.setOption(PropertyOption.MANDATORY); 081 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "config-directory")); 082 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 083 builder.setPattern(".*", "DIRECTORY"); 084 PD_CONFIG_DIRECTORY = builder.getInstance(); 085 INSTANCE.registerPropertyDefinition(PD_CONFIG_DIRECTORY); 086 } 087 088 089 090 /** Build the "java-class" property definition. */ 091 static { 092 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 093 builder.setOption(PropertyOption.MANDATORY); 094 builder.setOption(PropertyOption.ADVANCED); 095 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 096 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.protocols.http.rest2ldap.Rest2LdapEndpoint"); 097 builder.setDefaultBehaviorProvider(provider); 098 builder.addInstanceOf("org.opends.server.api.HttpEndpoint"); 099 PD_JAVA_CLASS = builder.getInstance(); 100 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 101 } 102 103 104 105 /** 106 * Get the Rest2ldap Endpoint configuration definition singleton. 107 * 108 * @return Returns the Rest2ldap Endpoint configuration definition 109 * singleton. 110 */ 111 public static Rest2ldapEndpointCfgDefn getInstance() { 112 return INSTANCE; 113 } 114 115 116 117 /** 118 * Private constructor. 119 */ 120 private Rest2ldapEndpointCfgDefn() { 121 super("rest2ldap-endpoint", HTTPEndpointCfgDefn.getInstance()); 122 } 123 124 125 126 /** {@inheritDoc} */ 127 public Rest2ldapEndpointCfgClient createClientConfiguration( 128 ManagedObject<? extends Rest2ldapEndpointCfgClient> impl) { 129 return new Rest2ldapEndpointCfgClientImpl(impl); 130 } 131 132 133 134 /** {@inheritDoc} */ 135 public Rest2ldapEndpointCfg createServerConfiguration( 136 ServerManagedObject<? extends Rest2ldapEndpointCfg> impl) { 137 return new Rest2ldapEndpointCfgServerImpl(impl); 138 } 139 140 141 142 /** {@inheritDoc} */ 143 public Class<Rest2ldapEndpointCfg> getServerConfigurationClass() { 144 return Rest2ldapEndpointCfg.class; 145 } 146 147 148 149 /** 150 * Get the "authorization-mechanism" property definition. 151 * <p> 152 * The HTTP authorization mechanisms supported by this Rest2ldap 153 * Endpoint. 154 * 155 * @return Returns the "authorization-mechanism" property definition. 156 */ 157 public AggregationPropertyDefinition<HTTPAuthorizationMechanismCfgClient, HTTPAuthorizationMechanismCfg> getAuthorizationMechanismPropertyDefinition() { 158 return HTTPEndpointCfgDefn.getInstance().getAuthorizationMechanismPropertyDefinition(); 159 } 160 161 162 163 /** 164 * Get the "base-path" property definition. 165 * <p> 166 * All HTTP requests matching the base path or subordinate to it 167 * will be routed to the HTTP endpoint unless a more specific HTTP 168 * endpoint is found. 169 * 170 * @return Returns the "base-path" property definition. 171 */ 172 public StringPropertyDefinition getBasePathPropertyDefinition() { 173 return HTTPEndpointCfgDefn.getInstance().getBasePathPropertyDefinition(); 174 } 175 176 177 178 /** 179 * Get the "config-directory" property definition. 180 * <p> 181 * The directory containing the Rest2Ldap configuration file(s) for 182 * this specific endpoint. 183 * <p> 184 * The directory must be readable by the server and may contain 185 * multiple configuration files, one for each supported version of 186 * the REST endpoint. If a relative path is used then it will be 187 * resolved against the server's instance directory. 188 * 189 * @return Returns the "config-directory" property definition. 190 */ 191 public StringPropertyDefinition getConfigDirectoryPropertyDefinition() { 192 return PD_CONFIG_DIRECTORY; 193 } 194 195 196 197 /** 198 * Get the "enabled" property definition. 199 * <p> 200 * Indicates whether the Rest2ldap Endpoint is enabled. 201 * 202 * @return Returns the "enabled" property definition. 203 */ 204 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 205 return HTTPEndpointCfgDefn.getInstance().getEnabledPropertyDefinition(); 206 } 207 208 209 210 /** 211 * Get the "java-class" property definition. 212 * <p> 213 * Specifies the fully-qualified name of the Java class that 214 * provides the Rest2ldap Endpoint implementation. 215 * 216 * @return Returns the "java-class" property definition. 217 */ 218 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 219 return PD_JAVA_CLASS; 220 } 221 222 223 224 /** 225 * Managed object client implementation. 226 */ 227 private static class Rest2ldapEndpointCfgClientImpl implements 228 Rest2ldapEndpointCfgClient { 229 230 /** Private implementation. */ 231 private ManagedObject<? extends Rest2ldapEndpointCfgClient> impl; 232 233 234 235 /** Private constructor. */ 236 private Rest2ldapEndpointCfgClientImpl( 237 ManagedObject<? extends Rest2ldapEndpointCfgClient> impl) { 238 this.impl = impl; 239 } 240 241 242 243 /** {@inheritDoc} */ 244 public SortedSet<String> getAuthorizationMechanism() { 245 return impl.getPropertyValues(INSTANCE.getAuthorizationMechanismPropertyDefinition()); 246 } 247 248 249 250 /** {@inheritDoc} */ 251 public void setAuthorizationMechanism(Collection<String> values) { 252 impl.setPropertyValues(INSTANCE.getAuthorizationMechanismPropertyDefinition(), values); 253 } 254 255 256 257 /** {@inheritDoc} */ 258 public String getBasePath() { 259 return impl.getPropertyValue(INSTANCE.getBasePathPropertyDefinition()); 260 } 261 262 263 264 /** {@inheritDoc} */ 265 public void setBasePath(String value) throws PropertyException { 266 impl.setPropertyValue(INSTANCE.getBasePathPropertyDefinition(), value); 267 } 268 269 270 271 /** {@inheritDoc} */ 272 public String getConfigDirectory() { 273 return impl.getPropertyValue(INSTANCE.getConfigDirectoryPropertyDefinition()); 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public void setConfigDirectory(String value) { 280 impl.setPropertyValue(INSTANCE.getConfigDirectoryPropertyDefinition(), value); 281 } 282 283 284 285 /** {@inheritDoc} */ 286 public Boolean isEnabled() { 287 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 288 } 289 290 291 292 /** {@inheritDoc} */ 293 public void setEnabled(boolean value) { 294 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 295 } 296 297 298 299 /** {@inheritDoc} */ 300 public String getJavaClass() { 301 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 302 } 303 304 305 306 /** {@inheritDoc} */ 307 public void setJavaClass(String value) { 308 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 309 } 310 311 312 313 /** {@inheritDoc} */ 314 public ManagedObjectDefinition<? extends Rest2ldapEndpointCfgClient, ? extends Rest2ldapEndpointCfg> definition() { 315 return INSTANCE; 316 } 317 318 319 320 /** {@inheritDoc} */ 321 public PropertyProvider properties() { 322 return impl; 323 } 324 325 326 327 /** {@inheritDoc} */ 328 public void commit() throws ManagedObjectAlreadyExistsException, 329 MissingMandatoryPropertiesException, ConcurrentModificationException, 330 OperationRejectedException, LdapException { 331 impl.commit(); 332 } 333 334 335 336 /** {@inheritDoc} */ 337 public String toString() { 338 return impl.toString(); 339 } 340 } 341 342 343 344 /** 345 * Managed object server implementation. 346 */ 347 private static class Rest2ldapEndpointCfgServerImpl implements 348 Rest2ldapEndpointCfg { 349 350 /** Private implementation. */ 351 private ServerManagedObject<? extends Rest2ldapEndpointCfg> impl; 352 353 /** The value of the "authorization-mechanism" property. */ 354 private final SortedSet<String> pAuthorizationMechanism; 355 356 /** The value of the "base-path" property. */ 357 private final String pBasePath; 358 359 /** The value of the "config-directory" property. */ 360 private final String pConfigDirectory; 361 362 /** The value of the "enabled" property. */ 363 private final boolean pEnabled; 364 365 /** The value of the "java-class" property. */ 366 private final String pJavaClass; 367 368 369 370 /** Private constructor. */ 371 private Rest2ldapEndpointCfgServerImpl(ServerManagedObject<? extends Rest2ldapEndpointCfg> impl) { 372 this.impl = impl; 373 this.pAuthorizationMechanism = impl.getPropertyValues(INSTANCE.getAuthorizationMechanismPropertyDefinition()); 374 this.pBasePath = impl.getPropertyValue(INSTANCE.getBasePathPropertyDefinition()); 375 this.pConfigDirectory = impl.getPropertyValue(INSTANCE.getConfigDirectoryPropertyDefinition()); 376 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 377 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 378 } 379 380 381 382 /** {@inheritDoc} */ 383 public void addRest2ldapEndpointChangeListener( 384 ConfigurationChangeListener<Rest2ldapEndpointCfg> listener) { 385 impl.registerChangeListener(listener); 386 } 387 388 389 390 /** {@inheritDoc} */ 391 public void removeRest2ldapEndpointChangeListener( 392 ConfigurationChangeListener<Rest2ldapEndpointCfg> listener) { 393 impl.deregisterChangeListener(listener); 394 } 395 /** {@inheritDoc} */ 396 public void addChangeListener( 397 ConfigurationChangeListener<HTTPEndpointCfg> listener) { 398 impl.registerChangeListener(listener); 399 } 400 401 402 403 /** {@inheritDoc} */ 404 public void removeChangeListener( 405 ConfigurationChangeListener<HTTPEndpointCfg> listener) { 406 impl.deregisterChangeListener(listener); 407 } 408 409 410 411 /** {@inheritDoc} */ 412 public SortedSet<String> getAuthorizationMechanism() { 413 return pAuthorizationMechanism; 414 } 415 416 417 418 /** 419 * {@inheritDoc} 420 */ 421 public SortedSet<DN> getAuthorizationMechanismDNs() { 422 SortedSet<String> values = getAuthorizationMechanism(); 423 SortedSet<DN> dnValues = new TreeSet<DN>(); 424 for (String value : values) { 425 DN dn = INSTANCE.getAuthorizationMechanismPropertyDefinition().getChildDN(value); 426 dnValues.add(dn); 427 } 428 return dnValues; 429 } 430 431 432 433 /** {@inheritDoc} */ 434 public String getBasePath() { 435 return pBasePath; 436 } 437 438 439 440 /** {@inheritDoc} */ 441 public String getConfigDirectory() { 442 return pConfigDirectory; 443 } 444 445 446 447 /** {@inheritDoc} */ 448 public boolean isEnabled() { 449 return pEnabled; 450 } 451 452 453 454 /** {@inheritDoc} */ 455 public String getJavaClass() { 456 return pJavaClass; 457 } 458 459 460 461 /** {@inheritDoc} */ 462 public Class<? extends Rest2ldapEndpointCfg> configurationClass() { 463 return Rest2ldapEndpointCfg.class; 464 } 465 466 467 468 /** {@inheritDoc} */ 469 public DN dn() { 470 return impl.getDN(); 471 } 472 473 474 475 /** {@inheritDoc} */ 476 public String toString() { 477 return impl.toString(); 478 } 479 } 480}