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 /** 163 * {@inheritDoc} 164 */ 165 public LDIFConnectionHandlerCfgClient createClientConfiguration( 166 ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl) { 167 return new LDIFConnectionHandlerCfgClientImpl(impl); 168 } 169 170 171 172 /** 173 * {@inheritDoc} 174 */ 175 public LDIFConnectionHandlerCfg createServerConfiguration( 176 ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl) { 177 return new LDIFConnectionHandlerCfgServerImpl(impl); 178 } 179 180 181 182 /** 183 * {@inheritDoc} 184 */ 185 public Class<LDIFConnectionHandlerCfg> getServerConfigurationClass() { 186 return LDIFConnectionHandlerCfg.class; 187 } 188 189 190 191 /** 192 * Get the "allowed-client" property definition. 193 * <p> 194 * Specifies a set of host names or address masks that determine the 195 * clients that are allowed to establish connections to this LDIF 196 * Connection Handler. 197 * <p> 198 * Valid values include a host name, a fully qualified domain name, 199 * a domain name, an IP address, or a subnetwork with subnetwork 200 * mask. 201 * 202 * @return Returns the "allowed-client" property definition. 203 */ 204 public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() { 205 return ConnectionHandlerCfgDefn.getInstance().getAllowedClientPropertyDefinition(); 206 } 207 208 209 210 /** 211 * Get the "denied-client" property definition. 212 * <p> 213 * Specifies a set of host names or address masks that determine the 214 * clients that are not allowed to establish connections to this LDIF 215 * Connection Handler. 216 * <p> 217 * Valid values include a host name, a fully qualified domain name, 218 * a domain name, an IP address, or a subnetwork with subnetwork 219 * mask. If both allowed and denied client masks are defined and a 220 * client connection matches one or more masks in both lists, then 221 * the connection is denied. If only a denied list is specified, then 222 * any client not matching a mask in that list is allowed. 223 * 224 * @return Returns the "denied-client" property definition. 225 */ 226 public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() { 227 return ConnectionHandlerCfgDefn.getInstance().getDeniedClientPropertyDefinition(); 228 } 229 230 231 232 /** 233 * Get the "enabled" property definition. 234 * <p> 235 * Indicates whether the LDIF Connection Handler is enabled. 236 * 237 * @return Returns the "enabled" property definition. 238 */ 239 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 240 return ConnectionHandlerCfgDefn.getInstance().getEnabledPropertyDefinition(); 241 } 242 243 244 245 /** 246 * Get the "java-class" property definition. 247 * <p> 248 * Specifies the fully-qualified name of the Java class that 249 * provides the LDIF Connection Handler implementation. 250 * 251 * @return Returns the "java-class" property definition. 252 */ 253 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 254 return PD_JAVA_CLASS; 255 } 256 257 258 259 /** 260 * Get the "ldif-directory" property definition. 261 * <p> 262 * Specifies the path to the directory in which the LDIF files 263 * should be placed. 264 * 265 * @return Returns the "ldif-directory" property definition. 266 */ 267 public StringPropertyDefinition getLDIFDirectoryPropertyDefinition() { 268 return PD_LDIF_DIRECTORY; 269 } 270 271 272 273 /** 274 * Get the "poll-interval" property definition. 275 * <p> 276 * Specifies how frequently the LDIF connection handler should check 277 * the LDIF directory to determine whether a new LDIF file has been 278 * added. 279 * 280 * @return Returns the "poll-interval" property definition. 281 */ 282 public DurationPropertyDefinition getPollIntervalPropertyDefinition() { 283 return PD_POLL_INTERVAL; 284 } 285 286 287 288 /** 289 * Managed object client implementation. 290 */ 291 private static class LDIFConnectionHandlerCfgClientImpl implements 292 LDIFConnectionHandlerCfgClient { 293 294 // Private implementation. 295 private ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl; 296 297 298 299 // Private constructor. 300 private LDIFConnectionHandlerCfgClientImpl( 301 ManagedObject<? extends LDIFConnectionHandlerCfgClient> impl) { 302 this.impl = impl; 303 } 304 305 306 307 /** 308 * {@inheritDoc} 309 */ 310 public SortedSet<AddressMask> getAllowedClient() { 311 return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 312 } 313 314 315 316 /** 317 * {@inheritDoc} 318 */ 319 public void setAllowedClient(Collection<AddressMask> values) { 320 impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values); 321 } 322 323 324 325 /** 326 * {@inheritDoc} 327 */ 328 public SortedSet<AddressMask> getDeniedClient() { 329 return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 330 } 331 332 333 334 /** 335 * {@inheritDoc} 336 */ 337 public void setDeniedClient(Collection<AddressMask> values) { 338 impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values); 339 } 340 341 342 343 /** 344 * {@inheritDoc} 345 */ 346 public Boolean isEnabled() { 347 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 348 } 349 350 351 352 /** 353 * {@inheritDoc} 354 */ 355 public void setEnabled(boolean value) { 356 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 357 } 358 359 360 361 /** 362 * {@inheritDoc} 363 */ 364 public String getJavaClass() { 365 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 366 } 367 368 369 370 /** 371 * {@inheritDoc} 372 */ 373 public void setJavaClass(String value) { 374 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 375 } 376 377 378 379 /** 380 * {@inheritDoc} 381 */ 382 public String getLDIFDirectory() { 383 return impl.getPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition()); 384 } 385 386 387 388 /** 389 * {@inheritDoc} 390 */ 391 public void setLDIFDirectory(String value) { 392 impl.setPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition(), value); 393 } 394 395 396 397 /** 398 * {@inheritDoc} 399 */ 400 public long getPollInterval() { 401 return impl.getPropertyValue(INSTANCE.getPollIntervalPropertyDefinition()); 402 } 403 404 405 406 /** 407 * {@inheritDoc} 408 */ 409 public void setPollInterval(long value) { 410 impl.setPropertyValue(INSTANCE.getPollIntervalPropertyDefinition(), value); 411 } 412 413 414 415 /** 416 * {@inheritDoc} 417 */ 418 public ManagedObjectDefinition<? extends LDIFConnectionHandlerCfgClient, ? extends LDIFConnectionHandlerCfg> definition() { 419 return INSTANCE; 420 } 421 422 423 424 /** 425 * {@inheritDoc} 426 */ 427 public PropertyProvider properties() { 428 return impl; 429 } 430 431 432 433 /** 434 * {@inheritDoc} 435 */ 436 public void commit() throws ManagedObjectAlreadyExistsException, 437 MissingMandatoryPropertiesException, ConcurrentModificationException, 438 OperationRejectedException, LdapException { 439 impl.commit(); 440 } 441 442 } 443 444 445 446 /** 447 * Managed object server implementation. 448 */ 449 private static class LDIFConnectionHandlerCfgServerImpl implements 450 LDIFConnectionHandlerCfg { 451 452 // Private implementation. 453 private ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl; 454 455 // The value of the "allowed-client" property. 456 private final SortedSet<AddressMask> pAllowedClient; 457 458 // The value of the "denied-client" property. 459 private final SortedSet<AddressMask> pDeniedClient; 460 461 // The value of the "enabled" property. 462 private final boolean pEnabled; 463 464 // The value of the "java-class" property. 465 private final String pJavaClass; 466 467 // The value of the "ldif-directory" property. 468 private final String pLDIFDirectory; 469 470 // The value of the "poll-interval" property. 471 private final long pPollInterval; 472 473 474 475 // Private constructor. 476 private LDIFConnectionHandlerCfgServerImpl(ServerManagedObject<? extends LDIFConnectionHandlerCfg> impl) { 477 this.impl = impl; 478 this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 479 this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 480 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 481 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 482 this.pLDIFDirectory = impl.getPropertyValue(INSTANCE.getLDIFDirectoryPropertyDefinition()); 483 this.pPollInterval = impl.getPropertyValue(INSTANCE.getPollIntervalPropertyDefinition()); 484 } 485 486 487 488 /** 489 * {@inheritDoc} 490 */ 491 public void addLDIFChangeListener( 492 ConfigurationChangeListener<LDIFConnectionHandlerCfg> listener) { 493 impl.registerChangeListener(listener); 494 } 495 496 497 498 /** 499 * {@inheritDoc} 500 */ 501 public void removeLDIFChangeListener( 502 ConfigurationChangeListener<LDIFConnectionHandlerCfg> listener) { 503 impl.deregisterChangeListener(listener); 504 } 505 /** 506 * {@inheritDoc} 507 */ 508 public void addChangeListener( 509 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 510 impl.registerChangeListener(listener); 511 } 512 513 514 515 /** 516 * {@inheritDoc} 517 */ 518 public void removeChangeListener( 519 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 520 impl.deregisterChangeListener(listener); 521 } 522 523 524 525 /** 526 * {@inheritDoc} 527 */ 528 public SortedSet<AddressMask> getAllowedClient() { 529 return pAllowedClient; 530 } 531 532 533 534 /** 535 * {@inheritDoc} 536 */ 537 public SortedSet<AddressMask> getDeniedClient() { 538 return pDeniedClient; 539 } 540 541 542 543 /** 544 * {@inheritDoc} 545 */ 546 public boolean isEnabled() { 547 return pEnabled; 548 } 549 550 551 552 /** 553 * {@inheritDoc} 554 */ 555 public String getJavaClass() { 556 return pJavaClass; 557 } 558 559 560 561 /** 562 * {@inheritDoc} 563 */ 564 public String getLDIFDirectory() { 565 return pLDIFDirectory; 566 } 567 568 569 570 /** 571 * {@inheritDoc} 572 */ 573 public long getPollInterval() { 574 return pPollInterval; 575 } 576 577 578 579 /** 580 * {@inheritDoc} 581 */ 582 public Class<? extends LDIFConnectionHandlerCfg> configurationClass() { 583 return LDIFConnectionHandlerCfg.class; 584 } 585 586 587 588 /** 589 * {@inheritDoc} 590 */ 591 public DN dn() { 592 return impl.getDN(); 593 } 594 595 } 596}