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.opends.server.admin.std.meta; 017 018 019 020import org.forgerock.opendj.ldap.DN; 021import org.opends.server.admin.AdministratorAction; 022import org.opends.server.admin.BooleanPropertyDefinition; 023import org.opends.server.admin.ClassPropertyDefinition; 024import org.opends.server.admin.client.AuthorizationException; 025import org.opends.server.admin.client.CommunicationException; 026import org.opends.server.admin.client.ConcurrentModificationException; 027import org.opends.server.admin.client.ManagedObject; 028import org.opends.server.admin.client.MissingMandatoryPropertiesException; 029import org.opends.server.admin.client.OperationRejectedException; 030import org.opends.server.admin.DefaultBehaviorProvider; 031import org.opends.server.admin.DefinedDefaultBehaviorProvider; 032import org.opends.server.admin.ManagedObjectAlreadyExistsException; 033import org.opends.server.admin.ManagedObjectDefinition; 034import org.opends.server.admin.PropertyOption; 035import org.opends.server.admin.PropertyProvider; 036import org.opends.server.admin.server.ConfigurationChangeListener; 037import org.opends.server.admin.server.ServerManagedObject; 038import org.opends.server.admin.std.client.FileBasedKeyManagerProviderCfgClient; 039import org.opends.server.admin.std.server.FileBasedKeyManagerProviderCfg; 040import org.opends.server.admin.std.server.KeyManagerProviderCfg; 041import org.opends.server.admin.StringPropertyDefinition; 042import org.opends.server.admin.Tag; 043import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 044 045 046 047/** 048 * An interface for querying the File Based Key Manager Provider 049 * managed object definition meta information. 050 * <p> 051 * The File Based Key Manager Provider can be used to obtain the 052 * server certificate from a key store file on the local file system. 053 */ 054public final class FileBasedKeyManagerProviderCfgDefn extends ManagedObjectDefinition<FileBasedKeyManagerProviderCfgClient, FileBasedKeyManagerProviderCfg> { 055 056 // The singleton configuration definition instance. 057 private static final FileBasedKeyManagerProviderCfgDefn INSTANCE = new FileBasedKeyManagerProviderCfgDefn(); 058 059 060 061 // The "java-class" property definition. 062 private static final ClassPropertyDefinition PD_JAVA_CLASS; 063 064 065 066 // The "key-store-file" property definition. 067 private static final StringPropertyDefinition PD_KEY_STORE_FILE; 068 069 070 071 // The "key-store-pin" property definition. 072 private static final StringPropertyDefinition PD_KEY_STORE_PIN; 073 074 075 076 // The "key-store-pin-environment-variable" property definition. 077 private static final StringPropertyDefinition PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE; 078 079 080 081 // The "key-store-pin-file" property definition. 082 private static final StringPropertyDefinition PD_KEY_STORE_PIN_FILE; 083 084 085 086 // The "key-store-pin-property" property definition. 087 private static final StringPropertyDefinition PD_KEY_STORE_PIN_PROPERTY; 088 089 090 091 // The "key-store-type" property definition. 092 private static final StringPropertyDefinition PD_KEY_STORE_TYPE; 093 094 095 096 // Build the "java-class" property definition. 097 static { 098 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 099 builder.setOption(PropertyOption.MANDATORY); 100 builder.setOption(PropertyOption.ADVANCED); 101 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 102 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.FileBasedKeyManagerProvider"); 103 builder.setDefaultBehaviorProvider(provider); 104 builder.addInstanceOf("org.opends.server.api.KeyManagerProvider"); 105 PD_JAVA_CLASS = builder.getInstance(); 106 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 107 } 108 109 110 111 // Build the "key-store-file" property definition. 112 static { 113 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-file"); 114 builder.setOption(PropertyOption.MANDATORY); 115 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-file")); 116 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 117 builder.setPattern(".*", "FILE"); 118 PD_KEY_STORE_FILE = builder.getInstance(); 119 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_FILE); 120 } 121 122 123 124 // Build the "key-store-pin" property definition. 125 static { 126 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin"); 127 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin")); 128 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 129 PD_KEY_STORE_PIN = builder.getInstance(); 130 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN); 131 } 132 133 134 135 // Build the "key-store-pin-environment-variable" property definition. 136 static { 137 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-environment-variable"); 138 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-environment-variable")); 139 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 140 builder.setPattern(".*", "STRING"); 141 PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE = builder.getInstance(); 142 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE); 143 } 144 145 146 147 // Build the "key-store-pin-file" property definition. 148 static { 149 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-file"); 150 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-file")); 151 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 152 builder.setPattern(".*", "FILE"); 153 PD_KEY_STORE_PIN_FILE = builder.getInstance(); 154 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_FILE); 155 } 156 157 158 159 // Build the "key-store-pin-property" property definition. 160 static { 161 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-property"); 162 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-property")); 163 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 164 builder.setPattern(".*", "STRING"); 165 PD_KEY_STORE_PIN_PROPERTY = builder.getInstance(); 166 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_PROPERTY); 167 } 168 169 170 171 // Build the "key-store-type" property definition. 172 static { 173 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-type"); 174 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-type")); 175 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 176 builder.setPattern(".*", "STRING"); 177 PD_KEY_STORE_TYPE = builder.getInstance(); 178 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_TYPE); 179 } 180 181 182 183 // Register the tags associated with this managed object definition. 184 static { 185 INSTANCE.registerTag(Tag.valueOf("security")); 186 } 187 188 189 190 /** 191 * Get the File Based Key Manager Provider configuration definition 192 * singleton. 193 * 194 * @return Returns the File Based Key Manager Provider configuration 195 * definition singleton. 196 */ 197 public static FileBasedKeyManagerProviderCfgDefn getInstance() { 198 return INSTANCE; 199 } 200 201 202 203 /** 204 * Private constructor. 205 */ 206 private FileBasedKeyManagerProviderCfgDefn() { 207 super("file-based-key-manager-provider", KeyManagerProviderCfgDefn.getInstance()); 208 } 209 210 211 212 /** 213 * {@inheritDoc} 214 */ 215 public FileBasedKeyManagerProviderCfgClient createClientConfiguration( 216 ManagedObject<? extends FileBasedKeyManagerProviderCfgClient> impl) { 217 return new FileBasedKeyManagerProviderCfgClientImpl(impl); 218 } 219 220 221 222 /** 223 * {@inheritDoc} 224 */ 225 public FileBasedKeyManagerProviderCfg createServerConfiguration( 226 ServerManagedObject<? extends FileBasedKeyManagerProviderCfg> impl) { 227 return new FileBasedKeyManagerProviderCfgServerImpl(impl); 228 } 229 230 231 232 /** 233 * {@inheritDoc} 234 */ 235 public Class<FileBasedKeyManagerProviderCfg> getServerConfigurationClass() { 236 return FileBasedKeyManagerProviderCfg.class; 237 } 238 239 240 241 /** 242 * Get the "enabled" property definition. 243 * <p> 244 * Indicates whether the File Based Key Manager Provider is enabled 245 * for use. 246 * 247 * @return Returns the "enabled" property definition. 248 */ 249 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 250 return KeyManagerProviderCfgDefn.getInstance().getEnabledPropertyDefinition(); 251 } 252 253 254 255 /** 256 * Get the "java-class" property definition. 257 * <p> 258 * The fully-qualified name of the Java class that provides the File 259 * Based Key Manager Provider implementation. 260 * 261 * @return Returns the "java-class" property definition. 262 */ 263 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 264 return PD_JAVA_CLASS; 265 } 266 267 268 269 /** 270 * Get the "key-store-file" property definition. 271 * <p> 272 * Specifies the path to the file that contains the private key 273 * information. This may be an absolute path, or a path that is 274 * relative to the OpenDJ instance root. 275 * <p> 276 * Changes to this property will take effect the next time that the 277 * key manager is accessed. 278 * 279 * @return Returns the "key-store-file" property definition. 280 */ 281 public StringPropertyDefinition getKeyStoreFilePropertyDefinition() { 282 return PD_KEY_STORE_FILE; 283 } 284 285 286 287 /** 288 * Get the "key-store-pin" property definition. 289 * <p> 290 * Specifies the clear-text PIN needed to access the File Based Key 291 * Manager Provider . 292 * 293 * @return Returns the "key-store-pin" property definition. 294 */ 295 public StringPropertyDefinition getKeyStorePinPropertyDefinition() { 296 return PD_KEY_STORE_PIN; 297 } 298 299 300 301 /** 302 * Get the "key-store-pin-environment-variable" property definition. 303 * <p> 304 * Specifies the name of the environment variable that contains the 305 * clear-text PIN needed to access the File Based Key Manager 306 * Provider . 307 * 308 * @return Returns the "key-store-pin-environment-variable" property definition. 309 */ 310 public StringPropertyDefinition getKeyStorePinEnvironmentVariablePropertyDefinition() { 311 return PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE; 312 } 313 314 315 316 /** 317 * Get the "key-store-pin-file" property definition. 318 * <p> 319 * Specifies the path to the text file whose only contents should be 320 * a single line containing the clear-text PIN needed to access the 321 * File Based Key Manager Provider . 322 * 323 * @return Returns the "key-store-pin-file" property definition. 324 */ 325 public StringPropertyDefinition getKeyStorePinFilePropertyDefinition() { 326 return PD_KEY_STORE_PIN_FILE; 327 } 328 329 330 331 /** 332 * Get the "key-store-pin-property" property definition. 333 * <p> 334 * Specifies the name of the Java property that contains the 335 * clear-text PIN needed to access the File Based Key Manager 336 * Provider . 337 * 338 * @return Returns the "key-store-pin-property" property definition. 339 */ 340 public StringPropertyDefinition getKeyStorePinPropertyPropertyDefinition() { 341 return PD_KEY_STORE_PIN_PROPERTY; 342 } 343 344 345 346 /** 347 * Get the "key-store-type" property definition. 348 * <p> 349 * Specifies the format for the data in the key store file. 350 * <p> 351 * Valid values should always include 'JKS' and 'PKCS12', but 352 * different implementations may allow other values as well. If no 353 * value is provided, the JVM-default value is used. Changes to this 354 * configuration attribute will take effect the next time that the 355 * key manager is accessed. 356 * 357 * @return Returns the "key-store-type" property definition. 358 */ 359 public StringPropertyDefinition getKeyStoreTypePropertyDefinition() { 360 return PD_KEY_STORE_TYPE; 361 } 362 363 364 365 /** 366 * Managed object client implementation. 367 */ 368 private static class FileBasedKeyManagerProviderCfgClientImpl implements 369 FileBasedKeyManagerProviderCfgClient { 370 371 // Private implementation. 372 private ManagedObject<? extends FileBasedKeyManagerProviderCfgClient> impl; 373 374 375 376 // Private constructor. 377 private FileBasedKeyManagerProviderCfgClientImpl( 378 ManagedObject<? extends FileBasedKeyManagerProviderCfgClient> impl) { 379 this.impl = impl; 380 } 381 382 383 384 /** 385 * {@inheritDoc} 386 */ 387 public Boolean isEnabled() { 388 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 389 } 390 391 392 393 /** 394 * {@inheritDoc} 395 */ 396 public void setEnabled(boolean value) { 397 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 398 } 399 400 401 402 /** 403 * {@inheritDoc} 404 */ 405 public String getJavaClass() { 406 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 407 } 408 409 410 411 /** 412 * {@inheritDoc} 413 */ 414 public void setJavaClass(String value) { 415 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 416 } 417 418 419 420 /** 421 * {@inheritDoc} 422 */ 423 public String getKeyStoreFile() { 424 return impl.getPropertyValue(INSTANCE.getKeyStoreFilePropertyDefinition()); 425 } 426 427 428 429 /** 430 * {@inheritDoc} 431 */ 432 public void setKeyStoreFile(String value) { 433 impl.setPropertyValue(INSTANCE.getKeyStoreFilePropertyDefinition(), value); 434 } 435 436 437 438 /** 439 * {@inheritDoc} 440 */ 441 public String getKeyStorePin() { 442 return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition()); 443 } 444 445 446 447 /** 448 * {@inheritDoc} 449 */ 450 public void setKeyStorePin(String value) { 451 impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition(), value); 452 } 453 454 455 456 /** 457 * {@inheritDoc} 458 */ 459 public String getKeyStorePinEnvironmentVariable() { 460 return impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition()); 461 } 462 463 464 465 /** 466 * {@inheritDoc} 467 */ 468 public void setKeyStorePinEnvironmentVariable(String value) { 469 impl.setPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition(), value); 470 } 471 472 473 474 /** 475 * {@inheritDoc} 476 */ 477 public String getKeyStorePinFile() { 478 return impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition()); 479 } 480 481 482 483 /** 484 * {@inheritDoc} 485 */ 486 public void setKeyStorePinFile(String value) { 487 impl.setPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition(), value); 488 } 489 490 491 492 /** 493 * {@inheritDoc} 494 */ 495 public String getKeyStorePinProperty() { 496 return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition()); 497 } 498 499 500 501 /** 502 * {@inheritDoc} 503 */ 504 public void setKeyStorePinProperty(String value) { 505 impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition(), value); 506 } 507 508 509 510 /** 511 * {@inheritDoc} 512 */ 513 public String getKeyStoreType() { 514 return impl.getPropertyValue(INSTANCE.getKeyStoreTypePropertyDefinition()); 515 } 516 517 518 519 /** 520 * {@inheritDoc} 521 */ 522 public void setKeyStoreType(String value) { 523 impl.setPropertyValue(INSTANCE.getKeyStoreTypePropertyDefinition(), value); 524 } 525 526 527 528 /** 529 * {@inheritDoc} 530 */ 531 public ManagedObjectDefinition<? extends FileBasedKeyManagerProviderCfgClient, ? extends FileBasedKeyManagerProviderCfg> 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 /** {@inheritDoc} */ 559 public String toString() { 560 return impl.toString(); 561 } 562 } 563 564 565 566 /** 567 * Managed object server implementation. 568 */ 569 private static class FileBasedKeyManagerProviderCfgServerImpl implements 570 FileBasedKeyManagerProviderCfg { 571 572 // Private implementation. 573 private ServerManagedObject<? extends FileBasedKeyManagerProviderCfg> impl; 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-store-file" property. 582 private final String pKeyStoreFile; 583 584 // The value of the "key-store-pin" property. 585 private final String pKeyStorePin; 586 587 // The value of the "key-store-pin-environment-variable" property. 588 private final String pKeyStorePinEnvironmentVariable; 589 590 // The value of the "key-store-pin-file" property. 591 private final String pKeyStorePinFile; 592 593 // The value of the "key-store-pin-property" property. 594 private final String pKeyStorePinProperty; 595 596 // The value of the "key-store-type" property. 597 private final String pKeyStoreType; 598 599 600 601 // Private constructor. 602 private FileBasedKeyManagerProviderCfgServerImpl(ServerManagedObject<? extends FileBasedKeyManagerProviderCfg> impl) { 603 this.impl = impl; 604 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 605 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 606 this.pKeyStoreFile = impl.getPropertyValue(INSTANCE.getKeyStoreFilePropertyDefinition()); 607 this.pKeyStorePin = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition()); 608 this.pKeyStorePinEnvironmentVariable = impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition()); 609 this.pKeyStorePinFile = impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition()); 610 this.pKeyStorePinProperty = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition()); 611 this.pKeyStoreType = impl.getPropertyValue(INSTANCE.getKeyStoreTypePropertyDefinition()); 612 } 613 614 615 616 /** 617 * {@inheritDoc} 618 */ 619 public void addFileBasedChangeListener( 620 ConfigurationChangeListener<FileBasedKeyManagerProviderCfg> listener) { 621 impl.registerChangeListener(listener); 622 } 623 624 625 626 /** 627 * {@inheritDoc} 628 */ 629 public void removeFileBasedChangeListener( 630 ConfigurationChangeListener<FileBasedKeyManagerProviderCfg> listener) { 631 impl.deregisterChangeListener(listener); 632 } 633 /** 634 * {@inheritDoc} 635 */ 636 public void addChangeListener( 637 ConfigurationChangeListener<KeyManagerProviderCfg> listener) { 638 impl.registerChangeListener(listener); 639 } 640 641 642 643 /** 644 * {@inheritDoc} 645 */ 646 public void removeChangeListener( 647 ConfigurationChangeListener<KeyManagerProviderCfg> listener) { 648 impl.deregisterChangeListener(listener); 649 } 650 651 652 653 /** 654 * {@inheritDoc} 655 */ 656 public boolean isEnabled() { 657 return pEnabled; 658 } 659 660 661 662 /** 663 * {@inheritDoc} 664 */ 665 public String getJavaClass() { 666 return pJavaClass; 667 } 668 669 670 671 /** 672 * {@inheritDoc} 673 */ 674 public String getKeyStoreFile() { 675 return pKeyStoreFile; 676 } 677 678 679 680 /** 681 * {@inheritDoc} 682 */ 683 public String getKeyStorePin() { 684 return pKeyStorePin; 685 } 686 687 688 689 /** 690 * {@inheritDoc} 691 */ 692 public String getKeyStorePinEnvironmentVariable() { 693 return pKeyStorePinEnvironmentVariable; 694 } 695 696 697 698 /** 699 * {@inheritDoc} 700 */ 701 public String getKeyStorePinFile() { 702 return pKeyStorePinFile; 703 } 704 705 706 707 /** 708 * {@inheritDoc} 709 */ 710 public String getKeyStorePinProperty() { 711 return pKeyStorePinProperty; 712 } 713 714 715 716 /** 717 * {@inheritDoc} 718 */ 719 public String getKeyStoreType() { 720 return pKeyStoreType; 721 } 722 723 724 725 /** 726 * {@inheritDoc} 727 */ 728 public Class<? extends FileBasedKeyManagerProviderCfg> configurationClass() { 729 return FileBasedKeyManagerProviderCfg.class; 730 } 731 732 733 734 /** 735 * {@inheritDoc} 736 */ 737 public DN dn() { 738 return impl.getDN(); 739 } 740 741 742 743 /** {@inheritDoc} */ 744 public String toString() { 745 return impl.toString(); 746 } 747 } 748}