KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > xmlreader > SecureStore


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.util.xmlreader;
16
17 /**
18  * This class encapsulate the setting that help in configuring a secure store.
19  * The example xml is <pre>
20     ....
21     &lt;secure-store&gt;
22         &lt;type&gt;JKS&lt;/type&gt;
23         &lt;algorithm&gt;SunX509&lt;/algorithm&gt;
24         &lt;provider&gt;SUN&lt;/provider&gt;
25         &lt;key-store-info&gt;
26             &lt;store-file&gt;&lt;/store-file&gt;
27             &lt;store-password&gt;&lt;/store-password&gt;
28             &lt;key-password&gt;&lt;/key-password&gt;
29         &lt;/key-store-info&gt;
30         &lt;trust-store-info&gt;
31             &lt;store-file&gt;&lt;/store-file&gt;
32             &lt;store-password&gt;&lt;/store-password&gt;
33         &lt;/trust-store-info&gt;
34         &lt;secure-store-manager&gt;org.quickserver.security.SecureStoreManager&lt;/secure-store-manager&gt;
35     &lt;/secure-store&gt;
36     ....
37  </pre>
38  * @see TrustStoreInfo
39  * @see KeyStoreInfo
40  * @see Secure
41  * @author Akshathkumar Shetty
42  * @since 1.4
43  */

44 public class SecureStore implements java.io.Serializable JavaDoc {
45     private String JavaDoc type = "JKS";
46     private String JavaDoc algorithm = "SunX509";
47     private String JavaDoc provider = null;//"SUN";
48
private KeyStoreInfo keyStoreInfo = null;
49     private TrustStoreInfo trustStoreInfo = null;
50     private String JavaDoc secureStoreManager = "org.quickserver.security.SecureStoreManager";
51
52     /**
53      * Sets the type of keystore.
54      * If not set, it will use <code>JKS</code><br/>
55      * XML Tag: &lt;type&gt;JKS&lt;/type&gt;
56      * @param type of keystore.
57      * @see #getType
58      */

59     public void setType(String JavaDoc type) {
60         if(type!=null && type.trim().length()!=0)
61             this.type = type;
62     }
63     /**
64      * Returns the type of keystore.
65      * @see #setType
66      */

67     public String JavaDoc getType() {
68         return type;
69     }
70
71     /**
72      * Sets the algorithm for the QuickServer used for key management
73      * when run in a secure mode.
74      * If not set, it will use <code>SunX509</code><br/>
75      * XML Tag: &lt;algorithm&gt;SunX509&lt;/algorithm&gt;
76      * @param algorithm for key management.
77      * @see #getAlgorithm
78      */

79     public void setAlgorithm(String JavaDoc algorithm) {
80         if(algorithm!=null && algorithm.trim().length()!=0)
81             this.algorithm = algorithm;
82     }
83     /**
84      * Returns the algorithm for the QuickServer used for key management
85      * when run in a secure mode.
86      * @see #setAlgorithm
87      */

88     public String JavaDoc getAlgorithm() {
89         return algorithm;
90     }
91
92     /**
93      * Sets the provider of keystore.
94      * Recommended not set, it will auto pick.<br/>
95      * XML Tag: &lt;provider&gt;SUN&lt;/provider&gt;
96      * @param provider of keystore.
97      * @see #getProvider
98      */

99     public void setProvider(String JavaDoc provider) {
100         if(provider!=null && provider.trim().length()!=0)
101             this.provider = provider;
102     }
103     /**
104      * Returns the provider of keystore.
105      * @see #setProvider
106      */

107     public String JavaDoc getProvider() {
108         return provider;
109     }
110
111     /**
112      * Sets KeyStore information
113      * XML Tag: &lt;key-store-info&gt;&lt;/key-store-info&gt;
114      * @param keyStoreInfo key store information
115      * @see #getKeyStoreInfo
116      */

117     public void setKeyStoreInfo(KeyStoreInfo keyStoreInfo) {
118         if(keyStoreInfo!=null)
119             this.keyStoreInfo = keyStoreInfo;
120     }
121     /**
122      * Returns KeyStore information.
123      * @see #setKeyStoreInfo
124      */

125     public KeyStoreInfo getKeyStoreInfo() {
126         return keyStoreInfo;
127     }
128
129     /**
130      * Sets TrustStore information
131      * XML Tag: &lt;trust-store-info&gt;&lt;/trust-store-info&gt;
132      * @param trustStoreInfo trust store information
133      * @see #getTrustStoreInfo
134      */

135     public void setTrustStoreInfo(TrustStoreInfo trustStoreInfo) {
136         if(trustStoreInfo!=null)
137             this.trustStoreInfo = trustStoreInfo;
138     }
139     /**
140      * Returns TrustStore information.
141      * @see #setTrustStoreInfo
142      */

143     public TrustStoreInfo getTrustStoreInfo() {
144         return trustStoreInfo;
145     }
146
147
148     /**
149      * Sets the SecureStoreManager class name.
150      * If not set, it will use <code>org.quickserver.security.SecureStoreManager</code><br/>
151      * XML Tag: &lt;secure-store-manager&gt;org.quickserver.security.SecureStoreManager&lt;/secure-store-manager&gt;
152      * @param className the fully qualified name of the class that
153      * extends {@link org.quickserver.security.SecureStoreManager}
154      * @see #getSecureStoreManager
155      * @see org.quickserver.security.SecureStoreManager
156      * @since 1.4
157      */

158     public void setSecureStoreManager(String JavaDoc className) {
159         if(className!=null && className.trim().length()!=0)
160             this.secureStoreManager = className;
161     }
162     /**
163      * Returns the SecureStoreManager class.
164      * @see #setSecureStoreManager
165      * @see org.quickserver.security.SecureStoreManager
166      * @since 1.4
167      */

168     public String JavaDoc getSecureStoreManager() {
169         return secureStoreManager;
170     }
171
172     /**
173      * Returns XML config of this class.
174      */

175     public String JavaDoc toXML(String JavaDoc pad) {
176         if(pad==null) pad="";
177         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
178         sb.append(pad).append("<secure-store>\n");
179         sb.append(pad).append("\t<type>").append(getType()).append("</type>\n");
180         sb.append(pad).append("\t<algorithm>").append(getAlgorithm()).append("</algorithm>\n");
181         if(getProvider()!=null)
182             sb.append(pad).append("\t<provider>").append(getProvider()).append("</provider>\n");
183         if(getKeyStoreInfo()!=null) {
184             sb.append(getKeyStoreInfo().toXML(pad+"\t"));
185         }
186         if(getTrustStoreInfo()!=null) {
187             sb.append(getTrustStoreInfo().toXML(pad+"\t"));
188         }
189         sb.append(pad).append("\t<secure-store-manager>").append(getSecureStoreManager()).append("</secure-store-manager>\n");
190         sb.append(pad+"</secure-store>\n");
191         return sb.toString();
192     }
193 }
194
Popular Tags