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