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