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