01: package com.sun.ssoadapter.impl;
02:
03: import java.net.MalformedURLException;
04: import java.net.URLEncoder;
05: import java.net.URL;
06: import java.net.HttpURLConnection;
07:
08: import java.io.*;
09: import javax.servlet.http.*;
10:
11: import com.iplanet.sso.SSOToken;
12: import com.iplanet.am.util.SystemProperties;
13:
14: /** This is a simple class that acts as the Session for the domino server.
15: * It works only if you have the SSO enabled on the Domino server.
16: * Which involves installing IS Agents on the Domino
17: * Hence it is tied to a single domino server with agents installed ,
18: * the IS server corresponding to the Agent's configuration and
19: * a valid user on IS and Domino.
20: * @see DominoSSO.html
21: */
22:
23: class RemoteDominoSession {
24:
25: String DOMINO_LTPA_NAME = "LtpaToken";
26: String IS_COOKIE_NAME = SystemProperties.get(
27: "com.iplanet.am.cookie.name", "iPlanetDirectoryPro");
28:
29: private String ltpaTokenValue = null;
30:
31: /** This constructor connects to the remote server with IS cookie.
32: * The domino server should return a LtpaToken cookie
33: */
34: public RemoteDominoSession(String protocol, String host,
35: String port, SSOToken token) throws MalformedURLException,
36: IOException, Exception {
37: String url = protocol + "://" + host + ":" + port
38: + "/names.nsf";
39: url = token.encodeURL(url);
40: HttpURLConnection urlConn = (HttpURLConnection) ((new URL(url))
41: .openConnection());
42: urlConn.setFollowRedirects(true);
43: urlConn.setRequestProperty("Cookie", IS_COOKIE_NAME + "="
44: + URLEncoder.encode(token.getTokenID().toString()));
45: urlConn.connect();
46: int code = urlConn.getResponseCode();
47: String msg = urlConn.getResponseMessage();
48: String value = urlConn.getHeaderField("Set-cookie");
49: if (value != null && value.length() > 0) {
50: int index = value.indexOf(DOMINO_LTPA_NAME);
51: if (index < 0) {
52: throw new Exception(
53: "This domino server "
54: + host
55: + " ,Does not work in SSO Mode for this user as the Dominserver did not return LtpaToken");
56: } else {
57: // get the string between the = and the ;
58: index = value.indexOf('=', index);
59: if (index > 0) {
60: int index2 = value.indexOf(';', index);
61: if (index2 > 0)
62: ltpaTokenValue = value.substring(index + 1,
63: index2);
64: }
65: }
66: }
67: }
68:
69: public String getLTPAToken() {
70: return ltpaTokenValue;
71: }
72: }
|