KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ca > certextensions > CertificateExtension


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.core.model.ca.certextensions;
15
16 import java.util.Iterator JavaDoc;
17 import java.util.Properties JavaDoc;
18
19 import org.bouncycastle.asn1.DEREncodable;
20 import org.ejbca.core.model.ca.caadmin.CA;
21 import org.ejbca.core.model.ca.certificateprofiles.CertificateProfile;
22 import org.ejbca.core.model.ra.UserDataVO;
23
24 /**
25  * Base class for a certificate extension.
26  * All extensions should inherit this class.
27  *
28  * The methods that need implementation is getValue
29  *
30  *
31  * @author Philip Vendil 2007 jan 5
32  *
33  * @version $Id: CertificateExtension.java,v 1.1 2007/01/09 16:47:19 herrvendil Exp $
34  */

35
36 public abstract class CertificateExtension {
37     
38     private int id;
39     private String JavaDoc oID;
40     private boolean criticalFlag;
41     private Properties JavaDoc properties;
42     
43     /**
44      * Constuctor for creating a Certificate Extension.
45      */

46     protected CertificateExtension() {
47         super();
48     }
49
50     /**
51      * @return the unique id of the extension
52      */

53     public int getId() {
54         return id;
55     }
56
57     /**
58      * @return The unique OID of the extension
59      */

60     public String JavaDoc getOID() {
61         return oID;
62     }
63     
64     /**
65      * @return flag indicating if the extension should be marked as critical or not.
66      */

67     public boolean isCriticalFlag() {
68         return criticalFlag;
69     }
70
71     /**
72      * The propertes configured for this extension. The properties are stripped
73      * of the beginning "idX.property.". Soo searching for the property
74      * "id1.property.value" only the key "value" should be used in the returned property.
75      *
76      * @return the properties configured for this certificate extension.
77      */

78     protected Properties JavaDoc getProperties() {
79         return properties;
80     }
81     
82     /**
83      * Method that initialises the CertificateExtension
84      *
85      * @param id, the uniqueID of the extension
86      * @param oID, the OID
87      * @param criticalFlag if the extension should be marked as critical or not.
88      * @param config the complete configuration property file. The init method
89      * parses it's own propery file and creates a propertary property file.
90      */

91     public void init(int id, String JavaDoc oID, boolean criticalFlag, Properties JavaDoc config){
92         this.id = id;
93         this.oID = oID;
94         this.criticalFlag = criticalFlag;
95     
96         this.properties = new Properties JavaDoc();
97         Iterator JavaDoc keyIter = config.keySet().iterator();
98         String JavaDoc matchString = "id" + id + ".property.";
99         while(keyIter.hasNext()){
100             String JavaDoc nextKey = (String JavaDoc) keyIter.next();
101             if(nextKey.startsWith(matchString)){
102                 if(nextKey.length() > matchString.length()){
103                   properties.put(nextKey.substring(matchString.length()), config.get(nextKey));
104                 }
105             }
106         }
107     }
108     
109     /**
110      * Method that should return the DEREncodable value used in the extension
111      * this is the method at all implementors must implement.
112      *
113      * @param userData the userdata of the issued certificate.
114      * @param ca the CA data with access to all the keys etc
115      * @param certProfile the certificate profile
116      * @return a DEREncodable never null.
117      */

118     public abstract DEREncodable getValue(UserDataVO userData, CA ca, CertificateProfile certProfile ) throws CertificateExtentionConfigurationException;
119
120     
121 }
122
Popular Tags