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.BooleanPropertyDefinition; 034import org.forgerock.opendj.config.ClassPropertyDefinition; 035import org.forgerock.opendj.config.client.ConcurrentModificationException; 036import org.forgerock.opendj.config.client.ManagedObject; 037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 038import org.forgerock.opendj.config.client.OperationRejectedException; 039import org.forgerock.opendj.config.DefaultBehaviorProvider; 040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 041import org.forgerock.opendj.config.DurationPropertyDefinition; 042import org.forgerock.opendj.config.IPAddressMaskPropertyDefinition; 043import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 044import org.forgerock.opendj.config.ManagedObjectDefinition; 045import org.forgerock.opendj.config.PropertyOption; 046import org.forgerock.opendj.config.PropertyProvider; 047import org.forgerock.opendj.config.server.ConfigurationChangeListener; 048import org.forgerock.opendj.config.server.ServerManagedObject; 049import org.forgerock.opendj.config.StringPropertyDefinition; 050import org.forgerock.opendj.config.Tag; 051import org.forgerock.opendj.ldap.AddressMask; 052import org.forgerock.opendj.ldap.DN; 053import org.forgerock.opendj.ldap.LdapException; 054import org.forgerock.opendj.server.config.client.LDIFConnectionHandlerCfgClient; 055import org.forgerock.opendj.server.config.server.ConnectionHandlerCfg; 056import org.forgerock.opendj.server.config.server.LDIFConnectionHandlerCfg; 057 058 059 060/** 061 * An interface for querying the LDIF Connection Handler managed 062 * object definition meta information. 063 * <p> 064 * The LDIF Connection Handler is used to process changes in the 065 * server using internal operations, where the changes to process are 066 * read from an LDIF file. 067 */ 068public final class LDIFConnectionHandlerCfgDefn extends ManagedObjectDefinition<LDIFConnectionHandlerCfgClient, LDIFConnectionHandlerCfg> { 069 070 /** The singleton configuration definition instance. */ 071 private static final LDIFConnectionHandlerCfgDefn INSTANCE = new LDIFConnectionHandlerCfgDefn(); 072 073 074 075 /** The "java-class" property definition. */ 076 private static final ClassPropertyDefinition PD_JAVA_CLASS; 077 078 079 080 /** The "ldif-directory" property definition. */ 081 private static final StringPropertyDefinition PD_LDIF_DIRECTORY; 082 083 084 085 /** The "poll-interval" property definition. */ 086 private static final DurationPropertyDefinition PD_POLL_INTERVAL; 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.COMPONENT_RESTART, INSTANCE, "java-class")); 096 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.protocols.LDIFConnectionHandler"); 097 builder.setDefaultBehaviorProvider(provider); 098 builder.addInstanceOf("org.opends.server.api.ConnectionHandler"); 099 PD_JAVA_CLASS = builder.getInstance(); 100 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 101 } 102 103 104 105 /** Build the "ldif-directory" property definition. */ 106 static { 107 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "ldif-directory"); 108 builder.setOption(PropertyOption.MANDATORY); 109 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "ldif-directory")); 110 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("config/auto-process-ldif"); 111 builder.setDefaultBehaviorProvider(provider); 112 PD_LDIF_DIRECTORY = builder.getInstance(); 113 INSTANCE.registerPropertyDefinition(PD_LDIF_DIRECTORY); 114 } 115 116 117 118 /** Build the "poll-interval" property definition. */ 119 static { 120 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "poll-interval"); 121 builder.setOption(PropertyOption.MANDATORY); 122 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "poll-interval")); 123 DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("5 seconds"); 124 builder.setDefaultBehaviorProvider(provider); 125 builder.setBaseUnit("ms"); 126 builder.setLowerLimit("1"); 127 PD_POLL_INTERVAL = builder.getInstance(); 128 INSTANCE.registerPropertyDefinition(PD_POLL_INTERVAL); 129 } 130 131 132 133 // Register the tags associated with this managed object definition. 134 static { 135 INSTANCE.registerTag(Tag.valueOf("core-server")); 136 } 137 138 139 140 /** 141 * Get the LDIF Connection Handler configuration definition 142 * singleton. 143 * 144 * @return Returns the LDIF Connection Handler configuration 145 * definition singleton. 146 */ 147 public static LDIFConnectionHandlerCfgDefn getInstance() { 148 return INSTANCE; 149 } 150 151 152 153 /** 154 * Private constructor. 155 */ 156 private LDIFConnectionHandlerCfgDefn() { 157 super("ldif-connection-handler", ConnectionHandlerCfgDefn.getInstance()); 158 } 159 160 161 162 /** {@inheritDoc} */ 163 public LDIFConnectionHandlerCfgClient createClientConfiguration( 164 ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl) { 165 return new LDIFConnectionHandlerCfgClientImpl(impl); 166 } 167 168 169 170 /** {@inheritDoc} */ 171 public LDIFConnectionHandlerCfg createServerConfiguration( 172 ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl) { 173 return new LDIFConnectionHandlerCfgServerImpl(impl); 174 } 175 176 177 178 /** {@inheritDoc} */ 179 public Class<LDIFConnectionHandlerCfg> getServerConfigurationClass() { 180 return LDIFConnectionHandlerCfg.class; 181 } 182 183 184 185 /** 186 * Get the "allowed-client" property definition. 187 * <p> 188 * Specifies a set of host names or address masks that determine the 189 * clients that are allowed to establish connections to this LDIF 190 * Connection Handler. 191 * <p> 192 * Valid values include a host name, a fully qualified domain name, 193 * a domain name, an IP address, or a subnetwork with subnetwork 194 * mask. 195 * 196 * @return Returns the "allowed-client" property definition. 197 */ 198 public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() { 199 return ConnectionHandlerCfgDefn.getInstance().getAllowedClientPropertyDefinition(); 200 } 201 202 203 204 /** 205 * Get the "denied-client" property definition. 206 * <p> 207 * Specifies a set of host names or address masks that determine the 208 * clients that are not allowed to establish connections to this LDIF 209 * Connection Handler. 210 * <p> 211 * Valid values include a host name, a fully qualified domain name, 212 * a domain name, an IP address, or a subnetwork with subnetwork 213 * mask. If both allowed and denied client masks are defined and a 214 * client connection matches one or more masks in both lists, then 215 * the connection is denied. If only a denied list is specified, then 216 * any client not matching a mask in that list is allowed. 217 * 218 * @return Returns the "denied-client" property definition. 219 */ 220 public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() { 221 return ConnectionHandlerCfgDefn.getInstance().getDeniedClientPropertyDefinition(); 222 } 223 224 225 226 /** 227 * Get the "enabled" property definition. 228 * <p> 229 * Indicates whether the LDIF Connection Handler is enabled. 230 * 231 * @return Returns the "enabled" property definition. 232 */ 233 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 234 return ConnectionHandlerCfgDefn.getInstance().getEnabledPropertyDefinition(); 235 } 236 237 238 239 /** 240 * Get the "java-class" property definition. 241 * <p> 242 * Specifies the fully-qualified name of the Java class that 243 * provides the LDIF Connection Handler implementation. 244 * 245 * @return Returns the "java-class" property definition. 246 */ 247 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 248 return PD_JAVA_CLASS; 249 } 250 251 252 253 /** 254 * Get the "ldif-directory" property definition. 255 * <p> 256 * Specifies the path to the directory in which the LDIF files 257 * should be placed. 258 * 259 * @return Returns the "ldif-directory" property definition. 260 */ 261 public StringPropertyDefinition getLDIFDirectoryPropertyDefinition() { 262 return PD_LDIF_DIRECTORY; 263 } 264 265 266 267 /** 268 * Get the "poll-interval" property definition. 269 * <p> 270 * Specifies how frequently the LDIF connection handler should check 271 * the LDIF directory to determine whether a new LDIF file has been 272 * added. 273 * 274 * @return Returns the "poll-interval" property definition. 275 */ 276 public DurationPropertyDefinition getPollIntervalPropertyDefinition() { 277 return PD_POLL_INTERVAL; 278 } 279 280 281 282 /** 283 * Managed object client implementation. 284 */ 285 private static class LDIFConnectionHandlerCfgClientImpl implements 286 LDIFConnectionHandlerCfgClient { 287 288 /** Private implementation. */ 289 private ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl; 290 291 292 293 /** Private constructor. */ 294 private LDIFConnectionHandlerCfgClientImpl( 295 ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl) { 296 this.impl = impl; 297 } 298 299 300 301 /** {@inheritDoc} */ 302 public SortedSet<AddressMask> getAllowedClient() { 303 return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 304 } 305 306 307 308 /** {@inheritDoc} */ 309 public void setAllowedClient(Collection<AddressMask> values) { 310 impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values); 311 } 312 313 314 315 /** {@inheritDoc} */ 316 public SortedSet<AddressMask> getDeniedClient() { 317 return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 318 } 319 320 321 322 /** {@inheritDoc} */ 323 public void setDeniedClient(Collection<AddressMask> values) { 324 impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values); 325 } 326 327 328 329 /** {@inheritDoc} */ 330 public Boolean isEnabled() { 331 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 332 } 333 334 335 336 /** {@inheritDoc} */ 337 public void setEnabled(boolean value) { 338 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 339 } 340 341 342 343 /** {@inheritDoc} */ 344 public String getJavaClass() { 345 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 346 } 347 348 349 350 /** {@inheritDoc} */ 351 public void setJavaClass(String value) { 352 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public String getLDIFDirectory() { 359 return impl.getPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition()); 360 } 361 362 363 364 /** {@inheritDoc} */ 365 public void setLDIFDirectory(String value) { 366 impl.setPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition(), value); 367 } 368 369 370 371 /** {@inheritDoc} */ 372 public long getPollInterval() { 373 return impl.getPropertyValue(INSTANCE.getPollIntervalPropertyDefinition()); 374 } 375 376 377 378 /** {@inheritDoc} */ 379 public void setPollInterval(long value) { 380 impl.setPropertyValue(INSTANCE.getPollIntervalPropertyDefinition(), value); 381 } 382 383 384 385 /** {@inheritDoc} */ 386 public ManagedObjectDefinition<? extends LDIFConnectionHandlerCfgClient, ? extends LDIFConnectionHandlerCfg> definition() { 387 return INSTANCE; 388 } 389 390 391 392 /** {@inheritDoc} */ 393 public PropertyProvider properties() { 394 return impl; 395 } 396 397 398 399 /** {@inheritDoc} */ 400 public void commit() throws ManagedObjectAlreadyExistsException, 401 MissingMandatoryPropertiesException, ConcurrentModificationException, 402 OperationRejectedException, LdapException { 403 impl.commit(); 404 } 405 406 407 408 /** {@inheritDoc} */ 409 public String toString() { 410 return impl.toString(); 411 } 412 } 413 414 415 416 /** 417 * Managed object server implementation. 418 */ 419 private static class LDIFConnectionHandlerCfgServerImpl implements 420 LDIFConnectionHandlerCfg { 421 422 /** Private implementation. */ 423 private ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl; 424 425 /** The value of the "allowed-client" property. */ 426 private final SortedSet<AddressMask> pAllowedClient; 427 428 /** The value of the "denied-client" property. */ 429 private final SortedSet<AddressMask> pDeniedClient; 430 431 /** The value of the "enabled" property. */ 432 private final boolean pEnabled; 433 434 /** The value of the "java-class" property. */ 435 private final String pJavaClass; 436 437 /** The value of the "ldif-directory" property. */ 438 private final String pLDIFDirectory; 439 440 /** The value of the "poll-interval" property. */ 441 private final long pPollInterval; 442 443 444 445 /** Private constructor. */ 446 private LDIFConnectionHandlerCfgServerImpl(ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl) { 447 this.impl = impl; 448 this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 449 this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 450 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 451 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 452 this.pLDIFDirectory = impl.getPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition()); 453 this.pPollInterval = impl.getPropertyValue(INSTANCE.getPollIntervalPropertyDefinition()); 454 } 455 456 457 458 /** {@inheritDoc} */ 459 public void addLDIFChangeListener( 460 ConfigurationChangeListener<LDIFConnectionHandlerCfg> listener) { 461 impl.registerChangeListener(listener); 462 } 463 464 465 466 /** {@inheritDoc} */ 467 public void removeLDIFChangeListener( 468 ConfigurationChangeListener<LDIFConnectionHandlerCfg> listener) { 469 impl.deregisterChangeListener(listener); 470 } 471 /** {@inheritDoc} */ 472 public void addChangeListener( 473 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 474 impl.registerChangeListener(listener); 475 } 476 477 478 479 /** {@inheritDoc} */ 480 public void removeChangeListener( 481 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 482 impl.deregisterChangeListener(listener); 483 } 484 485 486 487 /** {@inheritDoc} */ 488 public SortedSet<AddressMask> getAllowedClient() { 489 return pAllowedClient; 490 } 491 492 493 494 /** {@inheritDoc} */ 495 public SortedSet<AddressMask> getDeniedClient() { 496 return pDeniedClient; 497 } 498 499 500 501 /** {@inheritDoc} */ 502 public boolean isEnabled() { 503 return pEnabled; 504 } 505 506 507 508 /** {@inheritDoc} */ 509 public String getJavaClass() { 510 return pJavaClass; 511 } 512 513 514 515 /** {@inheritDoc} */ 516 public String getLDIFDirectory() { 517 return pLDIFDirectory; 518 } 519 520 521 522 /** {@inheritDoc} */ 523 public long getPollInterval() { 524 return pPollInterval; 525 } 526 527 528 529 /** {@inheritDoc} */ 530 public Class<? extends LDIFConnectionHandlerCfg> configurationClass() { 531 return LDIFConnectionHandlerCfg.class; 532 } 533 534 535 536 /** {@inheritDoc} */ 537 public DN dn() { 538 return impl.getDN(); 539 } 540 541 542 543 /** {@inheritDoc} */ 544 public String toString() { 545 return impl.toString(); 546 } 547 } 548}