001: /**
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */package com.sun.portal.rproxy.configservlet;
005:
006: import java.io.IOException;
007: import java.io.ObjectInputStream;
008: import java.io.ObjectOutputStream;
009: import java.io.OutputStream;
010: import java.rmi.RemoteException;
011:
012: import javax.servlet.ServletException;
013: import javax.servlet.http.HttpServlet;
014: import javax.servlet.http.HttpServletRequest;
015: import javax.servlet.http.HttpServletResponse;
016:
017: import com.iplanet.sso.SSOToken;
018: import com.iplanet.sso.SSOTokenManager;
019: import com.sun.portal.rproxy.configservlet.server.CdmHandler;
020: import com.sun.portal.rproxy.configservlet.server.GatewayServiceHandler;
021: import com.sun.portal.rproxy.configservlet.server.GlobalAttributesServiceHandler;
022: import com.sun.portal.rproxy.configservlet.server.UserAttributesServiceHandler;
023: import com.sun.portal.rproxy.configservlet.server.UserAttributesSetHandler;
024: import com.sun.portal.rproxy.rewriter.services.idsame.IDSAMEDataServiceSkeleton;
025:
026: // import java.net.URLDecoder;
027:
028: /**
029: * @author sanjib.ghosh@sun.com
030: * @version 1.0
031: */
032:
033: public class RemoteConfigServlet extends HttpServlet {
034: public void doPost(HttpServletRequest request,
035: HttpServletResponse response) throws ServletException,
036: IOException {
037: // System.out.println( "Post" + request );
038:
039: Request rq = getRequest(request);
040: if (!validateRequest(rq)) {
041: // throw new ServletException("Invalid Gateway session specified
042: // !!");
043: // return a Response with resp.setNeedRecreateSession(true);
044: Response resp = new Response("", "", "");
045: resp.setNeedRecreateSession(true);
046: sendResponse(response, resp);
047: return;
048: }
049: Response rsp = handleRequest(rq);
050: sendResponse(response, rsp);
051: }
052:
053: public void doGet(HttpServletRequest request,
054: HttpServletResponse response) throws ServletException,
055: IOException {
056: doPost(request, response);
057: }
058:
059: private Request getRequest(HttpServletRequest request)
060: throws ServletException, IOException {
061: try {
062: ObjectInputStream objectStream = new ObjectInputStream(
063: request.getInputStream());
064: Request ret = (Request) objectStream.readObject();
065: // objectStream.close();
066: return ret;
067: } catch (ClassNotFoundException e) {
068: throw new ServletException(e.getMessage());
069: }
070: }
071:
072: private void sendResponse(HttpServletResponse response, Response rsp)
073: throws ServletException, IOException {
074: OutputStream out = response.getOutputStream();
075: ObjectOutputStream objectStream = new ObjectOutputStream(out);
076: objectStream.writeObject(rsp);
077: out.close();
078: }
079:
080: private Response handleRequest(Request request) {
081: ServiceHandler handler = getServiceHandler(request);
082: try {
083: return handler.handleRequest(request);
084: } catch (RuntimeException e) {
085: return new Response(request.getServiceName(), request
086: .getRequestType(), e);
087: } catch (RemoteException e) {
088: return new Response(request.getServiceName(), request
089: .getRequestType(), e);
090: }
091: }
092:
093: // This class also a factory for Service handler
094:
095: private static final String GET_GLOBALS = "GET_GLOBALS";
096:
097: private static final String GET_USERS = "GET_USERS";
098:
099: // Added by Mridul
100: private static final String SET_USER_ATTRIBUTES = "SET_USER_ATTRIBUTES";
101:
102: // EOC : iDSAME migration - Mridul
103: // Added by Mridul
104: private static final String CDM_GET_CLIENT_PROPERTY = "CDM_GET_CLIENT_PROPERTY";
105:
106: // EOC : iDSAME migration - Mridul
107:
108: private ServiceHandler getServiceHandler(Request request) {
109:
110: if (GatewayServiceHandler.SERVICE_NAME.equals(request
111: .getServiceName())) {
112: return new GatewayServiceHandler();
113: }
114:
115: if (GET_GLOBALS.equals(request.getRequestType())) {
116: return new GlobalAttributesServiceHandler();
117: }
118:
119: if (GET_USERS.equals(request.getRequestType())) {
120: return new UserAttributesServiceHandler();
121:
122: }
123:
124: // iDSAME migration - Mridul
125: if (SET_USER_ATTRIBUTES.equals(request.getRequestType())) {
126: return new UserAttributesSetHandler();
127: }
128: // EOC : iDSAME migration - Mridul
129:
130: // MAP integration - Mridul
131: if (CDM_GET_CLIENT_PROPERTY.equals(request.getRequestType())) {
132: return CdmHandler.getInstance();
133: }
134: // EOC : MAP integration - Mridul
135:
136: // Start of Rewriter Integration
137: if (IDSAMEDataServiceSkeleton.SERVICE_NAME.equals(request
138: .getServiceName())) {
139: // System.out.println( "Rewriter Service Called by RemoteConfig
140: // Servlet" );
141: return new IDSAMEDataServiceSkeleton();
142: }
143: // End of Rewriter Integration
144:
145: return null;
146: }// getServiceHandler()
147:
148: private boolean validateRequest(Request req) {
149:
150: try {
151: SSOToken ssoToken = null;
152: SSOTokenManager ssoTokenManager = SSOTokenManager
153: .getInstance();
154: // String strSessionId =
155: // URLDecoder.decode(req.getGatewaySessionID());
156: String strSessionId = req.getGatewaySessionID();
157: ssoToken = ssoTokenManager.createSSOToken(strSessionId);
158: if (ssoTokenManager.isValidToken(ssoToken)) {
159: // Check whether the principal is srapGateway
160: /*
161: * if
162: * (ssoToken.getPrincipal().getName().toLowerCase().indexOf("srapGateway") !=
163: * -1){ return true; }
164: */
165: return true;
166: }
167: } catch (Exception e) {
168: }
169: return false;
170: }
171: }// class RemoteConfigServlet
|