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: import java.util.*;
018:
019: /**
020: * This class encapsulate the setting that help in configuring a secure socket
021: * based QuickServer.
022: * The example xml is <pre>
023: ....
024: <secure>
025: <enable>true</enable>
026: <load>true</load>
027: <port></port>
028: <protocol>TLS</protocol>
029: <client-auth-enable>false</client-auth-enable>
030: <secure-store>
031: ....
032: </secure-store>
033: </secure>
034: ....
035: </pre>
036: * @see TrustStoreInfo
037: * @see KeyStoreInfo
038: * @see SecureStore
039: * @author Akshathkumar Shetty
040: * @since 1.4
041: */
042: public class Secure implements java.io.Serializable {
043: private boolean enable = false;
044: private boolean load = false;
045: private int port = -1; //will use servers port
046: private String protocol = "TLS";
047: private boolean clientAuthEnable = false;
048: private SecureStore secureStore = new SecureStore();
049:
050: /**
051: * Sets the Secure enable flag.
052: * If not set, it will use <code>false</code><br/>
053: * XML Tag: <secure><enable>true</enable></secure>
054: * Allowed values = <code>true</code> | <code>false</code>
055: * If enable is set to <code>true</code> load is also set to <code>true</code>.
056: * @see #getEnable
057: */
058: public void setEnable(boolean enable) {
059: this .enable = enable;
060: if (enable == true) {
061: setLoad(true);
062: }
063: }
064:
065: /**
066: * Returns the Secure enable flag.
067: * @see #setEnable
068: */
069: public boolean getEnable() {
070: return enable;
071: }
072:
073: /**
074: * Returns the Secure enable flag.
075: */
076: public boolean isEnable() {
077: return enable;
078: }
079:
080: /**
081: * Sets the load flag for SSLContext.
082: * If not set, it will use <code>false</code><br/>
083: * XML Tag: <Secure><load>true</load></Secure>
084: * Allowed values = <code>true</code> | <code>false</code>
085: * @see #getLoad
086: */
087: public void setLoad(boolean load) {
088: this .load = load;
089: }
090:
091: /**
092: * Returns the load flag for SSLContext.
093: * @see #setLoad
094: */
095: public boolean getLoad() {
096: return load;
097: }
098:
099: /**
100: * Returns the load flag for SSLContext.
101: */
102: public boolean isLoad() {
103: return load;
104: }
105:
106: /**
107: * Sets the port for the QuickServer to listen on in secure mode.
108: * If not set, it will run on servers non secure port<br/>
109: * XML Tag: <port></port>
110: * @param port to listen on.
111: * @see #getPort
112: */
113: public void setPort(int port) {
114: if (port >= 0)
115: this .port = port;
116: }
117:
118: /**
119: * Returns the port for the QuickServer to listen on in secure mode.
120: * @see #setPort
121: */
122: public int getPort() {
123: return port;
124: }
125:
126: /**
127: * Sets the protocol for the QuickServer to listen on in secure mode.
128: * If not set, it will use <code>TLS</code><br/>
129: * XML Tag: <protocol>TLS</protocol>
130: * @param protocol to listen on in secure mode.
131: * @see #getProtocol
132: */
133: public void setProtocol(String protocol) {
134: if (protocol != null && protocol.trim().length() != 0)
135: this .protocol = protocol;
136: }
137:
138: /**
139: * Returns the protocol for the QuickServer to listen on in secure mode.
140: * @see #setProtocol
141: */
142: public String getProtocol() {
143: return protocol;
144: }
145:
146: /**
147: * Sets whether the connections which are accepted must include
148: * successful client authentication.
149: * If not set, it will use <code>false</code><br/>
150: * XML Tag: <client-auth-enable>false</client-auth-enable>
151: * @param enable client authentication enable flag
152: * @see #getClientAuthEnable
153: */
154: public void setClientAuthEnable(boolean enable) {
155: this .clientAuthEnable = enable;
156: }
157:
158: /**
159: * Returns whether the connections which are accepted must include
160: * successful client authentication.
161: * @see #setClientAuthEnable
162: */
163: public boolean getClientAuthEnable() {
164: return clientAuthEnable;
165: }
166:
167: /**
168: * Returns whether the connections which are accepted must include
169: * successful client authentication.
170: */
171: public boolean isClientAuthEnable() {
172: return clientAuthEnable;
173: }
174:
175: /**
176: * Sets SecureStore information
177: * XML Tag: <secure-store></secure-store>
178: * @param secureStore SecureStore information
179: * @see #getSecureStore
180: */
181: public void setSecureStore(SecureStore secureStore) {
182: if (secureStore != null)
183: this .secureStore = secureStore;
184: }
185:
186: /**
187: * Returns SecureStore information.
188: * @see #setSecureStore
189: */
190: public SecureStore getSecureStore() {
191: return secureStore;
192: }
193:
194: /**
195: * Returns XML config of this class.
196: */
197: public String toXML(String pad) {
198: if (pad == null)
199: pad = "";
200: StringBuffer sb = new StringBuffer();
201: sb.append(pad + "<secure>\n");
202: sb.append(pad + "\t<enable>" + getEnable() + "</enable>\n");
203: sb.append(pad + "\t<load>" + getLoad() + "</load>\n");
204: if (getPort() != -1)
205: sb.append(pad + "\t<port>" + getPort() + "</port>\n");
206: sb.append(pad + "\t<protocol>" + getProtocol()
207: + "</protocol>\n");
208: sb.append(pad + "\t<client-auth-enable>"
209: + getClientAuthEnable() + "</client-auth-enable>\n");
210: if (getSecureStore() != null) {
211: sb.append(getSecureStore().toXML(pad + "\t"));
212: }
213: sb.append(pad + "</secure>\n");
214: return sb.toString();
215: }
216: }
|