View Javadoc

1   // ////////////////////////////////////////////////////////////////////////////
2   // dexterIM - Instant Messaging Framework
3   // Copyright (C) 2003 Christoph Walcher
4   //
5   // This program is free software; you can redistribute it and/or modify
6   // it under the terms of the GNU General Public License as published by
7   // the Free Software Foundation; either version 2 of the License, or
8   // (at your option) any later version.
9   //
10  // This program is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  // GNU General Public License for more details.
14  //
15  // You should have received a copy of the GNU General Public License
16  // along with this program; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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  			// TODO Auto-generated catch block
63  			e.printStackTrace();
64  		}
65  		catch (IOException e) {
66  			// TODO Auto-generated catch block
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  }