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