001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and iPlanet
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.providers.calendar;
013:
014: import com.iplanet.sso.*;
015: import com.sun.ssoadapter.SSOAdapter;
016: import com.sun.ssoadapter.SSOAdapterException;
017: import com.sun.comclient.calendar.*;
018: import java.util.Properties;
019: import java.net.HttpURLConnection;
020: import java.net.URL;
021: import java.net.URLEncoder;
022: import java.io.*;
023: import java.util.*;
024: import java.util.logging.Logger;
025: import java.util.logging.Level;
026: import javax.servlet.http.*;
027: import com.sun.portal.providers.context.ProviderContext;
028: import com.sun.portal.providers.context.ProviderContextException;
029: import com.sun.portal.providers.ProviderException;
030: import com.sun.portal.providers.Provider;
031: import com.sun.portal.providers.ProfileProviderAdapter;
032: import com.sun.portal.providers.ApplicationHelper;
033: import com.sun.portal.providers.ProviderEditUtility;
034: import com.sun.portal.log.common.PortalLogger;
035:
036: /**
037: * This class implements CalendarSSOAdapter and CalendarApplicationAdapter functionality
038: * specific to the Sun One Portal and Calendar services.
039: * <p>Specific features include:
040: * <ul>
041: * <li>Support for username/password style authentication.</li>
042: * <li>Ability to generate web application URLs for the following:
043: * <ul>
044: * <li>Calendar Express</li>
045: * <li>MAP JSP Calendar application. The URL generated in this
046: * case will specify a configuration index via the
047: * query string parameter: "ci". </li>
048: * </ul>
049: * </li>
050: * </ul>
051: * <p>At the present time, username/password is stored in the clear.
052: * <p>This CalendarSSOAdapter implementation consumes the following
053: * Configuration properties:
054: * <ul>
055: * <li><b>protocol</b>: Required value. Specifies the protocol
056: * JCAPI will use to connect to the calendar server.
057: * For the time being, this should always be "http".
058: * <li><b>uid</b>: Required value. Username (uid) of calendar user.
059: * <li><b>password</b>: Required value. Password of calendar user.
060: * <li><b>host</b>: Required value. Name of host providing IMAP service.
061: * <li><b>winDomain</b>: Required value. NT domain to which user belongs.
062: * <li><b>port</b>: Optional value. Port number of calendar server.
063: * <li><b>clientProtocol</b>: Protocol to specify within URLs that activate
064: * web application functionality. Defaults to "http".
065: * <li><b>clientPort</b>: Port to specify within URLs that that activate web
066: * application functionality. Defaults to "80".
067: * <li><b>jspContextPath</b>: The "request context path" to use when forming a URL
068: * that activates MAP JSP application functionality.
069: * Defaults to request.getContextPath().
070: * <li><b>jspLaunch</b>: The document path to use when forming a URL
071: * that activates MAP JSP application functionality.
072: * Defaults to "/jsp/default/launchCal.jsp".
073: * <li><b>exchangeContextPath</b>: The "request context path" to use when forming a URL
074: * that activates Exchange OWA functionality.
075: * Defaults to "/exchange".
076: * <li><b>exchangeOperation</b>: The operation to be invoked within Exchange OWA.
077: * Defaults to null, but should be set to "calendar"
078: * for Exchange 2000 installations.
079: * </ul>
080: *
081: * @version 1.0
082: * @see com.sun.sso.SSOAdapter
083: * @see com.sun.sso.SSOAdapter
084: * @see com.sun.portal.sso.CalendarSSOAdapter
085: *
086: */
087:
088: public class ExchangeCalendarHelper extends ApplicationHelper implements
089: CalendarApplicationHelper {
090:
091: public CalendarProvider provider = null;
092: public SSOAdapter ssoAdapter = null;
093: public Properties adapterProperties = null;
094: protected String appName = "";
095: protected String containerName = "";
096:
097: // Create a logger for this class
098: private static Logger debugLogger = PortalLogger
099: .getLogger(ExchangeCalendarHelper.class);
100:
101: /**
102: * Initialize Helper
103: *
104: * @param provider CalendarProvider
105: * @param ssoAdapter SSOAdapter
106: */
107: public void init(CalendarProvider provider, SSOAdapter ssoAdapter)
108: throws Exception {
109: super .init((ProfileProviderAdapter) provider, ssoAdapter);
110: this .provider = provider;
111: this .ssoAdapter = ssoAdapter;
112:
113: if (ssoAdapter != null) {
114: this .adapterProperties = ssoAdapter.getProperties();
115: }
116:
117: }
118:
119: /**
120: * Returns a client URL, if supported by the service.
121: *
122: * @param provider CalendarProvider
123: * @param ssoAdapter SSOAdapter
124: */
125: public String getStartURL(CalendarProvider provider,
126: HttpServletRequest request) {
127: String url = null;
128:
129: try {
130: url = getApplicationURL(provider, request);
131: ProviderContext pc = provider.getProviderContext();
132: url = pc.escape(url);
133: } catch (Exception e) {
134: debugLogger.log(Level.FINE, "PSCC_CSPPC0002", e);
135: }
136:
137: return url;
138: }
139:
140: /**
141: * Returns client aware URL for calendar application access
142: * to service associated with a particular instance
143: * of a ExchangeCalendarHelper.
144: *
145: * @param provider CalendarProvider
146: * @param request HttpServletRequest
147: */
148: public String getApplicationURL(CalendarProvider provider,
149: HttpServletRequest request) throws Exception {
150: String host = adapterProperties.getProperty("host");
151: String clientPort = adapterProperties.getProperty("clientPort",
152: adapterProperties.getProperty("port", "80"));
153: String clientProtocol = adapterProperties.getProperty(
154: "clientProtocol", "http");
155: String exchangeContextPath = adapterProperties.getProperty(
156: "exchangeContextPath", "/exchange");
157:
158: String clientURL = clientProtocol + "://" + host + ":"
159: + clientPort + exchangeContextPath;
160:
161: // check for valid session, if not valid then return base url
162: SSOToken tok = ssoAdapter.getSSOToken();
163:
164: if (tok != null) {
165: String exchangeOperation = adapterProperties
166: .getProperty("exchangeOperation");
167:
168: if (exchangeOperation != null) {
169: clientURL += "/" + adapterProperties.getProperty("uid")
170: + "/" + exchangeOperation;
171: }
172: }
173:
174: return clientURL;
175: }
176:
177: /**
178: * Returns client aware URL for event access
179: * to service associated with a particular instance
180: * of a PortalCalendarSSOHelper.
181: *
182: * @param provider CalendarProvider
183: * @param request HttpServletRequest
184: * @param event Calendar Event
185: */
186: public String getEventURL(CalendarProvider provider,
187: HttpServletRequest request, VEvent event) throws Exception {
188: return null;
189: }
190:
191: /**
192: * Returns client aware URL for task access
193: * to service associated with a particular instance
194: * of a PortalCalendarSSOHelper.
195: *
196: * @param provider CalendarProvider
197: * @param request HttpServletRequest
198: * @param task Calendar Task
199: */
200: public String getTaskURL(CalendarProvider provider,
201: HttpServletRequest request, VTodo task) throws Exception {
202: return null;
203: }
204:
205: /**
206: * Returns the contents of the CalendarProviders edit page
207: *
208: *@param cprov Description of the Parameter
209: *@param req Description of the Parameter
210: *@param res Description of the Parameter
211: *@return The appPrefsEdit value
212: */
213: public StringBuffer getAppPrefsEdit(CalendarProvider cprov,
214: HttpServletRequest req, HttpServletResponse res) {
215: setEditContainer(cprov.editContainer);
216: setContainerName(cprov.containerName);
217: setTargetProvider(cprov.targetProvider);
218: return super .getAppPrefsEdit((Provider) cprov, req, res);
219: }
220:
221: /**
222: * Processes values returned from the CalendarProvider edit page
223: *
224: *@param cprov Instance of Calendar Provider
225: *@param req servlet request
226: *@param res servlet response
227: */
228: public URL processAppPrefsEdit(CalendarProvider cprov,
229: HttpServletRequest request, HttpServletResponse response)
230: throws ProviderException {
231: setEditContainer(cprov.editContainer);
232: setContainerName(cprov.containerName);
233: setTargetProvider(cprov.targetProvider);
234: return super .processAppPrefsEdit((Provider) cprov, request,
235: response);
236: }
237:
238: /**
239: * Returns a HTML link containing encoding specific for the app helper
240: */
241:
242: public String getAppHelperEditLink(HttpServletRequest req,
243: ProviderContext pc) {
244:
245: Hashtable tagTable = new Hashtable();
246: StringBuffer link = new StringBuffer();
247: try {
248: link.append(pc.getDesktopURL(req));
249: } catch (Exception e) {
250: return "";
251: }
252: link.append("?action=edit&provider=");
253: link.append(ProviderEditUtility.getRequestParameter("provider",
254: req));
255: link.append("&targetprovider=" + provider.getName());
256: link.append("&containerName=");
257: link.append(ProviderEditUtility.getRequestParameter(
258: "containerName", req));
259: link.append("&appPref=" + this .getName());
260:
261: tagTable.put("editLink", link.toString());
262: String content = null;
263:
264: try {
265: String fontTag = pc.getStringProperty(provider.getName(),
266: "fontFace1", "Sans-serif");
267: tagTable.put("iwtDesktop-fontFace1", fontTag);
268: content = pc.getTemplate(provider.getName(),
269: "edit-link.template", tagTable).toString();
270: debugLogger.log(Level.FINER, "PSCC_CSPPC0004", content
271: .toString());
272: } catch (Exception e) {
273: debugLogger.log(Level.INFO, "PSCC_CSPPC0005", e);
274: content = "";
275: }
276:
277: debugLogger.log(Level.FINER, "PSCC_CSPPC0006", content
278: .toString());
279:
280: return content;
281: }
282:
283: }
|