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