root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / network / FirewallPage.java @ 38608
History | View | Annotate | Download (10.8 KB)
1 | 5792 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | *
|
||
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 14808 | jmvivo | * Revision 1.9 2006/11/21 10:59:45 fjp
|
47 | 8884 | fjp | * Fallo proxy con usuario y contrase?a
|
48 | *
|
||
49 | 8895 | fjp | * Revision 1.8 2006/11/20 17:29:43 fjp
|
50 | * Fallo proxy con usuario y contrase?a
|
||
51 | *
|
||
52 | 8884 | fjp | * Revision 1.7 2006/10/18 07:55:43 jaume
|
53 | 8142 | jaume | * *** empty log message ***
|
54 | *
|
||
55 | * Revision 1.6 2006/08/22 12:23:05 jaume
|
||
56 | 6810 | jaume | * improved perfomance when saving changes
|
57 | *
|
||
58 | * Revision 1.5 2006/08/22 07:37:17 jaume
|
||
59 | 6805 | jaume | * *** empty log message ***
|
60 | *
|
||
61 | * Revision 1.4 2006/08/04 11:45:12 caballero
|
||
62 | 6662 | caballero | * lanzo una excepci?n cuando falla el m?todo storeValues
|
63 | *
|
||
64 | * Revision 1.3 2006/07/31 10:02:31 jaume
|
||
65 | 6575 | jaume | * *** empty log message ***
|
66 | *
|
||
67 | * Revision 1.2 2006/06/13 07:43:08 fjp
|
||
68 | 5804 | fjp | * Ajustes sobre los cuadros de dialogos de preferencias
|
69 | *
|
||
70 | * Revision 1.1 2006/06/12 16:04:28 caballero
|
||
71 | 5792 | caballero | * Preferencias
|
72 | *
|
||
73 | * Revision 1.11 2006/06/06 10:26:31 jaume
|
||
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | * Revision 1.10 2006/06/05 17:07:17 jaume
|
||
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | * Revision 1.9 2006/06/05 17:00:44 jaume
|
||
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | * Revision 1.8 2006/06/05 16:57:59 jaume
|
||
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | * Revision 1.7 2006/06/05 14:45:06 jaume
|
||
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | * Revision 1.6 2006/06/05 11:00:09 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | * Revision 1.5 2006/06/05 10:39:02 jaume
|
||
92 | * *** empty log message ***
|
||
93 | *
|
||
94 | * Revision 1.4 2006/06/05 10:13:40 jaume
|
||
95 | * *** empty log message ***
|
||
96 | *
|
||
97 | * Revision 1.3 2006/06/05 10:06:08 jaume
|
||
98 | * *** empty log message ***
|
||
99 | *
|
||
100 | * Revision 1.2 2006/06/05 09:51:56 jaume
|
||
101 | * *** empty log message ***
|
||
102 | *
|
||
103 | * Revision 1.1 2006/06/02 10:50:18 jaume
|
||
104 | * *** empty log message ***
|
||
105 | *
|
||
106 | *
|
||
107 | */
|
||
108 | 29630 | jpiera | package org.gvsig.coreplugin.preferences.network; |
109 | 5792 | caballero | |
110 | import java.awt.event.ActionEvent; |
||
111 | import java.awt.event.ActionListener; |
||
112 | 8884 | fjp | import java.net.Authenticator; |
113 | 5792 | caballero | import java.net.MalformedURLException; |
114 | 8884 | fjp | import java.net.PasswordAuthentication; |
115 | 5792 | caballero | import java.net.URL; |
116 | import java.util.Properties; |
||
117 | import java.util.prefs.Preferences; |
||
118 | |||
119 | import javax.swing.ImageIcon; |
||
120 | import javax.swing.JCheckBox; |
||
121 | import javax.swing.JPanel; |
||
122 | import javax.swing.JPasswordField; |
||
123 | import javax.swing.JTextField; |
||
124 | |||
125 | 29630 | jpiera | import org.gvsig.andami.PluginServices; |
126 | import org.gvsig.andami.preferences.AbstractPreferencePage; |
||
127 | import org.gvsig.andami.preferences.StoreException; |
||
128 | 5792 | caballero | |
129 | 29630 | jpiera | |
130 | 5792 | caballero | public class FirewallPage extends AbstractPreferencePage { |
131 | |||
132 | // Quiz? en vez de usar un prefs cada vez deber?amos de tener una clase gvSIG.java
|
||
133 | // donde se guarden todas las preferencias, queda m?s limpio y m?s claro si se hace
|
||
134 | // un: gvSIG.getProperty("gvsig.connection") que lo de abajo.
|
||
135 | private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" ); |
||
136 | private JCheckBox httpEnabled; |
||
137 | private JTextField httpHost; |
||
138 | private JTextField httpPort; |
||
139 | private JTextField httpUser; |
||
140 | private JPasswordField httpPass; |
||
141 | private JTextField httpNonProxy; |
||
142 | private JCheckBox socksEnabled; |
||
143 | private JTextField socksHost; |
||
144 | private JTextField socksPort; |
||
145 | 8142 | jaume | protected static String id = FirewallPage.class.getName(); |
146 | 5792 | caballero | private ImageIcon icon; |
147 | |||
148 | 8884 | fjp | private static final class ProxyAuth extends Authenticator { |
149 | private PasswordAuthentication auth; |
||
150 | |||
151 | private ProxyAuth(String user, String pass) { |
||
152 | auth = new PasswordAuthentication(user, pass.toCharArray()); |
||
153 | } |
||
154 | |||
155 | protected PasswordAuthentication getPasswordAuthentication() { |
||
156 | return auth;
|
||
157 | } |
||
158 | } |
||
159 | |||
160 | 5792 | caballero | public FirewallPage() {
|
161 | super();
|
||
162 | 38564 | jjdelcerro | icon=PluginServices.getIconTheme().get("edit-setup-firewall");
|
163 | 5792 | caballero | setParentID(NetworkPage.id); |
164 | 6575 | jaume | // checkbox
|
165 | 5792 | caballero | addComponent(httpEnabled = new JCheckBox(PluginServices.getText(this, |
166 | "options.firewall.http.enabled")));
|
||
167 | // proxy host
|
||
168 | addComponent(PluginServices.getText(this, "options.firewall.http.host") + ":", |
||
169 | httpHost = new JTextField("", 15)); |
||
170 | // proxy port
|
||
171 | addComponent(PluginServices.getText(this, "options.firewall.http.port") + ":", |
||
172 | httpPort = new JTextField("", 15)); |
||
173 | // proxy username
|
||
174 | addComponent(PluginServices.getText(this, "options.firewall.http.user") + ":", |
||
175 | httpUser = new JTextField("", 15)); |
||
176 | // proxy password
|
||
177 | addComponent(PluginServices.getText(this, "options.firewall.http.password") + ":", |
||
178 | httpPass = new JPasswordField("", 15)); |
||
179 | // no proxy for
|
||
180 | addComponent(PluginServices.getText(this, "options.firewall.http.nonProxy") + ":", |
||
181 | httpNonProxy = new JTextField("", 15)); |
||
182 | |||
183 | 6575 | jaume | // checkbox
|
184 | addComponent(socksEnabled = new JCheckBox(PluginServices.getText(this, |
||
185 | "options.firewall.socks.enabled")));
|
||
186 | // proxy host
|
||
187 | addComponent(PluginServices.getText(this, "options.firewall.socks.host") + ":", |
||
188 | socksHost = new JTextField("", 15)); |
||
189 | // proxy port
|
||
190 | addComponent(PluginServices.getText(this, "options.firewall.socks.port") + ":", |
||
191 | socksPort = new JTextField("", 15)); |
||
192 | |||
193 | } |
||
194 | |||
195 | public void initializeValues() { |
||
196 | |||
197 | 5792 | caballero | boolean enabled = prefs.getBoolean("firewall.http.enabled", false); |
198 | httpEnabled.setSelected(enabled); |
||
199 | httpHost.setEnabled(enabled); |
||
200 | httpHost.setText(prefs.get("firewall.http.host","")); |
||
201 | httpPort.setEnabled(enabled); |
||
202 | httpPort.setText(prefs.get("firewall.http.port","")); |
||
203 | httpUser.setEnabled(enabled); |
||
204 | httpUser.setText(prefs.get("firewall.http.user","")); |
||
205 | httpPass.setEnabled(enabled); |
||
206 | httpPass.setText(prefs.get("firewall.http.password","")); |
||
207 | httpNonProxy.setEnabled(enabled); |
||
208 | httpNonProxy.setText(prefs.get("firewall.http.nonProxyHosts","")); |
||
209 | |||
210 | |||
211 | httpEnabled.addActionListener(new ActionHandler());
|
||
212 | |||
213 | |||
214 | enabled = prefs.getBoolean("firewall.socks.enabled", false); |
||
215 | socksEnabled.setSelected(enabled); |
||
216 | socksHost.setEnabled(enabled); |
||
217 | socksHost.setText(prefs.get("firewall.socks.host","")); |
||
218 | socksPort.setEnabled(enabled); |
||
219 | socksPort.setText(prefs.get("firewall.socks.port","")); |
||
220 | |||
221 | socksEnabled.addActionListener(new ActionHandler());
|
||
222 | |||
223 | } |
||
224 | |||
225 | public String getID() { |
||
226 | return id;
|
||
227 | } |
||
228 | |||
229 | public String getTitle() { |
||
230 | return PluginServices.getText(this, "pref.network.firewall"); |
||
231 | } |
||
232 | |||
233 | public JPanel getPanel() { |
||
234 | return this; |
||
235 | } |
||
236 | |||
237 | 6662 | caballero | public void storeValues() throws StoreException{ |
238 | 5792 | caballero | Properties systemSettings = System.getProperties(); |
239 | URL httpURL, socksURL;
|
||
240 | |||
241 | try {
|
||
242 | 30328 | jpiera | httpURL = new URL(createURL(httpHost.getText(), httpPort.getText())); |
243 | 5792 | caballero | prefs.putBoolean("firewall.http.enabled", httpEnabled.isSelected());
|
244 | prefs.put("firewall.http.host", httpHost.getText());
|
||
245 | prefs.put("firewall.http.port", httpPort.getText());
|
||
246 | 8884 | fjp | String proxyUser = httpUser.getText();
|
247 | String proxyPassword = new String(httpPass.getPassword()); |
||
248 | prefs.put("firewall.http.user", proxyUser);
|
||
249 | prefs.put("firewall.http.password", proxyPassword);
|
||
250 | 5792 | caballero | prefs.put("firewall.http.nonProxyHosts", httpNonProxy.getText());
|
251 | |||
252 | if (httpEnabled.isSelected()) {
|
||
253 | 30328 | jpiera | systemSettings.put("http.proxySet", "true"); |
254 | 5792 | caballero | systemSettings.put("http.proxyHost", httpURL.getHost());
|
255 | systemSettings.put("http.proxyPort", httpURL.getPort()+""); |
||
256 | 8884 | fjp | systemSettings.put("http.proxyUserName", proxyUser);
|
257 | systemSettings.put("http.proxyPassword", proxyPassword);
|
||
258 | 5792 | caballero | } else {
|
259 | 30328 | jpiera | systemSettings.put("http.proxySet", "false"); |
260 | 5792 | caballero | systemSettings.remove("http.proxyHost");
|
261 | systemSettings.remove("http.proxyPort");
|
||
262 | systemSettings.remove("http.proxyUserName");
|
||
263 | systemSettings.remove("http.proxyPassword");
|
||
264 | 8895 | fjp | prefs.remove("firewall.http.host");
|
265 | prefs.remove("firewall.http.port");
|
||
266 | prefs.remove("firewall.http.user");
|
||
267 | prefs.remove("firewall.http.password");
|
||
268 | prefs.remove("firewall.http.nonProxyHosts");
|
||
269 | |||
270 | 5792 | caballero | } |
271 | |||
272 | System.setProperties(systemSettings);
|
||
273 | 8884 | fjp | if (proxyUser != null ) |
274 | { |
||
275 | Authenticator.setDefault(new ProxyAuth(proxyUser, |
||
276 | proxyPassword)); |
||
277 | } else {
|
||
278 | Authenticator.setDefault(new ProxyAuth("", "")); |
||
279 | } |
||
280 | 14808 | jmvivo | |
281 | 5792 | caballero | } catch (MalformedURLException e) { |
282 | if (httpEnabled.isSelected()) {
|
||
283 | 6662 | caballero | throw new StoreException(PluginServices.getText(this, "options.firewall.http.incorrect_host"),e); |
284 | 5792 | caballero | } |
285 | } |
||
286 | |||
287 | try {
|
||
288 | 30328 | jpiera | socksURL = new URL(createURL(socksHost.getText(),socksPort.getText())); |
289 | 5792 | caballero | |
290 | prefs.putBoolean("firewall.socks.enabled", socksEnabled.isSelected());
|
||
291 | prefs.put("firewall.socks.host", socksHost.getText());
|
||
292 | prefs.put("firewall.socks.port", socksPort.getText());
|
||
293 | |||
294 | if (socksEnabled.isSelected()) {
|
||
295 | systemSettings.put("socksProxyHost", socksURL.getHost());
|
||
296 | systemSettings.put("socksProxyPort", socksURL.getPort()+""); |
||
297 | } else {
|
||
298 | systemSettings.remove("socksProxyHost");
|
||
299 | systemSettings.remove("socksProxyPort");
|
||
300 | } |
||
301 | |||
302 | System.setProperties(systemSettings);
|
||
303 | 6810 | jaume | |
304 | 5792 | caballero | } catch (MalformedURLException e) { |
305 | if (socksEnabled.isSelected()) {
|
||
306 | 6662 | caballero | throw new StoreException(PluginServices.getText(this, "options.firewall.socks.incorrect_host"),e); |
307 | 5792 | caballero | } |
308 | } |
||
309 | } |
||
310 | |||
311 | public void initializeDefaults() { |
||
312 | httpEnabled.setSelected(false);
|
||
313 | httpHost.setText("");
|
||
314 | httpPort.setText("");
|
||
315 | httpUser.setText("");
|
||
316 | httpPass.setText("");
|
||
317 | httpNonProxy.setText("");
|
||
318 | socksEnabled.setSelected(false);
|
||
319 | socksHost.setText("");
|
||
320 | socksPort.setText("");
|
||
321 | |||
322 | } |
||
323 | |||
324 | 6575 | jaume | private class ActionHandler implements ActionListener { |
325 | 5792 | caballero | public void actionPerformed(ActionEvent evt) { |
326 | httpHost.setEnabled(httpEnabled.isSelected()); |
||
327 | httpPort.setEnabled(httpEnabled.isSelected()); |
||
328 | httpUser.setEnabled(httpEnabled.isSelected()); |
||
329 | httpPass.setEnabled(httpEnabled.isSelected()); |
||
330 | httpNonProxy.setEnabled(httpEnabled.isSelected()); |
||
331 | socksHost.setEnabled(socksEnabled.isSelected()); |
||
332 | socksPort.setEnabled(socksEnabled.isSelected()); |
||
333 | } |
||
334 | } |
||
335 | |||
336 | public ImageIcon getIcon() { |
||
337 | return icon;
|
||
338 | } |
||
339 | 6575 | jaume | |
340 | 6805 | jaume | public boolean isValueChanged() { |
341 | return hasChanged();
|
||
342 | } |
||
343 | 6575 | jaume | |
344 | 6810 | jaume | public void setChangesApplied() { |
345 | setChanged(false);
|
||
346 | 30328 | jpiera | } |
347 | 6805 | jaume | |
348 | 30328 | jpiera | private String createURL(String host, String port){ |
349 | StringBuffer strUrl = new StringBuffer(); |
||
350 | // add "http://" prefix if it wasn't included.
|
||
351 | strUrl.append(host.toLowerCase().startsWith("http://")
|
||
352 | ? host.toLowerCase() : "http://"+ host.toLowerCase());
|
||
353 | 6810 | jaume | |
354 | 30328 | jpiera | // add port
|
355 | strUrl.append(!port.equals("")
|
||
356 | ? ":" + port : ""); |
||
357 | return strUrl.toString();
|
||
358 | } |
||
359 | 5792 | caballero | } |