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.FileBasedKeyManagerProviderCfgClient;
051import org.forgerock.opendj.server.config.server.FileBasedKeyManagerProviderCfg;
052import org.forgerock.opendj.server.config.server.KeyManagerProviderCfg;
053
054
055
056/**
057 * An interface for querying the File Based Key Manager Provider
058 * managed object definition meta information.
059 * <p>
060 * The File Based Key Manager Provider can be used to obtain the
061 * server certificate from a key store file on the local file system.
062 */
063public final class FileBasedKeyManagerProviderCfgDefn extends ManagedObjectDefinition<FileBasedKeyManagerProviderCfgClient, FileBasedKeyManagerProviderCfg> {
064
065  // The singleton configuration definition instance.
066  private static final FileBasedKeyManagerProviderCfgDefn INSTANCE = new FileBasedKeyManagerProviderCfgDefn();
067
068
069
070  // The "java-class" property definition.
071  private static final ClassPropertyDefinition PD_JAVA_CLASS;
072
073
074
075  // The "key-store-file" property definition.
076  private static final StringPropertyDefinition PD_KEY_STORE_FILE;
077
078
079
080  // The "key-store-pin" property definition.
081  private static final StringPropertyDefinition PD_KEY_STORE_PIN;
082
083
084
085  // The "key-store-pin-environment-variable" property definition.
086  private static final StringPropertyDefinition PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE;
087
088
089
090  // The "key-store-pin-file" property definition.
091  private static final StringPropertyDefinition PD_KEY_STORE_PIN_FILE;
092
093
094
095  // The "key-store-pin-property" property definition.
096  private static final StringPropertyDefinition PD_KEY_STORE_PIN_PROPERTY;
097
098
099
100  // The "key-store-type" property definition.
101  private static final StringPropertyDefinition PD_KEY_STORE_TYPE;
102
103
104
105  // Build the "java-class" property definition.
106  static {
107      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
108      builder.setOption(PropertyOption.MANDATORY);
109      builder.setOption(PropertyOption.ADVANCED);
110      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
111      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.FileBasedKeyManagerProvider");
112      builder.setDefaultBehaviorProvider(provider);
113      builder.addInstanceOf("org.opends.server.api.KeyManagerProvider");
114      PD_JAVA_CLASS = builder.getInstance();
115      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
116  }
117
118
119
120  // Build the "key-store-file" property definition.
121  static {
122      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-file");
123      builder.setOption(PropertyOption.MANDATORY);
124      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-file"));
125      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
126      builder.setPattern(".*", "FILE");
127      PD_KEY_STORE_FILE = builder.getInstance();
128      INSTANCE.registerPropertyDefinition(PD_KEY_STORE_FILE);
129  }
130
131
132
133  // Build the "key-store-pin" property definition.
134  static {
135      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin");
136      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin"));
137      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
138      PD_KEY_STORE_PIN = builder.getInstance();
139      INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN);
140  }
141
142
143
144  // Build the "key-store-pin-environment-variable" property definition.
145  static {
146      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-environment-variable");
147      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-environment-variable"));
148      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
149      builder.setPattern(".*", "STRING");
150      PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE = builder.getInstance();
151      INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE);
152  }
153
154
155
156  // Build the "key-store-pin-file" property definition.
157  static {
158      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-file");
159      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-file"));
160      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
161      builder.setPattern(".*", "FILE");
162      PD_KEY_STORE_PIN_FILE = builder.getInstance();
163      INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_FILE);
164  }
165
166
167
168  // Build the "key-store-pin-property" property definition.
169  static {
170      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-pin-property");
171      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-pin-property"));
172      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
173      builder.setPattern(".*", "STRING");
174      PD_KEY_STORE_PIN_PROPERTY = builder.getInstance();
175      INSTANCE.registerPropertyDefinition(PD_KEY_STORE_PIN_PROPERTY);
176  }
177
178
179
180  // Build the "key-store-type" property definition.
181  static {
182      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "key-store-type");
183      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "key-store-type"));
184      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
185      builder.setPattern(".*", "STRING");
186      PD_KEY_STORE_TYPE = builder.getInstance();
187      INSTANCE.registerPropertyDefinition(PD_KEY_STORE_TYPE);
188  }
189
190
191
192  // Register the tags associated with this managed object definition.
193  static {
194    INSTANCE.registerTag(Tag.valueOf("security"));
195  }
196
197
198
199  /**
200   * Get the File Based Key Manager Provider configuration definition
201   * singleton.
202   *
203   * @return Returns the File Based Key Manager Provider configuration
204   *         definition singleton.
205   */
206  public static FileBasedKeyManagerProviderCfgDefn getInstance() {
207    return INSTANCE;
208  }
209
210
211
212  /**
213   * Private constructor.
214   */
215  private FileBasedKeyManagerProviderCfgDefn() {
216    super("file-based-key-manager-provider", KeyManagerProviderCfgDefn.getInstance());
217  }
218
219
220
221  /**
222   * {@inheritDoc}
223   */
224  public FileBasedKeyManagerProviderCfgClient createClientConfiguration(
225      ManagedObject<? extends FileBasedKeyManagerProviderCfgClient> impl) {
226    return new FileBasedKeyManagerProviderCfgClientImpl(impl);
227  }
228
229
230
231  /**
232   * {@inheritDoc}
233   */
234  public FileBasedKeyManagerProviderCfg createServerConfiguration(
235      ServerManagedObject<? extends FileBasedKeyManagerProviderCfg> impl) {
236    return new FileBasedKeyManagerProviderCfgServerImpl(impl);
237  }
238
239
240
241  /**
242   * {@inheritDoc}
243   */
244  public Class<FileBasedKeyManagerProviderCfg> getServerConfigurationClass() {
245    return FileBasedKeyManagerProviderCfg.class;
246  }
247
248
249
250  /**
251   * Get the "enabled" property definition.
252   * <p>
253   * Indicates whether the File Based Key Manager Provider is enabled
254   * for use.
255   *
256   * @return Returns the "enabled" property definition.
257   */
258  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
259    return KeyManagerProviderCfgDefn.getInstance().getEnabledPropertyDefinition();
260  }
261
262
263
264  /**
265   * Get the "java-class" property definition.
266   * <p>
267   * The fully-qualified name of the Java class that provides the File
268   * Based Key Manager Provider implementation.
269   *
270   * @return Returns the "java-class" property definition.
271   */
272  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
273    return PD_JAVA_CLASS;
274  }
275
276
277
278  /**
279   * Get the "key-store-file" property definition.
280   * <p>
281   * Specifies the path to the file that contains the private key
282   * information. This may be an absolute path, or a path that is
283   * relative to the OpenDJ instance root.
284   * <p>
285   * Changes to this property will take effect the next time that the
286   * key manager is accessed.
287   *
288   * @return Returns the "key-store-file" property definition.
289   */
290  public StringPropertyDefinition getKeyStoreFilePropertyDefinition() {
291    return PD_KEY_STORE_FILE;
292  }
293
294
295
296  /**
297   * Get the "key-store-pin" property definition.
298   * <p>
299   * Specifies the clear-text PIN needed to access the File Based Key
300   * Manager Provider .
301   *
302   * @return Returns the "key-store-pin" property definition.
303   */
304  public StringPropertyDefinition getKeyStorePinPropertyDefinition() {
305    return PD_KEY_STORE_PIN;
306  }
307
308
309
310  /**
311   * Get the "key-store-pin-environment-variable" property definition.
312   * <p>
313   * Specifies the name of the environment variable that contains the
314   * clear-text PIN needed to access the File Based Key Manager
315   * Provider .
316   *
317   * @return Returns the "key-store-pin-environment-variable" property definition.
318   */
319  public StringPropertyDefinition getKeyStorePinEnvironmentVariablePropertyDefinition() {
320    return PD_KEY_STORE_PIN_ENVIRONMENT_VARIABLE;
321  }
322
323
324
325  /**
326   * Get the "key-store-pin-file" property definition.
327   * <p>
328   * Specifies the path to the text file whose only contents should be
329   * a single line containing the clear-text PIN needed to access the
330   * File Based Key Manager Provider .
331   *
332   * @return Returns the "key-store-pin-file" property definition.
333   */
334  public StringPropertyDefinition getKeyStorePinFilePropertyDefinition() {
335    return PD_KEY_STORE_PIN_FILE;
336  }
337
338
339
340  /**
341   * Get the "key-store-pin-property" property definition.
342   * <p>
343   * Specifies the name of the Java property that contains the
344   * clear-text PIN needed to access the File Based Key Manager
345   * Provider .
346   *
347   * @return Returns the "key-store-pin-property" property definition.
348   */
349  public StringPropertyDefinition getKeyStorePinPropertyPropertyDefinition() {
350    return PD_KEY_STORE_PIN_PROPERTY;
351  }
352
353
354
355  /**
356   * Get the "key-store-type" property definition.
357   * <p>
358   * Specifies the format for the data in the key store file.
359   * <p>
360   * Valid values should always include 'JKS' and 'PKCS12', but
361   * different implementations may allow other values as well. If no
362   * value is provided, the JVM-default value is used. Changes to this
363   * configuration attribute will take effect the next time that the
364   * key manager is accessed.
365   *
366   * @return Returns the "key-store-type" property definition.
367   */
368  public StringPropertyDefinition getKeyStoreTypePropertyDefinition() {
369    return PD_KEY_STORE_TYPE;
370  }
371
372
373
374  /**
375   * Managed object client implementation.
376   */
377  private static class FileBasedKeyManagerProviderCfgClientImpl implements
378    FileBasedKeyManagerProviderCfgClient {
379
380    // Private implementation.
381    private ManagedObject<? extends FileBasedKeyManagerProviderCfgClient> impl;
382
383
384
385    // Private constructor.
386    private FileBasedKeyManagerProviderCfgClientImpl(
387        ManagedObject<? extends FileBasedKeyManagerProviderCfgClient> impl) {
388      this.impl = impl;
389    }
390
391
392
393    /**
394     * {@inheritDoc}
395     */
396    public Boolean isEnabled() {
397      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
398    }
399
400
401
402    /**
403     * {@inheritDoc}
404     */
405    public void setEnabled(boolean value) {
406      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
407    }
408
409
410
411    /**
412     * {@inheritDoc}
413     */
414    public String getJavaClass() {
415      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
416    }
417
418
419
420    /**
421     * {@inheritDoc}
422     */
423    public void setJavaClass(String value) {
424      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
425    }
426
427
428
429    /**
430     * {@inheritDoc}
431     */
432    public String getKeyStoreFile() {
433      return impl.getPropertyValue(INSTANCE.getKeyStoreFilePropertyDefinition());
434    }
435
436
437
438    /**
439     * {@inheritDoc}
440     */
441    public void setKeyStoreFile(String value) {
442      impl.setPropertyValue(INSTANCE.getKeyStoreFilePropertyDefinition(), value);
443    }
444
445
446
447    /**
448     * {@inheritDoc}
449     */
450    public String getKeyStorePin() {
451      return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition());
452    }
453
454
455
456    /**
457     * {@inheritDoc}
458     */
459    public void setKeyStorePin(String value) {
460      impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition(), value);
461    }
462
463
464
465    /**
466     * {@inheritDoc}
467     */
468    public String getKeyStorePinEnvironmentVariable() {
469      return impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition());
470    }
471
472
473
474    /**
475     * {@inheritDoc}
476     */
477    public void setKeyStorePinEnvironmentVariable(String value) {
478      impl.setPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition(), value);
479    }
480
481
482
483    /**
484     * {@inheritDoc}
485     */
486    public String getKeyStorePinFile() {
487      return impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition());
488    }
489
490
491
492    /**
493     * {@inheritDoc}
494     */
495    public void setKeyStorePinFile(String value) {
496      impl.setPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition(), value);
497    }
498
499
500
501    /**
502     * {@inheritDoc}
503     */
504    public String getKeyStorePinProperty() {
505      return impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition());
506    }
507
508
509
510    /**
511     * {@inheritDoc}
512     */
513    public void setKeyStorePinProperty(String value) {
514      impl.setPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition(), value);
515    }
516
517
518
519    /**
520     * {@inheritDoc}
521     */
522    public String getKeyStoreType() {
523      return impl.getPropertyValue(INSTANCE.getKeyStoreTypePropertyDefinition());
524    }
525
526
527
528    /**
529     * {@inheritDoc}
530     */
531    public void setKeyStoreType(String value) {
532      impl.setPropertyValue(INSTANCE.getKeyStoreTypePropertyDefinition(), value);
533    }
534
535
536
537    /**
538     * {@inheritDoc}
539     */
540    public ManagedObjectDefinition<? extends FileBasedKeyManagerProviderCfgClient, ? extends FileBasedKeyManagerProviderCfg> definition() {
541      return INSTANCE;
542    }
543
544
545
546    /**
547     * {@inheritDoc}
548     */
549    public PropertyProvider properties() {
550      return impl;
551    }
552
553
554
555    /**
556     * {@inheritDoc}
557     */
558    public void commit() throws ManagedObjectAlreadyExistsException,
559        MissingMandatoryPropertiesException, ConcurrentModificationException,
560        OperationRejectedException, LdapException {
561      impl.commit();
562    }
563
564  }
565
566
567
568  /**
569   * Managed object server implementation.
570   */
571  private static class FileBasedKeyManagerProviderCfgServerImpl implements
572    FileBasedKeyManagerProviderCfg {
573
574    // Private implementation.
575    private ServerManagedObject<? extends FileBasedKeyManagerProviderCfg> impl;
576
577    // The value of the "enabled" property.
578    private final boolean pEnabled;
579
580    // The value of the "java-class" property.
581    private final String pJavaClass;
582
583    // The value of the "key-store-file" property.
584    private final String pKeyStoreFile;
585
586    // The value of the "key-store-pin" property.
587    private final String pKeyStorePin;
588
589    // The value of the "key-store-pin-environment-variable" property.
590    private final String pKeyStorePinEnvironmentVariable;
591
592    // The value of the "key-store-pin-file" property.
593    private final String pKeyStorePinFile;
594
595    // The value of the "key-store-pin-property" property.
596    private final String pKeyStorePinProperty;
597
598    // The value of the "key-store-type" property.
599    private final String pKeyStoreType;
600
601
602
603    // Private constructor.
604    private FileBasedKeyManagerProviderCfgServerImpl(ServerManagedObject<? extends FileBasedKeyManagerProviderCfg> impl) {
605      this.impl = impl;
606      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
607      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
608      this.pKeyStoreFile = impl.getPropertyValue(INSTANCE.getKeyStoreFilePropertyDefinition());
609      this.pKeyStorePin = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyDefinition());
610      this.pKeyStorePinEnvironmentVariable = impl.getPropertyValue(INSTANCE.getKeyStorePinEnvironmentVariablePropertyDefinition());
611      this.pKeyStorePinFile = impl.getPropertyValue(INSTANCE.getKeyStorePinFilePropertyDefinition());
612      this.pKeyStorePinProperty = impl.getPropertyValue(INSTANCE.getKeyStorePinPropertyPropertyDefinition());
613      this.pKeyStoreType = impl.getPropertyValue(INSTANCE.getKeyStoreTypePropertyDefinition());
614    }
615
616
617
618    /**
619     * {@inheritDoc}
620     */
621    public void addFileBasedChangeListener(
622        ConfigurationChangeListener<FileBasedKeyManagerProviderCfg> listener) {
623      impl.registerChangeListener(listener);
624    }
625
626
627
628    /**
629     * {@inheritDoc}
630     */
631    public void removeFileBasedChangeListener(
632        ConfigurationChangeListener<FileBasedKeyManagerProviderCfg> listener) {
633      impl.deregisterChangeListener(listener);
634    }
635    /**
636     * {@inheritDoc}
637     */
638    public void addChangeListener(
639        ConfigurationChangeListener<KeyManagerProviderCfg> listener) {
640      impl.registerChangeListener(listener);
641    }
642
643
644
645    /**
646     * {@inheritDoc}
647     */
648    public void removeChangeListener(
649        ConfigurationChangeListener<KeyManagerProviderCfg> listener) {
650      impl.deregisterChangeListener(listener);
651    }
652
653
654
655    /**
656     * {@inheritDoc}
657     */
658    public boolean isEnabled() {
659      return pEnabled;
660    }
661
662
663
664    /**
665     * {@inheritDoc}
666     */
667    public String getJavaClass() {
668      return pJavaClass;
669    }
670
671
672
673    /**
674     * {@inheritDoc}
675     */
676    public String getKeyStoreFile() {
677      return pKeyStoreFile;
678    }
679
680
681
682    /**
683     * {@inheritDoc}
684     */
685    public String getKeyStorePin() {
686      return pKeyStorePin;
687    }
688
689
690
691    /**
692     * {@inheritDoc}
693     */
694    public String getKeyStorePinEnvironmentVariable() {
695      return pKeyStorePinEnvironmentVariable;
696    }
697
698
699
700    /**
701     * {@inheritDoc}
702     */
703    public String getKeyStorePinFile() {
704      return pKeyStorePinFile;
705    }
706
707
708
709    /**
710     * {@inheritDoc}
711     */
712    public String getKeyStorePinProperty() {
713      return pKeyStorePinProperty;
714    }
715
716
717
718    /**
719     * {@inheritDoc}
720     */
721    public String getKeyStoreType() {
722      return pKeyStoreType;
723    }
724
725
726
727    /**
728     * {@inheritDoc}
729     */
730    public Class<? extends FileBasedKeyManagerProviderCfg> configurationClass() {
731      return FileBasedKeyManagerProviderCfg.class;
732    }
733
734
735
736    /**
737     * {@inheritDoc}
738     */
739    public DN dn() {
740      return impl.getDN();
741    }
742
743  }
744}