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