001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.util.xmlreader;
016:
017: /**
018: * This class encapsulate the setting that help in configuring a secure store.
019: * The example xml is <pre>
020: ....
021: <secure-store>
022: <type>JKS</type>
023: <algorithm>SunX509</algorithm>
024: <provider>SUN</provider>
025: <key-store-info>
026: <store-file></store-file>
027: <store-password></store-password>
028: <key-password></key-password>
029: </key-store-info>
030: <trust-store-info>
031: <store-file></store-file>
032: <store-password></store-password>
033: </trust-store-info>
034: <secure-store-manager>org.quickserver.security.SecureStoreManager</secure-store-manager>
035: </secure-store>
036: ....
037: </pre>
038: * @see TrustStoreInfo
039: * @see KeyStoreInfo
040: * @see Secure
041: * @author Akshathkumar Shetty
042: * @since 1.4
043: */
044: public class SecureStore implements java.io.Serializable {
045: private String type = "JKS";
046: private String algorithm = "SunX509";
047: private String provider = null;//"SUN";
048: private KeyStoreInfo keyStoreInfo = null;
049: private TrustStoreInfo trustStoreInfo = null;
050: private String secureStoreManager = "org.quickserver.security.SecureStoreManager";
051:
052: /**
053: * Sets the type of keystore.
054: * If not set, it will use <code>JKS</code><br/>
055: * XML Tag: <type>JKS</type>
056: * @param type of keystore.
057: * @see #getType
058: */
059: public void setType(String type) {
060: if (type != null && type.trim().length() != 0)
061: this .type = type;
062: }
063:
064: /**
065: * Returns the type of keystore.
066: * @see #setType
067: */
068: public String getType() {
069: return type;
070: }
071:
072: /**
073: * Sets the algorithm for the QuickServer used for key management
074: * when run in a secure mode.
075: * If not set, it will use <code>SunX509</code><br/>
076: * XML Tag: <algorithm>SunX509</algorithm>
077: * @param algorithm for key management.
078: * @see #getAlgorithm
079: */
080: public void setAlgorithm(String algorithm) {
081: if (algorithm != null && algorithm.trim().length() != 0)
082: this .algorithm = algorithm;
083: }
084:
085: /**
086: * Returns the algorithm for the QuickServer used for key management
087: * when run in a secure mode.
088: * @see #setAlgorithm
089: */
090: public String getAlgorithm() {
091: return algorithm;
092: }
093:
094: /**
095: * Sets the provider of keystore.
096: * Recommended not set, it will auto pick.<br/>
097: * XML Tag: <provider>SUN</provider>
098: * @param provider of keystore.
099: * @see #getProvider
100: */
101: public void setProvider(String provider) {
102: if (provider != null && provider.trim().length() != 0)
103: this .provider = provider;
104: }
105:
106: /**
107: * Returns the provider of keystore.
108: * @see #setProvider
109: */
110: public String getProvider() {
111: return provider;
112: }
113:
114: /**
115: * Sets KeyStore information
116: * XML Tag: <key-store-info></key-store-info>
117: * @param keyStoreInfo key store information
118: * @see #getKeyStoreInfo
119: */
120: public void setKeyStoreInfo(KeyStoreInfo keyStoreInfo) {
121: if (keyStoreInfo != null)
122: this .keyStoreInfo = keyStoreInfo;
123: }
124:
125: /**
126: * Returns KeyStore information.
127: * @see #setKeyStoreInfo
128: */
129: public KeyStoreInfo getKeyStoreInfo() {
130: return keyStoreInfo;
131: }
132:
133: /**
134: * Sets TrustStore information
135: * XML Tag: <trust-store-info></trust-store-info>
136: * @param trustStoreInfo trust store information
137: * @see #getTrustStoreInfo
138: */
139: public void setTrustStoreInfo(TrustStoreInfo trustStoreInfo) {
140: if (trustStoreInfo != null)
141: this .trustStoreInfo = trustStoreInfo;
142: }
143:
144: /**
145: * Returns TrustStore information.
146: * @see #setTrustStoreInfo
147: */
148: public TrustStoreInfo getTrustStoreInfo() {
149: return trustStoreInfo;
150: }
151:
152: /**
153: * Sets the SecureStoreManager class name.
154: * If not set, it will use <code>org.quickserver.security.SecureStoreManager</code><br/>
155: * XML Tag: <secure-store-manager>org.quickserver.security.SecureStoreManager</secure-store-manager>
156: * @param className the fully qualified name of the class that
157: * extends {@link org.quickserver.security.SecureStoreManager}
158: * @see #getSecureStoreManager
159: * @see org.quickserver.security.SecureStoreManager
160: * @since 1.4
161: */
162: public void setSecureStoreManager(String className) {
163: if (className != null && className.trim().length() != 0)
164: this .secureStoreManager = className;
165: }
166:
167: /**
168: * Returns the SecureStoreManager class.
169: * @see #setSecureStoreManager
170: * @see org.quickserver.security.SecureStoreManager
171: * @since 1.4
172: */
173: public String getSecureStoreManager() {
174: return secureStoreManager;
175: }
176:
177: /**
178: * Returns XML config of this class.
179: */
180: public String toXML(String pad) {
181: if (pad == null)
182: pad = "";
183: StringBuffer sb = new StringBuffer();
184: sb.append(pad).append("<secure-store>\n");
185: sb.append(pad).append("\t<type>").append(getType()).append(
186: "</type>\n");
187: sb.append(pad).append("\t<algorithm>").append(getAlgorithm())
188: .append("</algorithm>\n");
189: if (getProvider() != null)
190: sb.append(pad).append("\t<provider>").append(getProvider())
191: .append("</provider>\n");
192: if (getKeyStoreInfo() != null) {
193: sb.append(getKeyStoreInfo().toXML(pad + "\t"));
194: }
195: if (getTrustStoreInfo() != null) {
196: sb.append(getTrustStoreInfo().toXML(pad + "\t"));
197: }
198: sb.append(pad).append("\t<secure-store-manager>").append(
199: getSecureStoreManager()).append(
200: "</secure-store-manager>\n");
201: sb.append(pad + "</secure-store>\n");
202: return sb.toString();
203: }
204: }
|