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.PKCS11KeyManagerProviderCfgClient; 051import org.forgerock.opendj.server.config.server.KeyManagerProviderCfg; 052import org.forgerock.opendj.server.config.server.PKCS11KeyManagerProviderCfg; 053 054 055 056/** 057 * An interface for querying the PKCS11 Key Manager Provider managed 058 * object definition meta information. 059 * <p> 060 * The PKCS11 Key Manager Provider enables the server to access the 061 * private key information through the PKCS11 interface. 062 */ 063public final class PKCS11KeyManagerProviderCfgDefn extends ManagedObjectDefinition<PKCS11KeyManagerProviderCfgClient, PKCS11KeyManagerProviderCfg> { 064 065 // The singleton configuration definition instance. 066 private static final PKCS11KeyManagerProviderCfgDefn INSTANCE = new PKCS11KeyManagerProviderCfgDefn(); 067 068 069 070 // The "java-class" property definition. 071 private static final ClassPropertyDefinition PD_JAVA_CLASS; 072 073 074 075 // The "key-store-pin" property definition. 076 private static final StringPropertyDefinition PD_KEY_STORE_PIN; 077 078 079 080 // The "key-store-pin-environment-variable" property definition. 081 private static final StringPropertyDefinition PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE; 082 083 084 085 // The "key-store-pin-file" property definition. 086 private static final StringPropertyDefinition PD_KEY_STORE_PIN_FILE; 087 088 089 090 // The "key-store-pin-property" property definition. 091 private static final StringPropertyDefinition PD_KEY_STORE_PIN_PROPERTY; 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.PKCS11KeyManagerProvider"); 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-pin" property definition. 111 static { 112 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin"); 113 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin")); 114 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 115 PD_KEY_STORE_PIN = builder.getInstance(); 116 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN); 117 } 118 119 120 121 // Build the "key-store-pin-environment-variable" property definition. 122 static { 123 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-environment-variable"); 124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-environment-variable")); 125 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 126 builder.setPattern(".*", "STRING"); 127 PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE = builder.getInstance(); 128 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE); 129 } 130 131 132 133 // Build the "key-store-pin-file" property definition. 134 static { 135 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-file"); 136 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-file")); 137 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 138 builder.setPattern(".*", "FILE"); 139 PD_KEY_STORE_PIN_FILE = builder.getInstance(); 140 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_FILE); 141 } 142 143 144 145 // Build the "key-store-pin-property" property definition. 146 static { 147 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-property"); 148 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-property")); 149 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 150 builder.setPattern(".*", "STRING"); 151 PD_KEY_STORE_PIN_PROPERTY = builder.getInstance(); 152 INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_PROPERTY); 153 } 154 155 156 157 // Register the tags associated with this managed object definition. 158 static { 159 INSTANCE.registerTag(Tag.valueOf("security")); 160 } 161 162 163 164 /** 165 * Get the PKCS11 Key Manager Provider configuration definition 166 * singleton. 167 * 168 * @return Returns the PKCS11 Key Manager Provider configuration 169 * definition singleton. 170 */ 171 public static PKCS11KeyManagerProviderCfgDefn getInstance() { 172 return INSTANCE; 173 } 174 175 176 177 /** 178 * Private constructor. 179 */ 180 private PKCS11KeyManagerProviderCfgDefn() { 181 super("pkcs11-key-manager-provider", KeyManagerProviderCfgDefn.getInstance()); 182 } 183 184 185 186 /** 187 * {@inheritDoc} 188 */ 189 public PKCS11KeyManagerProviderCfgClient createClientConfiguration( 190 ManagedObject<? extends PKCS11KeyManagerProviderCfgClient> impl) { 191 return new PKCS11KeyManagerProviderCfgClientImpl(impl); 192 } 193 194 195 196 /** 197 * {@inheritDoc} 198 */ 199 public PKCS11KeyManagerProviderCfg createServerConfiguration( 200 ServerManagedObject<? extends PKCS11KeyManagerProviderCfg> impl) { 201 return new PKCS11KeyManagerProviderCfgServerImpl(impl); 202 } 203 204 205 206 /** 207 * {@inheritDoc} 208 */ 209 public Class<PKCS11KeyManagerProviderCfg> getServerConfigurationClass() { 210 return PKCS11KeyManagerProviderCfg.class; 211 } 212 213 214 215 /** 216 * Get the "enabled" property definition. 217 * <p> 218 * Indicates whether the PKCS11 Key Manager Provider is enabled for 219 * use. 220 * 221 * @return Returns the "enabled" property definition. 222 */ 223 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 224 return KeyManagerProviderCfgDefn.getInstance().getEnabledPropertyDefinition(); 225 } 226 227 228 229 /** 230 * Get the "java-class" property definition. 231 * <p> 232 * The fully-qualified name of the Java class that provides the 233 * PKCS11 Key Manager Provider implementation. 234 * 235 * @return Returns the "java-class" property definition. 236 */ 237 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 238 return PD_JAVA_CLASS; 239 } 240 241 242 243 /** 244 * Get the "key-store-pin" property definition. 245 * <p> 246 * Specifies the clear-text PIN needed to access the PKCS11 Key 247 * Manager Provider . 248 * 249 * @return Returns the "key-store-pin" property definition. 250 */ 251 public StringPropertyDefinition getKeyStorePinPropertyDefinition() { 252 return PD_KEY_STORE_PIN; 253 } 254 255 256 257 /** 258 * Get the "key-store-pin-environment-variable" property definition. 259 * <p> 260 * Specifies the name of the environment variable that contains the 261 * clear-text PIN needed to access the PKCS11 Key Manager Provider . 262 * 263 * @return Returns the "key-store-pin-environment-variable" property definition. 264 */ 265 public StringPropertyDefinition getKeyStorePinEnvironmentVariablePropertyDefinition() { 266 return PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE; 267 } 268 269 270 271 /** 272 * Get the "key-store-pin-file" property definition. 273 * <p> 274 * Specifies the path to the text file whose only contents should be 275 * a single line containing the clear-text PIN needed to access the 276 * PKCS11 Key Manager Provider . 277 * 278 * @return Returns the "key-store-pin-file" property definition. 279 */ 280 public StringPropertyDefinition getKeyStorePinFilePropertyDefinition() { 281 return PD_KEY_STORE_PIN_FILE; 282 } 283 284 285 286 /** 287 * Get the "key-store-pin-property" property definition. 288 * <p> 289 * Specifies the name of the Java property that contains the 290 * clear-text PIN needed to access the PKCS11 Key Manager Provider . 291 * 292 * @return Returns the "key-store-pin-property" property definition. 293 */ 294 public StringPropertyDefinition getKeyStorePinPropertyPropertyDefinition() { 295 return PD_KEY_STORE_PIN_PROPERTY; 296 } 297 298 299 300 /** 301 * Managed object client implementation. 302 */ 303 private static class PKCS11KeyManagerProviderCfgClientImpl implements 304 PKCS11KeyManagerProviderCfgClient { 305 306 // Private implementation. 307 private ManagedObject<? extends PKCS11KeyManagerProviderCfgClient> impl; 308 309 310 311 // Private constructor. 312 private PKCS11KeyManagerProviderCfgClientImpl( 313 ManagedObject<? extends PKCS11KeyManagerProviderCfgClient> impl) { 314 this.impl = impl; 315 } 316 317 318 319 /** 320 * {@inheritDoc} 321 */ 322 public Boolean isEnabled() { 323 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 324 } 325 326 327 328 /** 329 * {@inheritDoc} 330 */ 331 public void setEnabled(boolean value) { 332 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 333 } 334 335 336 337 /** 338 * {@inheritDoc} 339 */ 340 public String getJavaClass() { 341 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 342 } 343 344 345 346 /** 347 * {@inheritDoc} 348 */ 349 public void setJavaClass(String value) { 350 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 351 } 352 353 354 355 /** 356 * {@inheritDoc} 357 */ 358 public String getKeyStorePin() { 359 return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition()); 360 } 361 362 363 364 /** 365 * {@inheritDoc} 366 */ 367 public void setKeyStorePin(String value) { 368 impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition(), value); 369 } 370 371 372 373 /** 374 * {@inheritDoc} 375 */ 376 public String getKeyStorePinEnvironmentVariable() { 377 return impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition()); 378 } 379 380 381 382 /** 383 * {@inheritDoc} 384 */ 385 public void setKeyStorePinEnvironmentVariable(String value) { 386 impl.setPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition(), value); 387 } 388 389 390 391 /** 392 * {@inheritDoc} 393 */ 394 public String getKeyStorePinFile() { 395 return impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition()); 396 } 397 398 399 400 /** 401 * {@inheritDoc} 402 */ 403 public void setKeyStorePinFile(String value) { 404 impl.setPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition(), value); 405 } 406 407 408 409 /** 410 * {@inheritDoc} 411 */ 412 public String getKeyStorePinProperty() { 413 return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition()); 414 } 415 416 417 418 /** 419 * {@inheritDoc} 420 */ 421 public void setKeyStorePinProperty(String value) { 422 impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition(), value); 423 } 424 425 426 427 /** 428 * {@inheritDoc} 429 */ 430 public ManagedObjectDefinition<? extends PKCS11KeyManagerProviderCfgClient, ? extends PKCS11KeyManagerProviderCfg> definition() { 431 return INSTANCE; 432 } 433 434 435 436 /** 437 * {@inheritDoc} 438 */ 439 public PropertyProvider properties() { 440 return impl; 441 } 442 443 444 445 /** 446 * {@inheritDoc} 447 */ 448 public void commit() throws ManagedObjectAlreadyExistsException, 449 MissingMandatoryPropertiesException, ConcurrentModificationException, 450 OperationRejectedException, LdapException { 451 impl.commit(); 452 } 453 454 } 455 456 457 458 /** 459 * Managed object server implementation. 460 */ 461 private static class PKCS11KeyManagerProviderCfgServerImpl implements 462 PKCS11KeyManagerProviderCfg { 463 464 // Private implementation. 465 private ServerManagedObject<? extends PKCS11KeyManagerProviderCfg> impl; 466 467 // The value of the "enabled" property. 468 private final boolean pEnabled; 469 470 // The value of the "java-class" property. 471 private final String pJavaClass; 472 473 // The value of the "key-store-pin" property. 474 private final String pKeyStorePin; 475 476 // The value of the "key-store-pin-environment-variable" property. 477 private final String pKeyStorePinEnvironmentVariable; 478 479 // The value of the "key-store-pin-file" property. 480 private final String pKeyStorePinFile; 481 482 // The value of the "key-store-pin-property" property. 483 private final String pKeyStorePinProperty; 484 485 486 487 // Private constructor. 488 private PKCS11KeyManagerProviderCfgServerImpl(ServerManagedObject<? extends PKCS11KeyManagerProviderCfg> impl) { 489 this.impl = impl; 490 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 491 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 492 this.pKeyStorePin = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition()); 493 this.pKeyStorePinEnvironmentVariable = impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition()); 494 this.pKeyStorePinFile = impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition()); 495 this.pKeyStorePinProperty = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition()); 496 } 497 498 499 500 /** 501 * {@inheritDoc} 502 */ 503 public void addPKCS11ChangeListener( 504 ConfigurationChangeListener<PKCS11KeyManagerProviderCfg> listener) { 505 impl.registerChangeListener(listener); 506 } 507 508 509 510 /** 511 * {@inheritDoc} 512 */ 513 public void removePKCS11ChangeListener( 514 ConfigurationChangeListener<PKCS11KeyManagerProviderCfg> listener) { 515 impl.deregisterChangeListener(listener); 516 } 517 /** 518 * {@inheritDoc} 519 */ 520 public void addChangeListener( 521 ConfigurationChangeListener<KeyManagerProviderCfg> listener) { 522 impl.registerChangeListener(listener); 523 } 524 525 526 527 /** 528 * {@inheritDoc} 529 */ 530 public void removeChangeListener( 531 ConfigurationChangeListener<KeyManagerProviderCfg> listener) { 532 impl.deregisterChangeListener(listener); 533 } 534 535 536 537 /** 538 * {@inheritDoc} 539 */ 540 public boolean isEnabled() { 541 return pEnabled; 542 } 543 544 545 546 /** 547 * {@inheritDoc} 548 */ 549 public String getJavaClass() { 550 return pJavaClass; 551 } 552 553 554 555 /** 556 * {@inheritDoc} 557 */ 558 public String getKeyStorePin() { 559 return pKeyStorePin; 560 } 561 562 563 564 /** 565 * {@inheritDoc} 566 */ 567 public String getKeyStorePinEnvironmentVariable() { 568 return pKeyStorePinEnvironmentVariable; 569 } 570 571 572 573 /** 574 * {@inheritDoc} 575 */ 576 public String getKeyStorePinFile() { 577 return pKeyStorePinFile; 578 } 579 580 581 582 /** 583 * {@inheritDoc} 584 */ 585 public String getKeyStorePinProperty() { 586 return pKeyStorePinProperty; 587 } 588 589 590 591 /** 592 * {@inheritDoc} 593 */ 594 public Class<? extends PKCS11KeyManagerProviderCfg> configurationClass() { 595 return PKCS11KeyManagerProviderCfg.class; 596 } 597 598 599 600 /** 601 * {@inheritDoc} 602 */ 603 public DN dn() { 604 return impl.getDN(); 605 } 606 607 } 608}