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