1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.msn.tweener;
20
21 import java.io.IOException;
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24
25 import org.apache.commons.httpclient.Header;
26 import org.apache.commons.httpclient.HttpClient;
27 import org.apache.commons.httpclient.HttpException;
28 import org.apache.commons.httpclient.methods.GetMethod;
29
30 /***
31 * @author christoph
32 *
33 */
34 public class PassportNexus {
35
36 private static final String NEXUS_URL = "https://nexus.passport.com/rdr/pprdr.asp";
37 private static final Pattern passportUrlsPattern = Pattern
38 .compile("DALogin=([a-z0-9_//./]*)");
39
40 private String nexusUrl;
41
42 public PassportNexus() {
43 this(NEXUS_URL);
44 }
45
46 public PassportNexus(String nexusUrl) {
47 this.nexusUrl = nexusUrl;
48 }
49
50 public String getNexusUrl() {
51 return nexusUrl;
52 }
53
54 public LoginServer connect() {
55 HttpClient httpclient = new HttpClient();
56 GetMethod httpget = new GetMethod(nexusUrl);
57
58 try {
59 httpclient.executeMethod(httpget);
60 }
61 catch (HttpException e) {
62
63 e.printStackTrace();
64 }
65 catch (IOException e) {
66
67 e.printStackTrace();
68 }
69
70 System.out.println(httpget.getStatusLine().toString());
71
72 Header headers[] = httpget.getResponseHeaders();
73
74 for (int i = 0; i < headers.length; i++) {
75 System.out.println(headers[i].toString());
76 }
77
78 Header passportUrls = httpget.getResponseHeader("PassportURLs");
79
80 String daLogin = getDaLogin(passportUrls.getValue());
81
82 return new LoginServer("https://" + daLogin);
83 }
84
85 private String getDaLogin(String passportUrls) {
86 Matcher matcher = passportUrlsPattern.matcher(passportUrls);
87
88 while (matcher.find()) {
89 if (matcher.group(1) != null) {
90 return matcher.group(1);
91 }
92 }
93
94 return null;
95 }
96 }