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