001: /*
002: * $Id: HTTPProxy.java,v 1.30 2006/01/10 05:11:23 ss150821 Exp $
003: * $Source: /m/portal/ps/srap/src/com/sun/portal/rproxy/rewriterproxy/HTTPProxy.java,v $
004: * $Log: HTTPProxy.java,v $
005: * Revision 1.30 2006/01/10 05:11:23 ss150821
006: * 6370423 - Rewriter Proxy should accecpt connections only from valid gateway clients
007: *
008: * Revision 1.29 2006/01/09 10:27:23 ss150821
009: * 6194618 - implement policy authorization on the rewriter proxy and/or URL Access/Deny specification
010: *
011: * Revision 1.28 2005/12/28 11:47:48 ss150821
012: * 4865902 - Rewriter Proxy in http mode
013: *
014: * Revision 1.27 2005/12/28 08:51:28 ss150821
015: * 4865902 - Rewriter Proxy in http mode
016: *
017: * Revision 1.26 2005/12/06 12:16:11 ss150821
018: * 6349604 - SUNWportal<rwproxyinstancename> directory in /var/opt should be removed
019: *
020: * Revision 1.25 2005/10/19 09:24:42 ss150821
021: * 6326825
022: *
023: * Revision 1.24 2005/10/19 05:31:59 dg154973
024: * CR 6280402 - log system results in excessive lock contention
025: *
026: * Revision 1.23 2005/09/21 11:07:29 dg154973
027: * CR 6280402 - log system results in excessive lock contention
028: *
029: * Revision 1.22 2005/07/07 10:06:23 np145014
030: * CR 6223492
031: *
032: * Revision 1.21 2005/06/28 06:51:12 ss150821
033: * CR - 6272934 Error in the order in which the properties were being set for logging.
034: *
035: * Revision 1.20 2005/06/14 11:06:25 ak118254
036: * 6281362 6281288 6281393 SUNWps to SUNWportal change.
037: *
038: * Revision 1.19 2005/05/19 09:44:00 ss150821
039: * CR - 6272934 NetletProxy and the Rewriter Proxy Servers do not log any messages to the log files
040: *
041: * Revision 1.18 2005/04/27 12:38:17 ss150821
042: * RFE 6223490 - SRA Should use JDK based logging
043: *
044: * Revision 1.17 2005/04/04 10:06:18 ss150821
045: * RFE 6223490 - SRA Should use JDK based logging
046: *
047: * Revision 1.16 2005/03/22 12:29:22 ss150821
048: * RFE 6223490 - SRA Should use JDK based logging - Making changes as PS Logging Codebase has changed
049: *
050: * Revision 1.15 2005/03/07 09:19:34 np145014
051: * CR 6223492
052: *
053: * Revision 1.14 2005/02/25 09:38:30 ss150821
054: * RFE 6223490 - SRA Should use JDK based logging, changed to start throwing the full stacktrace for the exception in the logs
055: *
056: * Revision 1.13 2005/02/23 08:35:04 ss150821
057: * RFE 6223490 - SRA Should use JDK based logging
058: *
059: * Revision 1.12 2004/10/26 09:20:22 ss150821
060: * #6178980 - SRA security component should point to jss4.jar
061: *
062: * Revision 1.11 2004/07/27 12:58:58 vt126379
063: * RFE#5075809, CRT#99
064: *
065: * Revision 1.10 2004/05/25 17:19:03 rc135440
066: * CRT22: ps63_linux_branch sync to trunk
067: *
068: * Revision 1.9.36.1 2004/03/26 11:57:38 rc135440
069: * #4935700 - Watchdog info picked up from platform.conf gateway.data.dir property
070: *
071: * Revision 1.9 2003/08/13 06:29:59 bs126381
072: * FIX for 4885766
073: *
074: * Revision 1.8 2003/05/30 12:54:31 mm132998
075: * Session Validation at server side
076: *
077: * Revision 1.7 2003/05/20 13:20:54 rt130506
078: * Rewriter Proxy Changes
079: *
080: * Revision 1.6 2003/05/20 11:58:15 mm132998
081: * Support for watchdog
082: *
083: * Revision 1.5 2003/05/20 09:50:49 mm132998
084: * Supporting watchdog in Rewriter Proxy
085: *
086: * Revision 1.4 2002/10/21 12:58:23 sg134305
087: * CRT (23) - Refactored RProxy code related to starting the server.
088: * Created a gatewaycontext interface which can be initialized with DSAME Context in production while test/default context during unit testing.
089: *
090: * Revision 1.3 2002/08/16 15:13:07 bv131302
091: * Hana CRT#1888 - Check log settings before logging
092: *
093: * Revision 1.2 2002/07/24 15:56:09 rt130506
094: * CRT 1717
095: *
096: * Revision 1.1 2002/06/14 09:54:00 rt130506
097: * SRAP rebranding
098: *
099: * Revision 1.6 2002/06/12 07:56:00 bv131302
100: * more rebranding - filenames
101: *
102: * Revision 1.5 2002/06/11 16:02:13 bv131302
103: * new branded
104: *
105: * Revision 1.4 2002/04/23 10:25:01 mm132998
106: * Bug ID : 4670681 , CRT : # 889 , Desc : HTTPProxy migration for Lihue.
107: *
108: * Revision 1.3 2002/03/04 09:21:43 mm132998
109: * Bug ID : 4646277 CRT: 442 Desc : Lihue PRD 4.5
110: *
111: *
112: */
113: //Copyright 03/22/00 Sun Microsystems, Inc. All Rights Reserved.
114: //#pragma ident "@(#)HTTPProxy.java 1.8 00/03/22 Sun Microsystems"
115: //
116: /*
117: * HTTPProxy.java
118: *
119: * $Author: ss150821 $
120: *
121: * $Revision: 1.30 $
122: *
123: * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
124: *
125: * Developed by SunPS and SunIR
126: */
127:
128: package com.sun.portal.rproxy.rewriterproxy;
129:
130: import java.net.SocketException;
131: import java.util.ArrayList;
132: import java.util.Iterator;
133: import java.util.ResourceBundle;
134: import java.util.StringTokenizer;
135: import java.util.logging.Level;
136: import java.util.logging.Logger;
137:
138: import com.sun.portal.log.common.PortalLogger;
139: import com.sun.portal.netlet.eproxy.RProxyConnection;
140: import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
141: import com.sun.portal.rproxy.configservlet.client.PlatformProfile;
142: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
143: import com.sun.portal.rproxy.server.GatewayContext;
144: import com.sun.portal.rproxy.server.GatewayContextFactory;
145: import com.sun.portal.util.GCThread;
146: import com.sun.portal.util.GWDebug;
147: import com.sun.portal.util.GWLocale;
148: import com.sun.portal.util.GWNSSInit;
149: import com.sun.portal.util.GWThreadPool;
150: import com.sun.portal.util.ServiceIdentifier;
151: import com.sun.portal.util.SystemProperties;
152:
153: public class HTTPProxy {
154: public static ResourceBundle _resources;
155:
156: public static final String DEFAULT_PORT = "10443";
157:
158: public static final String DEFAULT_RWPROXY_PROTOCOL = "https";
159:
160: private static final String HTTP_PROTOCOL = "http";
161:
162: private static Logger logger = null;
163:
164: private static String rwProxyProtocol = DEFAULT_RWPROXY_PROTOCOL;
165:
166: private static ArrayList validGateways = new ArrayList();
167:
168: static {
169: System.setProperty("com.sun.portal.sra.component.type",
170: "rwproxy");
171:
172: rwProxyProtocol = SystemProperties.get(
173: "rewriterproxy.protocol", DEFAULT_RWPROXY_PROTOCOL);
174:
175: String gwListString = SystemProperties
176: .get("rewriterproxy.accept.from.gateways");
177:
178: if (logger == null) {
179: // The following will replace the %sraComponentType key in the log
180: // file with the key
181: // RewriterProxy and generate the log file name . See the
182: // platform.conf file for the entire
183: // key
184:
185: logger = PortalLogger.getLogger(HTTPProxy.class);
186: GWDebug.createDefault("srapRewriterProxy");
187: }
188:
189: if (gwListString != null) {
190: StringTokenizer token = new StringTokenizer(gwListString,
191: ",");
192:
193: while (token.hasMoreElements()) {
194: String gw = token.nextToken();
195: Object[] params = { gw };
196: logger.log(Level.INFO, "PSSRRPROXY_CSPRRPROXY003", gw);
197: validGateways.add(gw);
198: }
199: } else
200: logger.info("PSSRRPROXY_CSPRRPROXY004");
201:
202: try {
203: GWNSSInit.initialize();
204: } catch (SocketException e1) {
205: if (GWDebug.debug.errorEnabled())
206: GWDebug.debug
207: .error("NetletProxy: Unable to initialize GatewayProfile/PlatformProfile -> "
208: + e1);
209: }
210:
211: try {
212: String profileName = System.getProperty(
213: "gateway.profilename", "default");
214: GatewayProfile.init("this-should-be-sid", profileName);
215: PlatformProfile.init("this-should-be-sid");
216: } catch (Exception e) {
217: e.printStackTrace();
218: System.out
219: .println("Unable to initialize GatewayProfile/PlatformProfile");
220: System.exit(1);
221: }
222:
223: ServiceIdentifier.createDefault("srapRewriterProxy");
224:
225: GWLocale.createDefault();
226: // EOC : iDSAME migration
227: GWThreadPool.init();
228:
229: GatewayContextFactory
230: .init(GatewayContextFactory.DSAME_INSTANCE);
231: MonitoringSubsystem.getInstance();
232: }
233:
234: public static void main(String argv[]) {
235: GCThread gc = new GCThread();
236: gc.start();
237:
238: // GatewayContext gatewayContext =
239: // GatewayContextFactory.getGatewayContext();
240:
241: // int httpProxyPort = gatewayContext.getHttpProxyPort();
242: int httpProxyPort = Integer.valueOf(
243: SystemProperties
244: .get("rewriterproxy.port", DEFAULT_PORT))
245: .intValue();
246:
247: try {
248: if (rwProxyProtocol
249: .equalsIgnoreCase(DEFAULT_RWPROXY_PROTOCOL)) {
250: RProxyConnection.startHttps(httpProxyPort);
251: } else {
252: RProxyConnection.startHttp(httpProxyPort);
253: }
254:
255: } catch (Exception ex) {
256: // logger.severe("RewriterProxy: exception " + ex);
257: logger.log(Level.SEVERE, "PSSRRPROXY_CSPRRPROXY000", ex);
258: } catch (Error er) {
259: // logger.severe("RewriterProxy: error " + er);
260: logger.log(Level.SEVERE, "PSSRRPROXY_CSPRRPROXY001", er);
261: }
262: }
263:
264: public static void exit(int status) {
265: System.exit(status);
266: }
267:
268: public static String getRwProxyProtocol() {
269: return rwProxyProtocol;
270: }
271:
272: public static boolean allowConnectionsFromAllClients() {
273: return validGateways.isEmpty();
274: }
275:
276: public static boolean isValidGateway(String ip) {
277: // If the property indicating a list of valid gateway's is not present
278: // or is empty then
279: // we run in the pre 7.0 mode where a rwproxy will accept connections
280: // from anyone
281: if (validGateways.isEmpty())
282: return true;
283:
284: boolean isValid = false;
285: if (validGateways.contains(ip))
286: isValid = true;
287:
288: return isValid;
289: }
290:
291: }
|