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 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.admin.std.meta; 028 029 030 031 import java.util.Collection; 032 import java.util.SortedSet; 033 import org.opends.server.admin.AdministratorAction; 034 import org.opends.server.admin.AggregationPropertyDefinition; 035 import org.opends.server.admin.AliasDefaultBehaviorProvider; 036 import org.opends.server.admin.BooleanPropertyDefinition; 037 import org.opends.server.admin.ClassPropertyDefinition; 038 import org.opends.server.admin.client.AuthorizationException; 039 import org.opends.server.admin.client.CommunicationException; 040 import org.opends.server.admin.client.ConcurrentModificationException; 041 import org.opends.server.admin.client.ManagedObject; 042 import org.opends.server.admin.client.MissingMandatoryPropertiesException; 043 import org.opends.server.admin.client.OperationRejectedException; 044 import org.opends.server.admin.condition.Conditions; 045 import org.opends.server.admin.DefaultBehaviorProvider; 046 import org.opends.server.admin.DefinedDefaultBehaviorProvider; 047 import org.opends.server.admin.GenericConstraint; 048 import org.opends.server.admin.IntegerPropertyDefinition; 049 import org.opends.server.admin.IPAddressMaskPropertyDefinition; 050 import org.opends.server.admin.ManagedObjectAlreadyExistsException; 051 import org.opends.server.admin.ManagedObjectDefinition; 052 import org.opends.server.admin.PropertyOption; 053 import org.opends.server.admin.PropertyProvider; 054 import org.opends.server.admin.server.ConfigurationChangeListener; 055 import org.opends.server.admin.server.ServerManagedObject; 056 import org.opends.server.admin.std.client.JMXConnectionHandlerCfgClient; 057 import org.opends.server.admin.std.client.KeyManagerProviderCfgClient; 058 import org.opends.server.admin.std.server.ConnectionHandlerCfg; 059 import org.opends.server.admin.std.server.JMXConnectionHandlerCfg; 060 import org.opends.server.admin.std.server.KeyManagerProviderCfg; 061 import org.opends.server.admin.StringPropertyDefinition; 062 import org.opends.server.admin.Tag; 063 import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 064 import org.opends.server.types.AddressMask; 065 import org.opends.server.types.DN; 066 067 068 069 /** 070 * An interface for querying the JMX Connection Handler managed object 071 * definition meta information. 072 * <p> 073 * The JMX Connection Handler is used to interact with clients using 074 * the Java Management Extensions (JMX) protocol. 075 */ 076 public final class JMXConnectionHandlerCfgDefn extends ManagedObjectDefinition<JMXConnectionHandlerCfgClient, JMXConnectionHandlerCfg> { 077 078 // The singleton configuration definition instance. 079 private static final JMXConnectionHandlerCfgDefn INSTANCE = new JMXConnectionHandlerCfgDefn(); 080 081 082 083 // The "java-class" property definition. 084 private static final ClassPropertyDefinition PD_JAVA_CLASS; 085 086 087 088 // The "key-manager-provider" property definition. 089 private static final AggregationPropertyDefinition<KeyManagerProviderCfgClient, KeyManagerProviderCfg> PD_KEY_MANAGER_PROVIDER; 090 091 092 093 // The "listen-port" property definition. 094 private static final IntegerPropertyDefinition PD_LISTEN_PORT; 095 096 097 098 // The "ssl-cert-nickname" property definition. 099 private static final StringPropertyDefinition PD_SSL_CERT_NICKNAME; 100 101 102 103 // The "use-ssl" property definition. 104 private static final BooleanPropertyDefinition PD_USE_SSL; 105 106 107 108 // Build the "java-class" property definition. 109 static { 110 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 111 builder.setOption(PropertyOption.MANDATORY); 112 builder.setOption(PropertyOption.ADVANCED); 113 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 114 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.protocols.jmx.JmxConnectionHandler"); 115 builder.setDefaultBehaviorProvider(provider); 116 builder.addInstanceOf("org.opends.server.api.ConnectionHandler"); 117 PD_JAVA_CLASS = builder.getInstance(); 118 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 119 } 120 121 122 123 // Build the "key-manager-provider" property definition. 124 static { 125 AggregationPropertyDefinition.Builder<KeyManagerProviderCfgClient, KeyManagerProviderCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "key-manager-provider"); 126 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-manager-provider")); 127 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 128 builder.setParentPath("/"); 129 builder.setRelationDefinition("key-manager-provider"); 130 PD_KEY_MANAGER_PROVIDER = builder.getInstance(); 131 INSTANCE.registerPropertyDefinition(PD_KEY_MANAGER_PROVIDER); 132 INSTANCE.registerConstraint(PD_KEY_MANAGER_PROVIDER.getSourceConstraint()); 133 } 134 135 136 137 // Build the "listen-port" property definition. 138 static { 139 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "listen-port"); 140 builder.setOption(PropertyOption.MANDATORY); 141 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "listen-port")); 142 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>()); 143 builder.setUpperLimit(65535); 144 builder.setLowerLimit(1); 145 PD_LISTEN_PORT = builder.getInstance(); 146 INSTANCE.registerPropertyDefinition(PD_LISTEN_PORT); 147 } 148 149 150 151 // Build the "ssl-cert-nickname" property definition. 152 static { 153 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "ssl-cert-nickname"); 154 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "ssl-cert-nickname")); 155 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "ssl-cert-nickname")); 156 PD_SSL_CERT_NICKNAME = builder.getInstance(); 157 INSTANCE.registerPropertyDefinition(PD_SSL_CERT_NICKNAME); 158 } 159 160 161 162 // Build the "use-ssl" property definition. 163 static { 164 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "use-ssl"); 165 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "use-ssl")); 166 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 167 builder.setDefaultBehaviorProvider(provider); 168 PD_USE_SSL = builder.getInstance(); 169 INSTANCE.registerPropertyDefinition(PD_USE_SSL); 170 } 171 172 173 174 // Register the tags associated with this managed object definition. 175 static { 176 INSTANCE.registerTag(Tag.valueOf("core-server")); 177 } 178 179 180 181 // Register the constraints associated with this managed object definition. 182 static { 183 INSTANCE.registerConstraint(new GenericConstraint(INSTANCE, 1, Conditions.implies(Conditions.contains("enabled", "true"), Conditions.implies(Conditions.contains("use-ssl", "true"), Conditions.isPresent("key-manager-provider"))))); 184 } 185 186 187 188 /** 189 * Get the JMX Connection Handler configuration definition 190 * singleton. 191 * 192 * @return Returns the JMX Connection Handler configuration 193 * definition singleton. 194 */ 195 public static JMXConnectionHandlerCfgDefn getInstance() { 196 return INSTANCE; 197 } 198 199 200 201 /** 202 * Private constructor. 203 */ 204 private JMXConnectionHandlerCfgDefn() { 205 super("jmx-connection-handler", ConnectionHandlerCfgDefn.getInstance()); 206 } 207 208 209 210 /** 211 * {@inheritDoc} 212 */ 213 public JMXConnectionHandlerCfgClient createClientConfiguration( 214 ManagedObject<? extends JMXConnectionHandlerCfgClient> impl) { 215 return new JMXConnectionHandlerCfgClientImpl(impl); 216 } 217 218 219 220 /** 221 * {@inheritDoc} 222 */ 223 public JMXConnectionHandlerCfg createServerConfiguration( 224 ServerManagedObject<? extends JMXConnectionHandlerCfg> impl) { 225 return new JMXConnectionHandlerCfgServerImpl(impl); 226 } 227 228 229 230 /** 231 * {@inheritDoc} 232 */ 233 public Class<JMXConnectionHandlerCfg> getServerConfigurationClass() { 234 return JMXConnectionHandlerCfg.class; 235 } 236 237 238 239 /** 240 * Get the "allowed-client" property definition. 241 * <p> 242 * Specifies a set of address masks that determines the addresses of 243 * the clients that are allowed to establish connections to this 244 * connection handler. 245 * 246 * @return Returns the "allowed-client" property definition. 247 */ 248 public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() { 249 return ConnectionHandlerCfgDefn.getInstance().getAllowedClientPropertyDefinition(); 250 } 251 252 253 254 /** 255 * Get the "denied-client" property definition. 256 * <p> 257 * Specifies a set of address masks that determines the addresses of 258 * the clients that are not allowed to establish connections to this 259 * connection handler. 260 * <p> 261 * If both allowed and denied client masks are defined and a client 262 * connection matches one or more masks in both lists, then the 263 * connection is denied. If only a denied list is specified, then any 264 * client not matching a mask in that list is allowed. 265 * 266 * @return Returns the "denied-client" property definition. 267 */ 268 public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() { 269 return ConnectionHandlerCfgDefn.getInstance().getDeniedClientPropertyDefinition(); 270 } 271 272 273 274 /** 275 * Get the "enabled" property definition. 276 * <p> 277 * Indicates whether the JMX Connection Handler is enabled. 278 * 279 * @return Returns the "enabled" property definition. 280 */ 281 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 282 return ConnectionHandlerCfgDefn.getInstance().getEnabledPropertyDefinition(); 283 } 284 285 286 287 /** 288 * Get the "java-class" property definition. 289 * <p> 290 * Specifies the fully-qualified name of the Java class that 291 * provides the JMX Connection Handler implementation. 292 * 293 * @return Returns the "java-class" property definition. 294 */ 295 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 296 return PD_JAVA_CLASS; 297 } 298 299 300 301 /** 302 * Get the "key-manager-provider" property definition. 303 * <p> 304 * Specifies the name of the key manager that should be used with 305 * this JMX Connection Handler . 306 * 307 * @return Returns the "key-manager-provider" property definition. 308 */ 309 public AggregationPropertyDefinition<KeyManagerProviderCfgClient, KeyManagerProviderCfg> getKeyManagerProviderPropertyDefinition() { 310 return PD_KEY_MANAGER_PROVIDER; 311 } 312 313 314 315 /** 316 * Get the "listen-port" property definition. 317 * <p> 318 * Specifies the port number on which the JMX Connection Handler 319 * will listen for connections from clients. 320 * <p> 321 * Only a single port number may be provided. 322 * 323 * @return Returns the "listen-port" property definition. 324 */ 325 public IntegerPropertyDefinition getListenPortPropertyDefinition() { 326 return PD_LISTEN_PORT; 327 } 328 329 330 331 /** 332 * Get the "ssl-cert-nickname" property definition. 333 * <p> 334 * Specifies the nickname (also called the alias) of the certificate 335 * that the JMX Connection Handler should use when performing SSL 336 * communication. 337 * <p> 338 * This is only applicable when the JMX Connection Handler is 339 * configured to use SSL. 340 * 341 * @return Returns the "ssl-cert-nickname" property definition. 342 */ 343 public StringPropertyDefinition getSSLCertNicknamePropertyDefinition() { 344 return PD_SSL_CERT_NICKNAME; 345 } 346 347 348 349 /** 350 * Get the "use-ssl" property definition. 351 * <p> 352 * Indicates whether the JMX Connection Handler should use SSL. 353 * <p> 354 * If enabled, the JMX Connection Handler will use SSL to encrypt 355 * communication with the clients. 356 * 357 * @return Returns the "use-ssl" property definition. 358 */ 359 public BooleanPropertyDefinition getUseSSLPropertyDefinition() { 360 return PD_USE_SSL; 361 } 362 363 364 365 /** 366 * Managed object client implementation. 367 */ 368 private static class JMXConnectionHandlerCfgClientImpl implements 369 JMXConnectionHandlerCfgClient { 370 371 // Private implementation. 372 private ManagedObject<? extends JMXConnectionHandlerCfgClient> impl; 373 374 375 376 // Private constructor. 377 private JMXConnectionHandlerCfgClientImpl( 378 ManagedObject<? extends JMXConnectionHandlerCfgClient> impl) { 379 this.impl = impl; 380 } 381 382 383 384 /** 385 * {@inheritDoc} 386 */ 387 public SortedSet<AddressMask> getAllowedClient() { 388 return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 389 } 390 391 392 393 /** 394 * {@inheritDoc} 395 */ 396 public void setAllowedClient(Collection<AddressMask> values) { 397 impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values); 398 } 399 400 401 402 /** 403 * {@inheritDoc} 404 */ 405 public SortedSet<AddressMask> getDeniedClient() { 406 return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 407 } 408 409 410 411 /** 412 * {@inheritDoc} 413 */ 414 public void setDeniedClient(Collection<AddressMask> values) { 415 impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values); 416 } 417 418 419 420 /** 421 * {@inheritDoc} 422 */ 423 public Boolean isEnabled() { 424 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 425 } 426 427 428 429 /** 430 * {@inheritDoc} 431 */ 432 public void setEnabled(boolean value) { 433 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 434 } 435 436 437 438 /** 439 * {@inheritDoc} 440 */ 441 public String getJavaClass() { 442 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 443 } 444 445 446 447 /** 448 * {@inheritDoc} 449 */ 450 public void setJavaClass(String value) { 451 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 452 } 453 454 455 456 /** 457 * {@inheritDoc} 458 */ 459 public String getKeyManagerProvider() { 460 return impl.getPropertyValue(INSTANCE.getKeyManagerProviderPropertyDefinition()); 461 } 462 463 464 465 /** 466 * {@inheritDoc} 467 */ 468 public void setKeyManagerProvider(String value) { 469 impl.setPropertyValue(INSTANCE.getKeyManagerProviderPropertyDefinition(), value); 470 } 471 472 473 474 /** 475 * {@inheritDoc} 476 */ 477 public Integer getListenPort() { 478 return impl.getPropertyValue(INSTANCE.getListenPortPropertyDefinition()); 479 } 480 481 482 483 /** 484 * {@inheritDoc} 485 */ 486 public void setListenPort(int value) { 487 impl.setPropertyValue(INSTANCE.getListenPortPropertyDefinition(), value); 488 } 489 490 491 492 /** 493 * {@inheritDoc} 494 */ 495 public String getSSLCertNickname() { 496 return impl.getPropertyValue(INSTANCE.getSSLCertNicknamePropertyDefinition()); 497 } 498 499 500 501 /** 502 * {@inheritDoc} 503 */ 504 public void setSSLCertNickname(String value) { 505 impl.setPropertyValue(INSTANCE.getSSLCertNicknamePropertyDefinition(), value); 506 } 507 508 509 510 /** 511 * {@inheritDoc} 512 */ 513 public boolean isUseSSL() { 514 return impl.getPropertyValue(INSTANCE.getUseSSLPropertyDefinition()); 515 } 516 517 518 519 /** 520 * {@inheritDoc} 521 */ 522 public void setUseSSL(Boolean value) { 523 impl.setPropertyValue(INSTANCE.getUseSSLPropertyDefinition(), value); 524 } 525 526 527 528 /** 529 * {@inheritDoc} 530 */ 531 public ManagedObjectDefinition<? extends JMXConnectionHandlerCfgClient, ? extends JMXConnectionHandlerCfg> definition() { 532 return INSTANCE; 533 } 534 535 536 537 /** 538 * {@inheritDoc} 539 */ 540 public PropertyProvider properties() { 541 return impl; 542 } 543 544 545 546 /** 547 * {@inheritDoc} 548 */ 549 public void commit() throws ManagedObjectAlreadyExistsException, 550 MissingMandatoryPropertiesException, ConcurrentModificationException, 551 OperationRejectedException, AuthorizationException, 552 CommunicationException { 553 impl.commit(); 554 } 555 556 } 557 558 559 560 /** 561 * Managed object server implementation. 562 */ 563 private static class JMXConnectionHandlerCfgServerImpl implements 564 JMXConnectionHandlerCfg { 565 566 // Private implementation. 567 private ServerManagedObject<? extends JMXConnectionHandlerCfg> impl; 568 569 // The value of the "allowed-client" property. 570 private final SortedSet<AddressMask> pAllowedClient; 571 572 // The value of the "denied-client" property. 573 private final SortedSet<AddressMask> pDeniedClient; 574 575 // The value of the "enabled" property. 576 private final boolean pEnabled; 577 578 // The value of the "java-class" property. 579 private final String pJavaClass; 580 581 // The value of the "key-manager-provider" property. 582 private final String pKeyManagerProvider; 583 584 // The value of the "listen-port" property. 585 private final int pListenPort; 586 587 // The value of the "ssl-cert-nickname" property. 588 private final String pSSLCertNickname; 589 590 // The value of the "use-ssl" property. 591 private final boolean pUseSSL; 592 593 594 595 // Private constructor. 596 private JMXConnectionHandlerCfgServerImpl(ServerManagedObject<? extends JMXConnectionHandlerCfg> impl) { 597 this.impl = impl; 598 this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 599 this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 600 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 601 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 602 this.pKeyManagerProvider = impl.getPropertyValue(INSTANCE.getKeyManagerProviderPropertyDefinition()); 603 this.pListenPort = impl.getPropertyValue(INSTANCE.getListenPortPropertyDefinition()); 604 this.pSSLCertNickname = impl.getPropertyValue(INSTANCE.getSSLCertNicknamePropertyDefinition()); 605 this.pUseSSL = impl.getPropertyValue(INSTANCE.getUseSSLPropertyDefinition()); 606 } 607 608 609 610 /** 611 * {@inheritDoc} 612 */ 613 public void addJMXChangeListener( 614 ConfigurationChangeListener<JMXConnectionHandlerCfg> listener) { 615 impl.registerChangeListener(listener); 616 } 617 618 619 620 /** 621 * {@inheritDoc} 622 */ 623 public void removeJMXChangeListener( 624 ConfigurationChangeListener<JMXConnectionHandlerCfg> listener) { 625 impl.deregisterChangeListener(listener); 626 } 627 /** 628 * {@inheritDoc} 629 */ 630 public void addChangeListener( 631 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 632 impl.registerChangeListener(listener); 633 } 634 635 636 637 /** 638 * {@inheritDoc} 639 */ 640 public void removeChangeListener( 641 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 642 impl.deregisterChangeListener(listener); 643 } 644 645 646 647 /** 648 * {@inheritDoc} 649 */ 650 public SortedSet<AddressMask> getAllowedClient() { 651 return pAllowedClient; 652 } 653 654 655 656 /** 657 * {@inheritDoc} 658 */ 659 public SortedSet<AddressMask> getDeniedClient() { 660 return pDeniedClient; 661 } 662 663 664 665 /** 666 * {@inheritDoc} 667 */ 668 public boolean isEnabled() { 669 return pEnabled; 670 } 671 672 673 674 /** 675 * {@inheritDoc} 676 */ 677 public String getJavaClass() { 678 return pJavaClass; 679 } 680 681 682 683 /** 684 * {@inheritDoc} 685 */ 686 public String getKeyManagerProvider() { 687 return pKeyManagerProvider; 688 } 689 690 691 692 /** 693 * {@inheritDoc} 694 */ 695 public DN getKeyManagerProviderDN() { 696 String value = getKeyManagerProvider(); 697 if (value == null) return null; 698 return INSTANCE.getKeyManagerProviderPropertyDefinition().getChildDN(value); 699 } 700 701 702 703 /** 704 * {@inheritDoc} 705 */ 706 public int getListenPort() { 707 return pListenPort; 708 } 709 710 711 712 /** 713 * {@inheritDoc} 714 */ 715 public String getSSLCertNickname() { 716 return pSSLCertNickname; 717 } 718 719 720 721 /** 722 * {@inheritDoc} 723 */ 724 public boolean isUseSSL() { 725 return pUseSSL; 726 } 727 728 729 730 /** 731 * {@inheritDoc} 732 */ 733 public Class<? extends JMXConnectionHandlerCfg> configurationClass() { 734 return JMXConnectionHandlerCfg.class; 735 } 736 737 738 739 /** 740 * {@inheritDoc} 741 */ 742 public DN dn() { 743 return impl.getDN(); 744 } 745 746 } 747 }