summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.iplog
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-03-11 11:19:50 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-03-11 15:15:03 -0800
commit41bc1738a4bbec12406a611b5d9f6ff7669c9431 (patch)
treeb3ce4f92e24e8da12b6fed7e5852e392fe884340 /org.eclipse.jgit.iplog
parent6c64148f666dad0046086b65eb4912dafafe7a20 (diff)
downloadjgit-41bc1738a4bbec12406a611b5d9f6ff7669c9431.tar.gz
jgit-41bc1738a4bbec12406a611b5d9f6ff7669c9431.zip
eclipse-ipzilla: Make sure login was successful
If the login fails due to an invalid username or password, the only way we can tell this is by looking at the page title and seeing if the error message "Invalid Username or Password" is present. If the user made a typo on their password, we shouldn't plow through and try to run a query. Doing so returns an HTML login page that can't be parsed as a CSV file. Change-Id: Ia6d7f862435a52ae09ebe29c3835bcee3cf73b93 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.iplog')
-rw-r--r--org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IPZillaQuery.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IPZillaQuery.java b/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IPZillaQuery.java
index 74bc10c50a..7d9f9a64c8 100644
--- a/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IPZillaQuery.java
+++ b/org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IPZillaQuery.java
@@ -48,6 +48,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.CookieHandler;
@@ -67,6 +68,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.jgit.util.HttpSupport;
@@ -186,6 +189,41 @@ class IPZillaQuery {
+ " failed: " + c.getResponseCode() + " "
+ c.getResponseMessage());
}
+
+ String content = readFully(c);
+ Matcher matcher = Pattern.compile("<title>(.*)</title>",
+ Pattern.CASE_INSENSITIVE).matcher(content);
+ if (!matcher.find()) {
+ throw new IOException("Login as " + username + " to " + login
+ + " failed: Response not HTML as expected");
+ }
+
+ String title = matcher.group(1);
+ if (!"IPZilla Main Page".equals(title)) {
+ throw new IOException("Login as " + username + " to " + login
+ + " failed; page title was \"" + title + "\"");
+ }
+ }
+
+ private String readFully(HttpURLConnection c) throws IOException {
+ String enc = c.getContentEncoding();
+ Reader reader;
+ if (enc != null) {
+ reader = new InputStreamReader(c.getInputStream(), enc);
+ } else {
+ reader = new InputStreamReader(c.getInputStream(), "ISO-8859-1");
+ }
+ try {
+ StringBuilder b = new StringBuilder();
+ BufferedReader r = new BufferedReader(reader);
+ String line;
+ while ((line = r.readLine()) != null) {
+ b.append(line).append('\n');
+ }
+ return b.toString();
+ } finally {
+ reader.close();
+ }
}
private void logout() throws MalformedURLException, ConnectException,