diff options
author | Frank Becker | 2014-04-21 14:21:38 +0000 |
---|---|---|
committer | Frank Becker | 2014-05-01 18:04:23 +0000 |
commit | 0b7e999d7f580408625d23596533327de4b8ce20 (patch) | |
tree | 651170ca2881eb1f76a1062604708f5ea37b22f0 /org.eclipse.mylyn.bugzilla.core/src | |
parent | b024cac5adf1d5db280988b77e9d5af082d931b2 (diff) | |
download | org.eclipse.mylyn.tasks-0b7e999d7f580408625d23596533327de4b8ce20.tar.gz org.eclipse.mylyn.tasks-0b7e999d7f580408625d23596533327de4b8ce20.tar.xz org.eclipse.mylyn.tasks-0b7e999d7f580408625d23596533327de4b8ce20.zip |
433095: update Bugzilla instances to 4.5.4, 4.4.4, 4.2.9, and 4.0.13
Change-Id: I6dc70a5798f0c17681a243bd1f9fc50fc585645d
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=433095
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core/src')
3 files changed, 158 insertions, 43 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java index 24e4a4d45..b9e65c0df 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java @@ -105,6 +105,8 @@ import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; */ public class BugzillaClient { + private static final String INPUT_TYPE_HIDDEN_NAME_BUGZILLA_LOGIN_TOKEN = "<input type=\"hidden\" name=\"Bugzilla_login_token"; //$NON-NLS-1$ + private static final String UNKNOWN_REPOSITORY_ERROR = "An unknown repository error has occurred: "; //$NON-NLS-1$ private static final String COOKIE_BUGZILLA_LOGIN = "Bugzilla_login"; //$NON-NLS-1$ @@ -286,7 +288,7 @@ public class BugzillaClient { * in order to provide an even better solution for bug 196056 the size of the bugzilla configuration downloaded must * be reduced. By using a cached version of the config.cgi this can reduce traffic considerably: * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.phoenix/infra-scripts/bugzilla/?root=Technology_Project - * + * * @param serverURL * @return a GetMethod with possibly gzip encoded response body, so caller MUST check with * "gzip".equals(method.getResponseHeader("Content-encoding") or use the utility method @@ -414,6 +416,74 @@ public class BugzillaClient { return zipped; } + private static String getStringFromInputStream(InputStream is) throws IOException { + + BufferedReader br = null; + StringBuilder sb = new StringBuilder(); + + String line; + try { + + br = new BufferedReader(new InputStreamReader(is)); + while ((line = br.readLine()) != null) { + sb.append(line); + sb.append("\n"); + } + } finally { + if (br != null) { + br.close(); + } + } + + return sb.toString(); + + } + + private String getBugzillaLoginTokenIfExists(IProgressMonitor monitor) throws CoreException { + String loginToken = null; + GzipPostMethod getMethod = new GzipPostMethod(WebUtil.getRequestPath(repositoryUrl.toString()) + "/index.cgi", + true); + try { + getMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" //$NON-NLS-1$ //$NON-NLS-2$ + + getCharacterEncoding()); + + getMethod.setDoAuthentication(true); + getMethod.setFollowRedirects(false); + httpClient.getState().clearCookies(); + // for Bugzilla > 4.4.2 but not 4.5, 4.5.1 or 4.5.2 we need first the Bugzilla_login_request_cookie + int code = WebUtil.execute(httpClient, hostConfiguration, getMethod, monitor); + WebUtil.releaseConnection(getMethod, monitor); + if (code != HttpURLConnection.HTTP_OK) { + loggedIn = false; + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + RepositoryStatus.ERROR_NETWORK, "Http error: " + HttpStatus.getStatusText(code))); //$NON-NLS-1$ + } + + // for Bugzilla > 4.4.2 but not 4.5, 4.5.1 or 4.5.2 we now do the real authentication + code = WebUtil.execute(httpClient, hostConfiguration, getMethod, monitor); + if (code != HttpURLConnection.HTTP_OK) { + loggedIn = false; + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + RepositoryStatus.ERROR_NETWORK, "Http error: " + HttpStatus.getStatusText(code))); //$NON-NLS-1$ + } + InputStream is = getResponseStream(getMethod, monitor); + String result = getStringFromInputStream(is); + if (result.lastIndexOf(INPUT_TYPE_HIDDEN_NAME_BUGZILLA_LOGIN_TOKEN) != -1) { + int index = result.lastIndexOf(INPUT_TYPE_HIDDEN_NAME_BUGZILLA_LOGIN_TOKEN); + String loginTokenAndRest = result.substring(index); + int valueStart = loginTokenAndRest.indexOf("value=\"") + 7; //$NON-NLS-1$ + int valueEnd = loginTokenAndRest.indexOf("\">"); //$NON-NLS-1$ + loginToken = loginTokenAndRest.substring(valueStart, valueEnd); + } + } catch (IOException e) { + throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + RepositoryStatus.ERROR_IO, repositoryUrl.toString(), e)); + } finally { + WebUtil.releaseConnection(getMethod, monitor); + } + return loginToken; + } + public void authenticate(IProgressMonitor monitor) throws CoreException { if (loggedIn || (!hasAuthenticationCredentials() && !hasHTTPAuthenticationCredentials())) { return; @@ -424,10 +494,18 @@ public class BugzillaClient { GzipPostMethod postMethod = null; try { - hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); - NameValuePair[] formData = new NameValuePair[2]; + NameValuePair[] formData; + + String loginToken = getBugzillaLoginTokenIfExists(monitor); + if (loginToken != null) { + formData = new NameValuePair[3]; + formData[2] = new NameValuePair("Bugzilla_login_token", loginToken); + } else { + formData = new NameValuePair[2]; + } + AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); AuthenticationCredentials httpAuthCredentials = location.getCredentials(AuthenticationType.HTTP); if (credentials == null && httpAuthCredentials == null) { @@ -459,7 +537,6 @@ public class BugzillaClient { } postMethod.setDoAuthentication(true); postMethod.setFollowRedirects(false); - httpClient.getState().clearCookies(); if (httpAuthCredentials != null && httpAuthCredentials.getUserName() != null && httpAuthCredentials.getUserName().length() > 0) { @@ -914,22 +991,7 @@ public class BugzillaClient { postMethod.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); List<PartBase> parts = new ArrayList<PartBase>(); parts.add(new StringPart(IBugzillaConstants.POST_INPUT_ACTION, VALUE_ACTION_INSERT, getCharacterEncoding())); - AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); - String username; - String password; - if (credentials != null) { - username = credentials.getUserName(); - password = credentials.getPassword(); - } else { - username = null; - password = null; - } - if (username != null && password != null) { - parts.add(new StringPart(IBugzillaConstants.POST_INPUT_BUGZILLA_LOGIN, username, getCharacterEncoding())); - parts.add(new StringPart(IBugzillaConstants.POST_INPUT_BUGZILLA_PASSWORD, password, - getCharacterEncoding())); - } parts.add(new StringPart(IBugzillaConstants.POST_INPUT_BUGID, bugReportID, getCharacterEncoding())); if (description != null) { parts.add(new StringPart(IBugzillaConstants.POST_INPUT_DESCRIPTION, description, getCharacterEncoding())); @@ -1037,7 +1099,7 @@ public class BugzillaClient { /** * calling method must release the connection on the returned PostMethod once finished. - * + * * @throws CoreException */ private GzipPostMethod postFormData(String formUrl, NameValuePair[] formData, IProgressMonitor monitor) @@ -2473,7 +2535,7 @@ public class BugzillaClient { /** * Currently only necessary for testing. Allows setting of the descriptor file property. - * + * * @param bugzillaDescriptorFile * @param canonicalPath */ @@ -2517,7 +2579,7 @@ public class BugzillaClient { /** * Copies all bytes in the given source stream to the given destination stream. Neither streams are closed. - * + * * @param source * the given source stream * @param destination @@ -2536,7 +2598,7 @@ public class BugzillaClient { /** * Returns the given file path with its separator character changed from the given old separator to the given new * separator. - * + * * @param path * a file path * @param oldSeparator diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java index 7a2513e65..8111dff97 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java @@ -55,7 +55,7 @@ public interface IBugzillaConstants { public static final String POST_INPUT_DATA = "data"; //$NON-NLS-1$ - public static final String URL_POST_LOGIN = "/index.cgi"; //$NON-NLS-1$ + public static final String URL_POST_LOGIN = "/index.cgi?GoAheadAndLogIn=1"; //$NON-NLS-1$ public static final String URL_POST_ATTACHMENT_UPLOAD = "/attachment.cgi"; //$NON-NLS-1$ @@ -163,7 +163,7 @@ public interface IBugzillaConstants { // Default values for keys static final String[] DEFAULT_STATUS_VALUES = { "Unconfirmed", "New", "Assigned", "Reopened", "Resolved", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$ - "Verified", "Closed" }; //$NON-NLS-1$//$NON-NLS-2$ + "Verified", "Closed" }; //$NON-NLS-1$//$NON-NLS-2$ static final String[] DEFAULT_PRESELECTED_STATUS_VALUES = { "New", "Assigned", "Reopened" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -172,15 +172,15 @@ public interface IBugzillaConstants { // "Worksforme", "Moved" }; static final String[] DEFAULT_SEVERITY_VALUES = { "blocker", "critical", "major", "normal", "minor", "trivial", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - "enhancement" }; //$NON-NLS-1$ + "enhancement" }; //$NON-NLS-1$ static final String[] DEFAULT_PRIORITY_VALUES = { "P1", "P2", "P3", "P4", "P5" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ static final String[] DEFAULT_HARDWARE_VALUES = { "All", "Macintosh", "PC", "Power PC", "Sun", "Other" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ static final String[] DEFAULT_OS_VALUES = { "All", "AIX Motif", "Windows 95", "Windows 98", "Windows CE", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$ - "Windows ME", "Windows 2000", "Windows NT", "Windows XP", "Windows All", "MacOS X", "Linux", "Linux-GTK", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - "Linux-Motif", "HP-UX", "Neutrino", "QNX-Photon", "Solaris", "Unix All", "other" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$//$NON-NLS-7$ + "Windows ME", "Windows 2000", "Windows NT", "Windows XP", "Windows All", "MacOS X", "Linux", "Linux-GTK", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ + "Linux-Motif", "HP-UX", "Neutrino", "QNX-Photon", "Solaris", "Unix All", "other" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$//$NON-NLS-7$ static final String[] DEFAULT_PRODUCT_VALUES = {}; @@ -278,7 +278,7 @@ public interface IBugzillaConstants { public static final String BUGZILLA_PREFIX_ISPRIVATE = "isprivate_"; //$NON-NLS-1$ - // Bugzilla Task Attribute Editor Types + // Bugzilla Task Attribute Editor Types public static final String EDITOR_TYPE_KEYWORDS = "bugzilla.editor.keywords"; //$NON-NLS-1$ diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java index da997ac99..00f2a0774 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java @@ -16,6 +16,7 @@ import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -60,10 +61,12 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { public static final String XML_BUGZILLA_VERSION = "Bugzilla.version"; //$NON-NLS-1$ - public static final String XML_BUGZILLA_TIME = "Bugzilla.time"; //$NON-NLS-1$ + public static final String XML_BUGZILLA_TIME = "Bugzilla.time"; //$NON-NLS-1$ public static final String XML_USER_LOGIN = "User.login"; //$NON-NLS-1$ + public static final String XML_USER_LOGOUT = "User.logout"; //$NON-NLS-1$ + public static final String XML_USER_GET = "User.get"; //$NON-NLS-1$ public static final String XML_BUG_ATTACHMENTS = "Bug.attachments"; //$NON-NLS-1$ @@ -86,7 +89,7 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { /* * Parameter Definitions - * + * */ public static final String XML_PARAMETER_LOGIN = "login"; //$NON-NLS-1$ @@ -103,9 +106,11 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { public static final String XML_PARAMETER_EXCLUDE_FIELDS = "exclude_fields"; //$NON-NLS-1$ + public static final String XML_PARAMETER_TOKEN = "Bugzilla_token"; //$NON-NLS-1$ + /* * Response Parameter Definitions - * + * */ public static final String XML_RESPONSE_DB_TIME = "db_time"; //$NON-NLS-1$ @@ -129,12 +134,16 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { public static final String XML_RESPONSE_BUGS = "bugs"; //$NON-NLS-1$ + public static final String XML_RESPONSE_TOKEN = "token"; //$NON-NLS-1$ + /* * Fields - * + * */ private int userID = -1; + private String token; + private final BugzillaClient bugzillaClient; public BugzillaXmlRpcClient(AbstractWebLocation location, HttpClient client, BugzillaClient bugzillaClient) { @@ -221,6 +230,11 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { } }); if (response != null) { Integer result = response2Integer(response, XML_RESPONSE_ID); + if (response.get(XML_RESPONSE_TOKEN) != null) { + token = response2String(response, XML_RESPONSE_TOKEN); + } else { + token = null; + } return result; } return null; @@ -230,6 +244,22 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { return userID; } + public void logout(final IProgressMonitor monitor) throws XmlRpcException { + try { + (new BugzillaXmlRpcOperation<Integer>(this) { + @Override + public Integer execute() throws XmlRpcException { + call(monitor, XML_USER_LOGOUT); + return -1; + } + }).execute(); + } finally { + userID = -1; + token = null; + } + return; + } + private Object[] getUserInfoInternal(final IProgressMonitor monitor, final Object[] callParm) throws XmlRpcException { return (new BugzillaXmlRpcOperation<Object[]>(this) { @@ -245,18 +275,24 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { @SuppressWarnings("serial") public Object[] getUserInfoFromIDs(final IProgressMonitor monitor, final Integer[] ids) throws XmlRpcException { - return getUserInfoInternal(monitor, new Object[] { new HashMap<String, Object[]>() { + return getUserInfoInternal(monitor, new Object[] { new HashMap<String, Object>() { { put(XML_PARAMETER_IDS, ids); + if (token != null) { + put(XML_PARAMETER_TOKEN, token); + } } } }); } @SuppressWarnings("serial") public Object[] getUserInfoFromNames(final IProgressMonitor monitor, final String[] names) throws XmlRpcException { - return getUserInfoInternal(monitor, new Object[] { new HashMap<String, Object[]>() { + return getUserInfoInternal(monitor, new Object[] { new HashMap<String, Object>() { { put(XML_PARAMETER_NAMES, names); + if (token != null) { + put(XML_PARAMETER_TOKEN, token); + } } } }); } @@ -286,18 +322,26 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { @SuppressWarnings("serial") public Object[] getFieldsWithNames(final IProgressMonitor monitor, final String[] names) throws XmlRpcException { - return getFieldsInternal(monitor, new Object[] { new HashMap<String, Object[]>() { + return getFieldsInternal(monitor, new Object[] { new HashMap<String, Object>() { { put(XML_PARAMETER_NAMES, names); + if (token != null) { + put(XML_PARAMETER_TOKEN, token); + } + } } }); } @SuppressWarnings("serial") public Object[] getFieldsWithIDs(final IProgressMonitor monitor, final Integer[] ids) throws XmlRpcException { - return getFieldsInternal(monitor, new Object[] { new HashMap<String, Object[]>() { + return getFieldsInternal(monitor, new Object[] { new HashMap<String, Object>() { { put(XML_PARAMETER_IDS, ids); + if (token != null) { + put(XML_PARAMETER_TOKEN, token); + } + } } }); } @@ -307,7 +351,9 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { @Override public Object[] execute() throws XmlRpcException { Object[] result = null; - HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET_SELECTABLE, (Object[]) null); + HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET_SELECTABLE, (token == null) + ? null + : new Object[] { Collections.singletonMap(XML_PARAMETER_TOKEN, token) }); result = response2ObjectArray(response, XML_RESPONSE_IDS); return result; } @@ -319,7 +365,9 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { @Override public Object[] execute() throws XmlRpcException { Object[] result = null; - HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET_ENTERABLE, (Object[]) null); + HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET_ENTERABLE, (token == null) + ? null + : new Object[] { Collections.singletonMap(XML_PARAMETER_TOKEN, token) }); result = response2ObjectArray(response, XML_RESPONSE_IDS); return result; } @@ -331,7 +379,9 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { @Override public Object[] execute() throws XmlRpcException { Object[] result = null; - HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET_ACCESSIBLE, (Object[]) null); + HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET_ACCESSIBLE, (token == null) + ? null + : new Object[] { Collections.singletonMap(XML_PARAMETER_TOKEN, token) }); result = response2ObjectArray(response, XML_RESPONSE_IDS); return result; } @@ -345,9 +395,12 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { public Object[] execute() throws XmlRpcException { Object[] result = null; HashMap<?, ?> response = (HashMap<?, ?>) call(monitor, XML_PRODUCT_GET, - new Object[] { new HashMap<String, Object[]>() { + new Object[] { new HashMap<String, Object>() { { put(XML_PARAMETER_IDS, ids); + if (token != null) { + put(XML_PARAMETER_TOKEN, token); + } } } }); result = response2ObjectArray(response, XML_RESPONSE_PRODUCTS); @@ -610,7 +663,7 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { || xmlrpcName.equals("assigned_to") || xmlrpcName.equals("classification") //$NON-NLS-1$ //$NON-NLS-2$ || xmlrpcName.equals("cc") || xmlrpcName.equals("remaining_time") //$NON-NLS-1$ //$NON-NLS-2$ || xmlrpcName.equals("estimated_time") || xmlrpcName.equals("deadline") //$NON-NLS-1$ //$NON-NLS-2$ - || xmlrpcName.equals("alias")) { //$NON-NLS-1$ + || xmlrpcName.equals("alias")) { //$NON-NLS-1$ return xmlrpcName; } else if (xmlrpcName.equals("last_change_time")) { //$NON-NLS-1$ return "delta_ts"; //$NON-NLS-1$ @@ -730,7 +783,7 @@ public class BugzillaXmlRpcClient extends CommonXmlRpcClient { taskIds.removeAll(idsToRetrieve); taskDataMap.clear(); } catch (XmlRpcException e) { - throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, "XmlRpcException: ", e)); //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, "XmlRpcException: ", e)); //$NON-NLS-1$ } } } |