//SSL is slow, open new thread to do this
new Thread() {
private String getPassportUrlSlow() throws IOException {
// log.debug("MSNDEBUG: Lets ask the nexus what passport url to use");
HttpsURLConnection conn = null;
try {
conn = (HttpsURLConnection) new URL(
"https://nexus.passport.com/rdr/pprdr.asp")
.openConnection();
conn.setUseCaches(false);
// log.debug("MSNDEBUG: Got password urls: "+conn.getHeaderField("PassportURLs"));
Matcher matcher = passportUrlPattern.matcher(conn
.getHeaderField("PassportURLs"));
if (matcher.matches()) {
// log.debug("MSNDEBUG: We're going to use url: "+matcher.group(1));
return "https://" + matcher.group(1);
}
// log.debug("MSNDEBUG: Crap, no url found?!");
return null;
} finally {
if (conn != null)
conn.disconnect();
}
}
private String getPassportUrl() throws IOException {
// log.debug("MSNDEBUG: Retrieving passport url");
if (JmlConstants.FAST_SSL_LOGIN)
return "https://login.live.com/login2.srf";
return getPassportUrlSlow();
}
private String getLoginTicket(String visitUrl, String passport,
String password, String challengeStr)
throws IOException {
// log.debug("MSNDEBUG: Retrieving the login ticket from url "+visitUrl+" and passport "+passport);
HttpsURLConnection conn = null;
try {
conn = (HttpsURLConnection) new URL(visitUrl)
.openConnection();
conn.setUseCaches(false);
// log.debug("MSNDEBUG: Setting request property");
conn.setRequestProperty("Authorization",
// "Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in="
"Passport1.4 OrgVerb=GET,OrgURL="
+ StringUtils.urlEncode(visitUrl)
+ ",sign-in="
+ StringUtils.urlEncode(passport)
+ ",pwd="
+ StringUtils.urlEncode(password) + ","
+ challengeStr);
// log.debug("MSNDEBUG: Request property is "+conn.getRequestProperty("Authorization"));
switch (conn.getResponseCode()) {
case 200: //success
// log.debug("MSNDEBUG: Response code is 200, success!");
Matcher matcher = ticketPattern.matcher(conn
.getHeaderField("Authentication-Info"));
if (matcher.matches()) {
return matcher.group(1);
}
return null;
case 302: //redirect
// log.debug("MSNDEBUG: Response code is 302, being redirected!");
visitUrl = conn.getHeaderField("Location");
// log.debug("MSNDEBUG: Redirect to "+visitUrl);
return getLoginTicket(visitUrl, passport, password,
challengeStr);
case 401: //failed
// log.debug("MSNDEBUG: Response code is 401, we failed?");
return null;
default:
// log.debug("MSNDEBUG: Response code (unknown) was "+conn.getResponseCode());
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
return null;
}