KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
18
19 /**
20  * This class encapsulate the setting that help in configuring a secure socket
21  * based QuickServer.
22  * The example xml is <pre>
23     ....
24     &lt;secure&gt;
25         &lt;enable&gt;true&lt;/enable&gt;
26         &lt;load&gt;true&lt;/load&gt;
27         &lt;port&gt;&lt;/port&gt;
28         &lt;protocol&gt;TLS&lt;/protocol&gt;
29         &lt;client-auth-enable&gt;false&lt;/client-auth-enable&gt;
30         &lt;secure-store&gt;
31             ....
32         &lt;/secure-store&gt;
33     &lt;/secure&gt;
34     ....
35  </pre>
36  * @see TrustStoreInfo
37  * @see KeyStoreInfo
38  * @see SecureStore
39  * @author Akshathkumar Shetty
40  * @since 1.4
41  */

42 public class Secure implements java.io.Serializable JavaDoc {
43     private boolean enable = false;
44     private boolean load = false;
45     private int port = -1; //will use servers port
46
private String JavaDoc protocol = "TLS";
47     private boolean clientAuthEnable = false;
48     private SecureStore secureStore = new SecureStore();
49
50     /**
51      * Sets the Secure enable flag.
52      * If not set, it will use <code>false</code><br/>
53      * XML Tag: &lt;secure&gt;&lt;enable&gt;true&lt;/enable&gt;&lt;/secure&gt;
54      * Allowed values = <code>true</code> | <code>false</code>
55      * If enable is set to <code>true</code> load is also set to <code>true</code>.
56      * @see #getEnable
57      */

58     public void setEnable(boolean enable) {
59         this.enable = enable;
60         if(enable==true) {
61             setLoad(true);
62         }
63     }
64     /**
65      * Returns the Secure enable flag.
66      * @see #setEnable
67      */

68     public boolean getEnable() {
69         return enable;
70     }
71     /**
72      * Returns the Secure enable flag.
73      */

74     public boolean isEnable() {
75         return enable;
76     }
77
78
79     /**
80      * Sets the load flag for SSLContext.
81      * If not set, it will use <code>false</code><br/>
82      * XML Tag: &lt;Secure&gt;&lt;load&gt;true&lt;/load&gt;&lt;/Secure&gt;
83      * Allowed values = <code>true</code> | <code>false</code>
84      * @see #getLoad
85      */

86     public void setLoad(boolean load) {
87         this.load = load;
88     }
89     /**
90      * Returns the load flag for SSLContext.
91      * @see #setLoad
92      */

93     public boolean getLoad() {
94         return load;
95     }
96     /**
97      * Returns the load flag for SSLContext.
98      */

99     public boolean isLoad() {
100         return load;
101     }
102
103     /**
104      * Sets the port for the QuickServer to listen on in secure mode.
105      * If not set, it will run on servers non secure port<br/>
106      * XML Tag: &lt;port&gt;&lt;/port&gt;
107      * @param port to listen on.
108      * @see #getPort
109      */

110     public void setPort(int port) {
111         if(port>=0)
112             this.port = port;
113     }
114     /**
115      * Returns the port for the QuickServer to listen on in secure mode.
116      * @see #setPort
117      */

118     public int getPort() {
119         return port;
120     }
121
122
123     /**
124      * Sets the protocol for the QuickServer to listen on in secure mode.
125      * If not set, it will use <code>TLS</code><br/>
126      * XML Tag: &lt;protocol&gt;TLS&lt;/protocol&gt;
127      * @param protocol to listen on in secure mode.
128      * @see #getProtocol
129      */

130     public void setProtocol(String JavaDoc protocol) {
131         if(protocol!=null && protocol.trim().length()!=0)
132             this.protocol = protocol;
133     }
134     /**
135      * Returns the protocol for the QuickServer to listen on in secure mode.
136      * @see #setProtocol
137      */

138     public String JavaDoc getProtocol() {
139         return protocol;
140     }
141
142     /**
143      * Sets whether the connections which are accepted must include
144      * successful client authentication.
145      * If not set, it will use <code>false</code><br/>
146      * XML Tag: &lt;client-auth-enable&gt;false&lt;/client-auth-enable&gt;
147      * @param enable client authentication enable flag
148      * @see #getClientAuthEnable
149      */

150     public void setClientAuthEnable(boolean enable) {
151         this.clientAuthEnable = enable;
152     }
153     /**
154      * Returns whether the connections which are accepted must include
155      * successful client authentication.
156      * @see #setClientAuthEnable
157      */

158     public boolean getClientAuthEnable() {
159         return clientAuthEnable;
160     }
161     /**
162      * Returns whether the connections which are accepted must include
163      * successful client authentication.
164      */

165     public boolean isClientAuthEnable() {
166         return clientAuthEnable;
167     }
168
169     /**
170      * Sets SecureStore information
171      * XML Tag: &lt;secure-store&gt;&lt;/secure-store&gt;
172      * @param secureStore SecureStore information
173      * @see #getSecureStore
174      */

175     public void setSecureStore(SecureStore secureStore) {
176         if(secureStore!=null)
177             this.secureStore = secureStore;
178     }
179     /**
180      * Returns SecureStore information.
181      * @see #setSecureStore
182      */

183     public SecureStore getSecureStore() {
184         return secureStore;
185     }
186
187     /**
188      * Returns XML config of this class.
189      */

190     public String JavaDoc toXML(String JavaDoc pad) {
191         if(pad==null) pad="";
192         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
193         sb.append(pad+"<secure>\n");
194         sb.append(pad+"\t<enable>"+getEnable()+"</enable>\n");
195         sb.append(pad+"\t<load>"+getLoad()+"</load>\n");
196         if(getPort()!=-1)
197             sb.append(pad+"\t<port>"+getPort()+"</port>\n");
198         sb.append(pad+"\t<protocol>"+getProtocol()+"</protocol>\n");
199         sb.append(pad+"\t<client-auth-enable>"+
200             getClientAuthEnable()+"</client-auth-enable>\n");
201         if(getSecureStore()!=null) {
202             sb.append(getSecureStore().toXML(pad+"\t"));
203         }
204         sb.append(pad+"</secure>\n");
205         return sb.toString();
206     }
207 }
208
Popular Tags