001: package com.sun.portal.rproxy.configservlet;
002:
003: import java.io.Serializable;
004:
005: import com.iplanet.sso.SSOToken;
006: import com.iplanet.sso.SSOTokenManager;
007: import com.sun.portal.util.GWLogManager;
008: import com.sun.portal.util.SSOUtil;
009:
010: public class Request implements Serializable {
011:
012: private String serviceName;
013:
014: private String ssoTokenId;
015:
016: private String requestType;
017:
018: private Object requestObject;
019:
020: private Object[] arguments;
021:
022: private String gatewaySessionID = null;
023:
024: public Request(String sessionId, String serviceName,
025: String requestType, Object requestObject, Object[] arguments) {
026: this .ssoTokenId = sessionId;
027: this .serviceName = serviceName;
028: this .requestType = requestType;
029: this .requestObject = requestObject;
030: this .arguments = arguments;
031: }
032:
033: public Request(String sessionId, String serviceName,
034: String requestType, Object requestObject) {
035: this (sessionId, serviceName, requestType, requestObject, null);
036:
037: }
038:
039: public Request(String sessionId, String serviceName,
040: String requestType) {
041: this (sessionId, serviceName, requestType, null);
042: }
043:
044: public String getServiceName() {
045: return serviceName;
046: }
047:
048: public String getSSOTokenId() {
049: return ssoTokenId;
050: }
051:
052: public String getRequestType() {
053: return requestType;
054: }
055:
056: public Object getRequestObject() {
057: return requestObject;
058: }
059:
060: public Object[] getArguments() {
061: return arguments;
062: }
063:
064: public String getGatewaySessionID() {
065: return gatewaySessionID;
066: }
067:
068: private static int retryCount = 0;
069:
070: // 1 minutes
071: private static int MIN_RETRY_TIME = 60000;
072:
073: private static long prevRetryTime = 0;
074:
075: private static synchronized void retryAddGatewaySessionId(
076: Request req) {
077: // System.out.println("Retry count : " + retryCount);
078: if (retryCount > 5
079: || System.currentTimeMillis() - prevRetryTime < MIN_RETRY_TIME) {
080: boolean needTimeReset = (retryCount > 5);
081:
082: retryCount = 0;
083:
084: if (needTimeReset) {
085: prevRetryTime = System.currentTimeMillis();
086: }
087: req.gatewaySessionID = null;
088: return;
089: }
090: GWLogManager.createNewAppSession();
091:
092: SSOToken appToken = getToken(GWLogManager.appSession);
093:
094: if (appToken != null) {
095: String sessId = GWLogManager.appSession.getTokenID()
096: .toString();
097: req.gatewaySessionID = sessId;
098: prevRetryTime = System.currentTimeMillis();
099: } else {
100: retryCount++;
101: retryAddGatewaySessionId(req);
102: }
103: }
104:
105: public static SSOToken getToken(SSOToken tok) {
106: if (tok == null) {
107: return null;
108: }
109: String sessId = tok.getTokenID().toString();
110: SSOToken appToken = null;
111: try {
112: SSOTokenManager tokManager = SSOTokenManager.getInstance();
113: appToken = SSOUtil.getSSOTokenNoDecode(sessId);
114: tok = null;
115: if (tokManager.isValidToken(appToken)) {
116: tok = appToken;
117: }
118: } catch (Exception ex) {
119: // ex.printStackTrace();
120: tok = null;
121: }
122: return tok;
123: }
124:
125: public void setGatewaySessionID() {
126:
127: // Should we try recreation everytime ?
128: // There is a potential performance penality with this approach.
129: SSOToken appToken = getToken(GWLogManager.appSession);
130: // SSOToken appToken = GWLogManager.appSession;
131: if (appToken != null) {
132: String sessId = GWLogManager.appSession.getTokenID()
133: .toString();
134: this.gatewaySessionID = sessId;
135: } else {
136: retryAddGatewaySessionId(this);
137: }
138: }
139: }
|