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 /** {@inheritDoc} */ 187 public PKCS11KeyManagerProviderCfgClient createClientConfiguration( 188 ManagedObject<? extends PKCS11KeyManagerProviderCfgClient> impl) { 189 return new PKCS11KeyManagerProviderCfgClientImpl(impl); 190 } 191 192 193 194 /** {@inheritDoc} */ 195 public PKCS11KeyManagerProviderCfg createServerConfiguration( 196 ServerManagedObject<? extends PKCS11KeyManagerProviderCfg> impl) { 197 return new PKCS11KeyManagerProviderCfgServerImpl(impl); 198 } 199 200 201 202 /** {@inheritDoc} */ 203 public Class<PKCS11KeyManagerProviderCfg> getServerConfigurationClass() { 204 return PKCS11KeyManagerProviderCfg.class; 205 } 206 207 208 209 /** 210 * Get the "enabled" property definition. 211 * <p> 212 * Indicates whether the PKCS11 Key Manager Provider is enabled for 213 * use. 214 * 215 * @return Returns the "enabled" property definition. 216 */ 217 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 218 return KeyManagerProviderCfgDefn.getInstance().getEnabledPropertyDefinition(); 219 } 220 221 222 223 /** 224 * Get the "java-class" property definition. 225 * <p> 226 * The fully-qualified name of the Java class that provides the 227 * PKCS11 Key Manager Provider implementation. 228 * 229 * @return Returns the "java-class" property definition. 230 */ 231 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 232 return PD_JAVA_CLASS; 233 } 234 235 236 237 /** 238 * Get the "key-store-pin" property definition. 239 * <p> 240 * Specifies the clear-text PIN needed to access the PKCS11 Key 241 * Manager Provider . 242 * 243 * @return Returns the "key-store-pin" property definition. 244 */ 245 public StringPropertyDefinition getKeyStorePinPropertyDefinition() { 246 return PD_KEY_STORE_PIN; 247 } 248 249 250 251 /** 252 * Get the "key-store-pin-environment-variable" property definition. 253 * <p> 254 * Specifies the name of the environment variable that contains the 255 * clear-text PIN needed to access the PKCS11 Key Manager Provider . 256 * 257 * @return Returns the "key-store-pin-environment-variable" property definition. 258 */ 259 public StringPropertyDefinition getKeyStorePinEnvironmentVariablePropertyDefinition() { 260 return PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE; 261 } 262 263 264 265 /** 266 * Get the "key-store-pin-file" property definition. 267 * <p> 268 * Specifies the path to the text file whose only contents should be 269 * a single line containing the clear-text PIN needed to access the 270 * PKCS11 Key Manager Provider . 271 * 272 * @return Returns the "key-store-pin-file" property definition. 273 */ 274 public StringPropertyDefinition getKeyStorePinFilePropertyDefinition() { 275 return PD_KEY_STORE_PIN_FILE; 276 } 277 278 279 280 /** 281 * Get the "key-store-pin-property" property definition. 282 * <p> 283 * Specifies the name of the Java property that contains the 284 * clear-text PIN needed to access the PKCS11 Key Manager Provider . 285 * 286 * @return Returns the "key-store-pin-property" property definition. 287 */ 288 public StringPropertyDefinition getKeyStorePinPropertyPropertyDefinition() { 289 return PD_KEY_STORE_PIN_PROPERTY; 290 } 291 292 293 294 /** 295 * Managed object client implementation. 296 */ 297 private static class PKCS11KeyManagerProviderCfgClientImpl implements 298 PKCS11KeyManagerProviderCfgClient { 299 300 /** Private implementation. */ 301 private ManagedObject<? extends PKCS11KeyManagerProviderCfgClient> impl; 302 303 304 305 /** Private constructor. */ 306 private PKCS11KeyManagerProviderCfgClientImpl( 307 ManagedObject<? extends PKCS11KeyManagerProviderCfgClient> impl) { 308 this.impl = impl; 309 } 310 311 312 313 /** {@inheritDoc} */ 314 public Boolean isEnabled() { 315 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 316 } 317 318 319 320 /** {@inheritDoc} */ 321 public void setEnabled(boolean value) { 322 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 323 } 324 325 326 327 /** {@inheritDoc} */ 328 public String getJavaClass() { 329 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 330 } 331 332 333 334 /** {@inheritDoc} */ 335 public void setJavaClass(String value) { 336 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 337 } 338 339 340 341 /** {@inheritDoc} */ 342 public String getKeyStorePin() { 343 return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition()); 344 } 345 346 347 348 /** {@inheritDoc} */ 349 public void setKeyStorePin(String value) { 350 impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition(), value); 351 } 352 353 354 355 /** {@inheritDoc} */ 356 public String getKeyStorePinEnvironmentVariable() { 357 return impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition()); 358 } 359 360 361 362 /** {@inheritDoc} */ 363 public void setKeyStorePinEnvironmentVariable(String value) { 364 impl.setPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition(), value); 365 } 366 367 368 369 /** {@inheritDoc} */ 370 public String getKeyStorePinFile() { 371 return impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition()); 372 } 373 374 375 376 /** {@inheritDoc} */ 377 public void setKeyStorePinFile(String value) { 378 impl.setPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition(), value); 379 } 380 381 382 383 /** {@inheritDoc} */ 384 public String getKeyStorePinProperty() { 385 return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition()); 386 } 387 388 389 390 /** {@inheritDoc} */ 391 public void setKeyStorePinProperty(String value) { 392 impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition(), value); 393 } 394 395 396 397 /** {@inheritDoc} */ 398 public ManagedObjectDefinition<? extends PKCS11KeyManagerProviderCfgClient, ? extends PKCS11KeyManagerProviderCfg> definition() { 399 return INSTANCE; 400 } 401 402 403 404 /** {@inheritDoc} */ 405 public PropertyProvider properties() { 406 return impl; 407 } 408 409 410 411 /** {@inheritDoc} */ 412 public void commit() throws ManagedObjectAlreadyExistsException, 413 MissingMandatoryPropertiesException, ConcurrentModificationException, 414 OperationRejectedException, LdapException { 415 impl.commit(); 416 } 417 418 419 420 /** {@inheritDoc} */ 421 public String toString() { 422 return impl.toString(); 423 } 424 } 425 426 427 428 /** 429 * Managed object server implementation. 430 */ 431 private static class PKCS11KeyManagerProviderCfgServerImpl implements 432 PKCS11KeyManagerProviderCfg { 433 434 /** Private implementation. */ 435 private ServerManagedObject<? extends PKCS11KeyManagerProviderCfg> impl; 436 437 /** The value of the "enabled" property. */ 438 private final boolean pEnabled; 439 440 /** The value of the "java-class" property. */ 441 private final String pJavaClass; 442 443 /** The value of the "key-store-pin" property. */ 444 private final String pKeyStorePin; 445 446 /** The value of the "key-store-pin-environment-variable" property. */ 447 private final String pKeyStorePinEnvironmentVariable; 448 449 /** The value of the "key-store-pin-file" property. */ 450 private final String pKeyStorePinFile; 451 452 /** The value of the "key-store-pin-property" property. */ 453 private final String pKeyStorePinProperty; 454 455 456 457 /** Private constructor. */ 458 private PKCS11KeyManagerProviderCfgServerImpl(ServerManagedObject<? extends PKCS11KeyManagerProviderCfg> impl) { 459 this.impl = impl; 460 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 461 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 462 this.pKeyStorePin = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition()); 463 this.pKeyStorePinEnvironmentVariable = impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition()); 464 this.pKeyStorePinFile = impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition()); 465 this.pKeyStorePinProperty = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition()); 466 } 467 468 469 470 /** {@inheritDoc} */ 471 public void addPKCS11ChangeListener( 472 ConfigurationChangeListener<PKCS11KeyManagerProviderCfg> listener) { 473 impl.registerChangeListener(listener); 474 } 475 476 477 478 /** {@inheritDoc} */ 479 public void removePKCS11ChangeListener( 480 ConfigurationChangeListener<PKCS11KeyManagerProviderCfg> listener) { 481 impl.deregisterChangeListener(listener); 482 } 483 /** {@inheritDoc} */ 484 public void addChangeListener( 485 ConfigurationChangeListener<KeyManagerProviderCfg> listener) { 486 impl.registerChangeListener(listener); 487 } 488 489 490 491 /** {@inheritDoc} */ 492 public void removeChangeListener( 493 ConfigurationChangeListener<KeyManagerProviderCfg> listener) { 494 impl.deregisterChangeListener(listener); 495 } 496 497 498 499 /** {@inheritDoc} */ 500 public boolean isEnabled() { 501 return pEnabled; 502 } 503 504 505 506 /** {@inheritDoc} */ 507 public String getJavaClass() { 508 return pJavaClass; 509 } 510 511 512 513 /** {@inheritDoc} */ 514 public String getKeyStorePin() { 515 return pKeyStorePin; 516 } 517 518 519 520 /** {@inheritDoc} */ 521 public String getKeyStorePinEnvironmentVariable() { 522 return pKeyStorePinEnvironmentVariable; 523 } 524 525 526 527 /** {@inheritDoc} */ 528 public String getKeyStorePinFile() { 529 return pKeyStorePinFile; 530 } 531 532 533 534 /** {@inheritDoc} */ 535 public String getKeyStorePinProperty() { 536 return pKeyStorePinProperty; 537 } 538 539 540 541 /** {@inheritDoc} */ 542 public Class<? extends PKCS11KeyManagerProviderCfg> configurationClass() { 543 return PKCS11KeyManagerProviderCfg.class; 544 } 545 546 547 548 /** {@inheritDoc} */ 549 public DN dn() { 550 return impl.getDN(); 551 } 552 553 554 555 /** {@inheritDoc} */ 556 public String toString() { 557 return impl.toString(); 558 } 559 } 560}