diff options
author | Omair Majid <[email protected]> | 2010-11-23 10:05:06 -0500 |
---|---|---|
committer | Omair Majid <[email protected]> | 2010-11-23 10:05:06 -0500 |
commit | 870e7d61c514309119de218c3d7181ceeeffcb38 (patch) | |
tree | 5f7bc0ac13c08275d872bc645e20716c5f51b627 /plugin/icedteanp | |
parent | b2311631f029fd5f77e62d36807678a099bd6a4d (diff) |
integrate basic proxy configuration support
2010-11-23 Omair Majid <[email protected]>
* netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java:
Add KEY_PROXY_TYPE, KEY_PROXY_SAME, KEY_PROXY_AUTO_CONFIG_URL,
KEY_PROXY_BYPASS_LIST, KEY_PROXY_BYPASS_LOCAL, KEY_PROXY_HTTP_HOST,
KEY_PROXY_HTTP_PORT, KEY_PROXY_HTTPS_HOST, KEY_PROXY_HTTPS_PORT,
KEY_PROXY_FTP_HOST, KEY_PROXY_FTP_PORT, KEY_PROXY_SOCKS4_HOST,
KEY_PROXY_SOCKS4_PORT, and KEY_PROXY_OVERRIDE_HOSTS.
(loadDefaultProperties): Use the new constants.
* netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java: New
class.
(JNLPProxySelector): New method.
(parseConfiguration): New method. Initializes this object by
querying the configuration.
(getHost): New method.
(getPort): New method.
(connectFailed): New method.
(select): New method. Returns a list of appropriate proxies to use
for a given uri.
(inBypassList): New method. Return true if the host in the URI
should be bypassed for proxy purposes.
(isLocalHost): New method.
(getFromConfiguration): New method. Finds a proxy based on
configuration.
(getFromPAC): New method.
(getFromBrowser): New method.
* netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
(initialize): Install proxy selector and authenticator.
* plugin/icedteanp/java/sun/applet/PluginMain.java
(init): Do not install authenticator.
(CustomAuthenticator): Moved to...
* netx/net/sourceforge/jnlp/security/JNLPAuthenticator.java: Here.
* plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java
Moved to...
* netx/net/sourceforge/jnlp/security
/PasswordAuthenticationDialog.java: Here.
* plugin/icedteanp/java/sun/applet/PluginProxySelector.java: Extend
JNLPProxySelector.
(select): Renamed to...
(getFromBrowser): New method.
Diffstat (limited to 'plugin/icedteanp')
3 files changed, 7 insertions, 275 deletions
diff --git a/plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java b/plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java deleted file mode 100644 index 843603e..0000000 --- a/plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java +++ /dev/null @@ -1,241 +0,0 @@ -/* PasswordAuthenticationDialog -- requests authentication information from users - Copyright (C) 2009 Red Hat - -This file is part of IcedTea. - -IcedTea is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -IcedTea is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with IcedTea; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package sun.applet; - -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.net.PasswordAuthentication; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPasswordField; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; - -/** - * Modal non-minimizable dialog to request http authentication credentials - */ - -public class PasswordAuthenticationDialog extends JDialog { - - private JLabel jlInfo = new JLabel(""); - private JTextField jtfUserName = new JTextField(); - private JPasswordField jpfPassword = new JPasswordField(); - private boolean userCancelled; - - public PasswordAuthenticationDialog() { - initialize(); - } - - /** - * Initialized the dialog components - */ - - public void initialize() { - - setTitle("IcedTea Java Plugin - Authorization needed to proceed"); - - setLayout(new GridBagLayout()); - - JLabel jlUserName = new JLabel("Username: "); - JLabel jlPassword = new JLabel("Password: "); - JButton jbOK = new JButton("OK"); - JButton jbCancel = new JButton("Cancel"); - - jtfUserName.setSize(20, 10); - jpfPassword.setSize(20, 10); - - GridBagConstraints c; - - c = new GridBagConstraints(); - c.fill = c.HORIZONTAL; - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 2; - c.insets = new Insets(10, 5, 3, 3); - add(jlInfo, c); - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 1; - c.insets = new Insets(10, 5, 3, 3); - add(jlUserName, c); - - c = new GridBagConstraints(); - c.fill = c.HORIZONTAL; - c.gridx = 1; - c.gridy = 1; - c.insets = new Insets(10, 5, 3, 3); - c.weightx = 1.0; - add(jtfUserName, c); - - - c = new GridBagConstraints(); - c.gridx = 0; - c.gridy = 2; - c.insets = new Insets(5, 5, 3, 3); - add(jlPassword, c); - - c = new GridBagConstraints(); - c.fill = c.HORIZONTAL; - c.gridx = 1; - c.gridy = 2; - c.insets = new Insets(5, 5, 3, 3); - c.weightx = 1.0; - add(jpfPassword, c); - - c = new GridBagConstraints(); - c.anchor = c.SOUTHEAST; - c.gridx = 1; - c.gridy = 3; - c.insets = new Insets(5, 5, 3, 70); - c.weightx = 0.0; - add(jbCancel, c); - - c = new GridBagConstraints(); - c.anchor = c.SOUTHEAST; - c.gridx = 1; - c.gridy = 3; - c.insets = new Insets(5, 5, 3, 3); - c.weightx = 0.0; - add(jbOK, c); - - setMinimumSize(new Dimension(400,150)); - setMaximumSize(new Dimension(1024,150)); - setAlwaysOnTop(true); - - setSize(400,150); - setLocationRelativeTo(null); - - // OK => read supplied info and pass it on - jbOK.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - userCancelled = false; - dispose(); - } - }); - - // Cancel => discard supplied info and pass on an empty auth - jbCancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - userCancelled = true; - dispose(); - } - }); - - // "return" key in either user or password field => OK - - jtfUserName.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - userCancelled = false; - dispose(); - } - }); - - jpfPassword.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - userCancelled = false; - dispose(); - } - }); - } - - /** - * Present a dialog to the user asking them for authentication information - * - * @param hostThe host for with authentication is needed - * @param port The port being accessed - * @param prompt The prompt (realm) as presented by the server - * @param type The type of server (proxy/web) - * @return PasswordAuthentication containing the credentials (empty credentials if user cancelled) - */ - protected PasswordAuthentication askUser(String host, int port, String prompt, String type) { - PasswordAuthentication auth = null; - - host += port != -1 ? ":" + port : ""; - - // This frame is reusable. So reset everything first. - userCancelled = true; - jlInfo.setText("<html>The " + type + " server at " + host + " is requesting authentication. It says \"" + prompt + "\"</html>"); - - try { - SwingUtilities.invokeAndWait( new Runnable() { - public void run() { - // show dialog to user - setVisible(true); - } - }); - - PluginDebug.debug("password dialog shown"); - - // wait until dialog is gone - while (this.isShowing()) { - try { - Thread.sleep(200); - } catch (InterruptedException ie) { - } - } - - PluginDebug.debug("password dialog closed"); - - if (!userCancelled) { - auth = new PasswordAuthentication(jtfUserName.getText(), jpfPassword.getText().toCharArray()); - } - } catch (Exception e) { - e.printStackTrace(); - - // Nothing else we can do. Empty auth will be returned - } - - return auth; - } - - public static void main(String[] args) { - PasswordAuthenticationDialog frame = new PasswordAuthenticationDialog(); - - PasswordAuthentication auth = frame.askUser("127.0.0.1", 3128, "Password for local proxy", "proxy"); - - System.err.println("Auth info: " + auth.getUserName() + ":" + new String(auth.getPassword())); - System.exit(0); - } -} diff --git a/plugin/icedteanp/java/sun/applet/PluginMain.java b/plugin/icedteanp/java/sun/applet/PluginMain.java index f270d9e..6c83ffd 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMain.java +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java @@ -77,6 +77,7 @@ import java.util.Properties; import net.sourceforge.jnlp.runtime.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.security.JNLPAuthenticator; /** * The main entry point into PluginAppletViewer. @@ -202,8 +203,9 @@ public class PluginMain boolean installAuthenticator = Boolean.valueOf(JNLPRuntime.getConfiguration() .getProperty(DeploymentConfiguration.KEY_SECURITY_INSTALL_AUTHENTICATOR)); if (installAuthenticator) { - Authenticator.setDefault(new CustomAuthenticator()); + Authenticator.setDefault(new JNLPAuthenticator()); } + // override the proxy selector set by JNLPRuntime ProxySelector.setDefault(new PluginProxySelector()); CookieManager ckManager = new PluginCookieManager(); @@ -218,24 +220,4 @@ public class PluginMain return streamHandler.getMessage(); } - static class CustomAuthenticator extends Authenticator { - - public PasswordAuthentication getPasswordAuthentication() { - - // No security check is required here, because the only way to - // set parameters for which auth info is needed - // (Authenticator:requestPasswordAuthentication()), has a security - // check - - String type = this.getRequestorType() == RequestorType.PROXY ? "proxy" : "web"; - - // request auth info from user - PasswordAuthenticationDialog pwDialog = new PasswordAuthenticationDialog(); - PasswordAuthentication auth = pwDialog.askUser(this.getRequestingHost(), this.getRequestingPort(), this.getRequestingPrompt(), type); - - // send it along - return auth; - } - } - } diff --git a/plugin/icedteanp/java/sun/applet/PluginProxySelector.java b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java index dff8ded..f6a096f 100644 --- a/plugin/icedteanp/java/sun/applet/PluginProxySelector.java +++ b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java @@ -37,18 +37,16 @@ exception statement from your version. */ package sun.applet; -import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; -import java.net.ProxySelector; -import java.net.SocketAddress; import java.net.URI; import java.util.Date; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import net.sourceforge.jnlp.runtime.JNLPProxySelector; + /** * Proxy selector implementation for plugin network functions. * @@ -58,17 +56,10 @@ import java.util.List; * */ -public class PluginProxySelector extends ProxySelector { +public class PluginProxySelector extends JNLPProxySelector { private TimedHashMap<String, Proxy> proxyCache = new TimedHashMap<String, Proxy>(); - - @Override - public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { - // If the connection fails, there is little we can do here. Just print the exception - ioe.printStackTrace(); - } - /** * Selects the appropriate proxy (or DIRECT connection method) for the given URI * @@ -76,7 +67,7 @@ public class PluginProxySelector extends ProxySelector { * @return A list of Proxy objects that are usable for this URI */ @Override - public List<Proxy> select(URI uri) { + protected List<Proxy> getFromBrowser(URI uri) { List<Proxy> proxyList = new ArrayList<Proxy>(); |