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