001: /**
002: * Copyright 2003 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 Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.consumer.markup.impl;
013:
014: import java.util.logging.Logger;
015:
016: import com.sun.portal.container.ContainerRequest;
017: import com.sun.portal.container.ContainerException;
018: import com.sun.portal.container.ContentException;
019: import com.sun.portal.wsrp.common.stubs.SessionContext;
020: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Markup_PortType;
021: import com.sun.portal.wsrp.consumer.markup.MarkupConfig;
022: import com.sun.portal.wsrp.consumer.markup.ProducerSessionManager;
023: import com.sun.portal.wsrp.consumer.common.WSRPConsumerConfig;
024:
025: /**
026: * This is the implementation of ProducerSessionManager designed that
027: * has methods to manage the session and cookies with a WSRP Producer.
028: * This implementation basically delegates all its functionality to
029: * AnonProducerSessionManager if the user is anonymous/authless or
030: * to AuthProducerSessionManagerImpl if the user is a a regular user.
031: * Basic difference and the reason for two such implementations is
032: * that in our portal, Anonymous is not allowed to have session, so
033: * anonymous desktop shouldn't be configured with a portlet from
034: * producer that requires initCookie. Having such portlet means
035: * the markup stub needs to be saved for the session and for
036: * anonymous user, there is no place to store it.
037: * Hence all session information is stored in client properties
038: * for anonymous user and as providerContext.setSessionProperty
039: * for regular users.
040: *
041: */
042: public class ProducerSessionManagerImpl implements
043: ProducerSessionManager {
044:
045: private ProducerSessionManager _anonProducerSessionManager = null;
046: private ProducerSessionManager _authProducerSessionManager = null;
047:
048: public ProducerSessionManagerImpl() {
049:
050: _authProducerSessionManager = new ProducerSessionManagerInitCookie();
051:
052: if (WSRPConsumerConfig.getInstance()
053: .doesAnonSupportInitCookie()) {
054:
055: // use the same implementation as used for regular user
056:
057: _anonProducerSessionManager = _authProducerSessionManager;
058: } else {
059: _anonProducerSessionManager = new ProducerSessionManagerNoInitCookie();
060: }
061:
062: }
063:
064: /**
065: * This method processes the SessionContext sent by the producer
066: * as part of the response.
067: * Information in SessionContext must be stored so that it can be returned
068: * on following requests to maintain the session.
069: *
070: * @param markupConfig markup configuration object.
071: * @param request container request.
072: * @param sessionContext session context sent back as a response from the producer.
073: * @exception com.sun.portal.container.ContainerException
074: * @exception com.sun.portal.container.ContentException
075: */
076:
077: public void processSessionContext(MarkupConfig markupConfig,
078: ContainerRequest request, SessionContext sessionContext)
079: throws ContainerException, ContentException {
080:
081: if (MarkupUtil.isAuthless(request)) {
082: _anonProducerSessionManager.processSessionContext(
083: markupConfig, request, sessionContext);
084: } else {
085: _authProducerSessionManager.processSessionContext(
086: markupConfig, request, sessionContext);
087: }
088:
089: }
090:
091: /**
092: * Get the session id to be returned back to producer
093: * for this request
094: *
095: * @param markupConfig
096: * @param request
097: * @exception com.sun.portal.container.ContainerException
098: * @exception com.sun.portal.container.ContentException
099: */
100: public String getProducerSessionId(MarkupConfig markupConfig,
101: ContainerRequest request) throws ContainerException,
102: ContentException {
103:
104: if (MarkupUtil.isAuthless(request)) {
105: return _anonProducerSessionManager.getProducerSessionId(
106: markupConfig, request);
107: } else {
108: return _authProducerSessionManager.getProducerSessionId(
109: markupConfig, request);
110: }
111: }
112:
113: /**
114: * Invalidate or remove the session explicitly.
115: *
116: * @param markupConfig
117: * @param request
118: * @exception com.sun.portal.container.ContainerException
119: * @exception com.sun.portal.container.ContentException
120: */
121: public void resetSessionId(String invalidSessionId,
122: MarkupConfig markupConfig, ContainerRequest request)
123: throws ContainerException, ContentException {
124:
125: if (MarkupUtil.isAuthless(request)) {
126: _anonProducerSessionManager.resetSessionId(
127: invalidSessionId, markupConfig, request);
128: } else {
129: _authProducerSessionManager.resetSessionId(
130: invalidSessionId, markupConfig, request);
131: }
132:
133: }
134:
135: /**
136: * Returns a markup porttype stub that can be used
137: * for calling remote markup methods. If initCookie
138: * requirement is on for this producer, this stub
139: * is ornamented with all the right cookies.
140: *
141: * @param markupConfig
142: * @param request
143: * @exception com.sun.portal.container.ContainerException
144: * @exception com.sun.portal.container.ContentException
145: */
146:
147: public WSRP_v1_Markup_PortType getMarkupPortType(
148: MarkupConfig markupConfig, ContainerRequest request)
149: throws ContainerException, ContentException {
150:
151: if (MarkupUtil.isAuthless(request)) {
152: return _anonProducerSessionManager.getMarkupPortType(
153: markupConfig, request);
154: } else {
155: return _authProducerSessionManager.getMarkupPortType(
156: markupConfig, request);
157: }
158:
159: }
160:
161: public void resetMarkupPortType(
162: WSRP_v1_Markup_PortType invalidPortType,
163: MarkupConfig markupConfig, ContainerRequest request)
164: throws ContainerException, ContentException {
165: if (MarkupUtil.isAuthless(request)) {
166: _anonProducerSessionManager.resetMarkupPortType(
167: invalidPortType, markupConfig, request);
168: } else {
169: _authProducerSessionManager.resetMarkupPortType(
170: invalidPortType, markupConfig, request);
171: }
172:
173: }
174:
175: /**
176: * We need to share this string with the proxy servlet
177: * that also might want to read or update the cookies
178: * when processing a url of type resource.
179: *
180: * @param markupConfig
181: * @param request
182: * @exception com.sun.portal.container.ContainerException
183: * @exception com.sun.portal.container.ContentException
184: */
185: public String getCookieHandleKey(MarkupConfig markupConfig,
186: ContainerRequest request) throws ContainerException {
187:
188: if (MarkupUtil.isAuthless(request)) {
189: return _anonProducerSessionManager.getCookieHandleKey(
190: markupConfig, request);
191: } else {
192: return _authProducerSessionManager.getCookieHandleKey(
193: markupConfig, request);
194: }
195:
196: }
197:
198: }
|