View Javadoc

1   /*
2    * The MIT License
3    *
4    * Original work sponsored and donated by National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
5    *
6    * Copyright (C) 2011 National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   *
26   * $HeadURL: https://svn.softwareborsen.dk/sosi/trunk/modules/seal/src/main/java/dk/sosi/seal/pki/CertificationAuthorityFactory.java $
27   * $Id: CertificationAuthorityFactory.java 8697 2011-09-02 10:33:55Z chg@lakeside.dk $
28   */
29  package dk.sosi.seal.pki;
30  
31  import dk.sosi.seal.pki.impl.PropertiesSOSIConfiguration;
32  import dk.sosi.seal.pki.impl.federationcert.FederationCertificateStoreAdapter;
33  import dk.sosi.seal.pki.impl.intermediate.IntermediateCertificateStoreAdapter;
34  
35  import java.util.Properties;
36  
37  /**
38   * Factory class for creating <code>CertificationAuthority</code> instances.
39   *
40   * @author ads@lakeside.dk
41   * @author $LastChangedBy: chg@lakeside.dk $
42   * @version $Revision: 8697 $
43   * @since 2.0
44   */
45  public class CertificationAuthorityFactory {
46  
47      /**
48       * The string identifying the OCES production CA.
49       */
50      public static final String OCES_CA = "OCES_CA";
51  
52      /**
53       * The string identifying the OCES test CA.
54       */
55      public static final String OCES_SYSTEMTEST_CA = "OCES_SYSTEMTEST_CA";
56  
57      /**
58       * Create an instance of CertificationAuthority.
59       *
60       * @param properties                   The initialization <code>Properties</code> of the system
61       * @param identifier                   id of the CA to be created
62       * @param certificateStatusChecker     <code>CertificateStatusChecker</code> instance used for CRL status check.
63       * @param intermediateCertificateCache <code>intermediateCertificateCache</code> instance used for retrieving and caching intermediate certificates.
64       * @return new instance of requested CA.
65       * @throws PKIException if construction fails.
66       * @deprecated Use @link(#create) instead
67       */
68      @Deprecated
69      public static CertificationAuthority createNewCertificationAuthority(Properties properties, String identifier, CertificateStatusChecker certificateStatusChecker, IntermediateCertificateCache intermediateCertificateCache) throws PKIException {
70          if (identifier.equals(OCES_CA)) {
71              return new OCESCertificationAuthority(properties, certificateStatusChecker, intermediateCertificateCache);
72          } else if (identifier.equals(OCES_SYSTEMTEST_CA)) {
73              return new OCESTestCertificationAuthority(properties, certificateStatusChecker, intermediateCertificateCache);
74          }
75          throw new PKIException("Unknown CA identifier: " + identifier);
76      }
77  
78      /**
79       * Create an instance of CertificationAuthority.
80       *
81       * @param properties               The initialization <code>Properties</code> of the system
82       * @param identifier               id of the CA to be created
83       * @param certificateStatusChecker <code>CertificateStatusChecker</code> instance used for CRL status check.
84       * @param cache                    <code>Cache</code> instance used for retrieving and caching certificates.
85       * @return new instance of requested CA.
86       * @throws PKIException if construction fails.
87       */
88      public static CertificationAuthority create(Properties properties, String identifier, CertificateStatusChecker certificateStatusChecker, CertificateCache cache) throws PKIException {
89          IntermediateCertificateCache intermediateCertificateStoreAdapter = new IntermediateCertificateStoreAdapter(cache);
90  
91          if (identifier.equals(OCES_CA)) {
92              SOSIConfiguration configuration = PropertiesSOSIConfiguration.createWithDefaultOcesProperties(properties);
93              FederationCertificateResolver federationCertificateResolver = new FederationCertificateStoreAdapter(configuration, cache);
94              return new OCESCertificationAuthority(configuration, certificateStatusChecker, intermediateCertificateStoreAdapter, federationCertificateResolver);
95          } else if (identifier.equals(OCES_SYSTEMTEST_CA)) {
96              SOSIConfiguration configuration = PropertiesSOSIConfiguration.createWithDefaultOcesTestProperties(properties);
97              FederationCertificateResolver federationCertificateResolver = new FederationCertificateStoreAdapter(configuration, cache);
98              return new OCESTestCertificationAuthority(configuration, certificateStatusChecker, intermediateCertificateStoreAdapter, federationCertificateResolver);
99          } else {
100             throw new PKIException("Unknown CA identifier: " + identifier);
101         }
102     }
103 }