diff options
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
8 files changed, 185 insertions, 93 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF index baac735bc..45d76aee0 100644 --- a/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF @@ -17,7 +17,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.jface.text, org.eclipse.ui.workbench.texteditor, org.eclipse.ui.editors, - org.eclipse.pde.ui + org.eclipse.pde.ui, + org.eclipse.update.core, + org.eclipse.update.ui Eclipse-AutoStart: true Bundle-Vendor: University of British Columbia Bundle-ClassPath: bugzilla-core.jar diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugPost.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugPost.java index ab8acbd1c..300f655d4 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugPost.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugPost.java @@ -19,6 +19,7 @@ import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.net.URLEncoder; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -26,8 +27,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.IStatus; @@ -103,13 +102,12 @@ public class BugPost { try { // connect to the bugzilla server - SSLContext ctx = SSLContext.getInstance("TLS"); - - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - HttpURLConnection postConnection = (HttpURLConnection) anURL.openConnection(); - + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(anURL); + if(cntx == null || !(cntx instanceof HttpURLConnection)) + return null; + + HttpURLConnection postConnection = (HttpURLConnection) cntx; + // set the connection method postConnection.setRequestMethod("POST"); postConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaAuthenticator.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaAuthenticator.java new file mode 100644 index 000000000..3d83b56bb --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaAuthenticator.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylar.bugzilla.core; + +import java.net.Authenticator; +import java.net.InetAddress; +import java.net.PasswordAuthentication; + +import org.eclipse.update.internal.ui.security.Authentication; +import org.eclipse.update.internal.ui.security.UserValidationDialog; + +/** + * Update Manager Authenticator Sadly there can only be one registered per VM + */ +public class BugzillaAuthenticator extends Authenticator { + //private Authentication savedPasswordAuthentication; + + /* + * @see Authenticator#getPasswordAuthentication() + */ + protected PasswordAuthentication getPasswordAuthentication() { + // String protocol = getRequestingProtocol(); + String host = getRequestingHost(); // can be null; + InetAddress address = getRequestingSite(); // can be null; + // int port = getRequestingPort(); + String prompt = getRequestingPrompt(); // realm or message, not documented that can be null + // String scheme = getRequestingScheme(); // not documented that can be null + + String hostString = host; + if (hostString == null && address != null) { + address.getHostName(); + } + if (hostString == null) { + hostString = ""; //$NON-NLS-1$ + } + String promptString = prompt; + if (prompt == null) { + promptString = ""; //$NON-NLS-1$ + } + + Authentication auth = UserValidationDialog.getAuthentication( + hostString, promptString); + if (auth != null) + return new PasswordAuthentication(auth.getUser(), auth + .getPassword().toCharArray()); + else + return null; + } +} diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java index 7b65fc999..4a9b70276 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPlugin.java @@ -11,8 +11,19 @@ package org.eclipse.mylar.bugzilla.core; import java.io.IOException; +import java.net.Authenticator; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.URL; +import java.net.URLConnection; +import java.net.Proxy.Type; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; import java.util.List; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; + import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; @@ -26,6 +37,8 @@ import org.eclipse.mylar.bugzilla.core.internal.ProductConfigurationFactory; import org.eclipse.mylar.bugzilla.core.offline.OfflineReportsFile; import org.eclipse.mylar.bugzilla.ui.favorites.FavoritesFile; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.update.internal.core.UpdateCore; +import org.eclipse.update.internal.ui.UpdateUI; import org.osgi.framework.BundleContext; @@ -60,6 +73,8 @@ public class BugzillaPlugin extends AbstractUIPlugin { { super(); } + + Authenticator authenticator = null; /** * Get the singleton instance for the plugin @@ -76,6 +91,12 @@ public class BugzillaPlugin extends AbstractUIPlugin { super.start(context); plugin = this; plugin = this; + + authenticator = UpdateUI.getDefault().getAuthenticator(); + if(authenticator == null) + authenticator = new BugzillaAuthenticator(); + Authenticator.setDefault(authenticator); + readFavoritesFile(); readOfflineReportsFile(); readCachedProductConfiguration(); @@ -284,4 +305,23 @@ public class BugzillaPlugin extends AbstractUIPlugin { public List<IBugzillaBug> getSavedBugReports() { return offlineReportsFile.elements(); } + + public URLConnection getUrlConnection(URL url) throws IOException, NoSuchAlgorithmException, KeyManagementException{ + SSLContext ctx = SSLContext.getInstance("TLS"); + + javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; + ctx.init(null, tm, null); + HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); + + Proxy p = Proxy.NO_PROXY; + if (UpdateCore.getPlugin().getPluginPreferences().getBoolean(UpdateCore.HTTP_PROXY_ENABLE)) { + String proxyHost = UpdateCore.getPlugin().getPluginPreferences().getString(UpdateCore.HTTP_PROXY_HOST); + int proxyPort = UpdateCore.getPlugin().getPluginPreferences().getInt(UpdateCore.HTTP_PROXY_PORT); + + InetSocketAddress sockAddr = new InetSocketAddress(proxyHost, proxyPort); + p = new Proxy(Type.HTTP, sockAddr); + } + URLConnection cntx = url.openConnection(p); + return cntx; + } } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPreferences.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPreferences.java index bd803f781..d54fa6c8c 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPreferences.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaPreferences.java @@ -14,12 +14,11 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.CoreException; @@ -168,17 +167,16 @@ public class BugzillaPreferences ProductConfiguration configuration = null; try { - SSLContext ctx = SSLContext.getInstance("TLS"); - - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - + // append "/show_bug.cgi" to url provided for cases where the connection is successful, // but full path hasn't been specified (i.e. http://hipikat.cs.ubc.ca:8081) URL serverURL = new URL(bugzillaServer.getStringValue() + "/show_bug.cgi"); - - HttpURLConnection serverConnection = (HttpURLConnection) serverURL.openConnection(); + + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(serverURL); + if(cntx == null || !(cntx instanceof HttpURLConnection)) + return false; + + HttpURLConnection serverConnection = (HttpURLConnection)cntx; serverConnection.connect(); diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaRepository.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaRepository.java index 9e8ee67ed..e70f18f4c 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaRepository.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/BugzillaRepository.java @@ -12,10 +12,12 @@ package org.eclipse.mylar.bugzilla.core; import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.net.URLEncoder; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -23,8 +25,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.IStatus; @@ -113,13 +113,7 @@ public class BugzillaRepository BufferedReader in = null; try { - // connect to the bugzilla server - SSLContext ctx = SSLContext.getInstance("TLS"); - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - // create a new input stream for getting the bug String url = bugzillaUrl + "/show_bug.cgi?id=" + id; @@ -137,12 +131,20 @@ public class BugzillaRepository url += "&GoAheadAndLogIn=1&Bugzilla_login=" + URLEncoder.encode(BugzillaPreferences.getUserName(), "UTF-8") + "&Bugzilla_password=" + URLEncoder.encode(BugzillaPreferences.getPassword(), "UTF-8"); } - in = new BufferedReader(new InputStreamReader(new URL(url).openStream())); - - // get the actual bug fron the server and return it - BugReport bug = BugParser.parseBug(in, id, BugzillaPlugin.getDefault().getServerName(), BugzillaPreferences.is218(), BugzillaPreferences.getUserName(), BugzillaPreferences.getPassword()); - - return bug; + URL bugUrl = new URL(url); + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(bugUrl); + if(cntx != null){ + InputStream input = cntx.getInputStream(); + if(input != null) { + in = new BufferedReader(new InputStreamReader(input)); + + // get the actual bug fron the server and return it + BugReport bug = BugParser.parseBug(in, id, BugzillaPlugin.getDefault().getServerName(), BugzillaPreferences.is218(), BugzillaPreferences.getUserName(), BugzillaPreferences.getPassword()); + return bug; + } + } + // TODO handle the error + return null; } catch (MalformedURLException e) { throw e; @@ -205,12 +207,6 @@ public class BugzillaRepository try { // connect to the bugzilla server - SSLContext ctx = SSLContext.getInstance("TLS"); - - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - String urlText = ""; // use the usename and password to get into bugzilla if we have it @@ -227,11 +223,18 @@ public class BugzillaRepository URL url = new URL(bugzillaUrl + "/enter_bug.cgi"+urlText); - // create a new input stream for getting the bug - in = new BufferedReader(new InputStreamReader(url.openStream())); - + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(url); + if(cntx != null){ + InputStream input = cntx.getInputStream(); + if(input != null) { - return new ProductParser(in).getProducts(); + // create a new input stream for getting the bug + in = new BufferedReader(new InputStreamReader(input)); + + return new ProductParser(in).getProducts(); + } + } + return null; } finally { @@ -255,13 +258,6 @@ public class BugzillaRepository BufferedReader in = null; try { - // connect to the bugzilla server - SSLContext ctx = SSLContext.getInstance("TLS"); - - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - // create a new input stream for getting the bug String prodname = URLEncoder.encode(nbm.getProduct(), "UTF-8"); @@ -282,9 +278,16 @@ public class BugzillaRepository */ url += "&GoAheadAndLogIn=1&Bugzilla_login=" + URLEncoder.encode(BugzillaPreferences.getUserName(), "UTF-8") + "&Bugzilla_password=" + URLEncoder.encode(BugzillaPreferences.getPassword(), "UTF-8"); - in = new BufferedReader(new InputStreamReader(new URL(url).openStream())); + URL bugUrl = new URL(url); + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(bugUrl); + if(cntx != null){ + InputStream input = cntx.getInputStream(); + if(input != null) { + in = new BufferedReader(new InputStreamReader(input)); - new NewBugParser(in).parseBugAttributes(nbm, getProd); + new NewBugParser(in).parseBugAttributes(nbm, getProd); + } + } } catch(Exception e) { diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaQueryPageParser.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaQueryPageParser.java index cb3d14f3e..b788acaf5 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaQueryPageParser.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaQueryPageParser.java @@ -12,17 +12,17 @@ package org.eclipse.mylar.bugzilla.core.search; import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.net.URLEncoder; import java.text.ParseException; import java.util.ArrayList; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.IProgressMonitor; @@ -33,7 +33,6 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.core.BugzillaPreferences; import org.eclipse.mylar.bugzilla.core.IBugzillaConstants; -import org.eclipse.mylar.bugzilla.core.TrustAll; import org.eclipse.mylar.bugzilla.core.internal.HtmlStreamTokenizer; import org.eclipse.mylar.bugzilla.core.internal.HtmlTag; import org.eclipse.mylar.bugzilla.core.internal.HtmlStreamTokenizer.Token; @@ -160,33 +159,34 @@ public class BugzillaQueryPageParser // try to connect to the server monitor.subTask("Connecting to server"); - - SSLContext ctx = SSLContext.getInstance("TLS"); - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - monitor.worked(1); + URL url = new URL(this.urlString); + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(url); + if(cntx != null){ + InputStream input = cntx.getInputStream(); + if(input != null) { - URL url = new URL(this.urlString); + monitor.worked(1); + + // initialize the input stream + in = new BufferedReader(new InputStreamReader(input)); + + // increment the position of the status monitor + monitor.worked(2); + + // check if the operation has been cancelled so we can end if it has been + if (monitor.isCanceled()) + monitor.done(); + else + monitor.subTask("Reading values from server"); - // initialize the input stream - in = new BufferedReader(new InputStreamReader(url.openStream())); - - // increment the position of the status monitor - monitor.worked(2); - - // check if the operation has been cancelled so we can end if it has been - if (monitor.isCanceled()) - monitor.done(); - else - monitor.subTask("Reading values from server"); - - // parse the data from the server - parseQueryPage(in); - - // set the operation to being successful - successful = true; + // parse the data from the server + parseQueryPage(in); + + // set the operation to being successful + successful = true; + } + } } catch (LoginException e) { diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaSearchEngine.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaSearchEngine.java index 69ac837c6..45788e55a 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaSearchEngine.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/core/search/BugzillaSearchEngine.java @@ -16,10 +16,9 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLConnection; import java.net.URLEncoder; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.CoreException; @@ -32,10 +31,8 @@ import org.eclipse.mylar.bugzilla.core.BugzillaException; import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.core.BugzillaPreferences; import org.eclipse.mylar.bugzilla.core.IBugzillaConstants; -import org.eclipse.mylar.bugzilla.core.TrustAll; import org.eclipse.search.ui.NewSearchUI; - import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match; import com.sun.org.apache.xerces.internal.impl.xpath.regex.RegularExpression; @@ -134,15 +131,12 @@ public class BugzillaSearchEngine { monitor.beginTask(QUERYING_SERVER, IProgressMonitor.UNKNOWN); collector.aboutToStart(startMatches); - SSLContext ctx = SSLContext.getInstance("TLS"); - - javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[]{new TrustAll()}; - ctx.init(null, tm, null); - HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); - - URL url = new URL(this.urlString); + URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(new URL(urlString)); + if(cntx == null || !(cntx instanceof HttpURLConnection)) + return null; - HttpURLConnection connect = (HttpURLConnection) url.openConnection(); + HttpURLConnection connect = (HttpURLConnection) cntx; + connect.connect(); int responseCode = connect.getResponseCode(); @@ -158,7 +152,7 @@ public class BugzillaSearchEngine { throw new BugzillaException(msg); } - in = new BufferedReader(new InputStreamReader(url.openStream())); + in = new BufferedReader(new InputStreamReader(connect.getInputStream())); Match match = new Match(); String line; |