001: /*
002: * PACFileIntranetInfo.java
003: *
004: * Created on May 16, 2003, 1:57 PM
005: */
006:
007: package com.sun.portal.util;
008:
009: import java.util.StringTokenizer;
010: import java.util.logging.Level;
011: import java.util.logging.Logger;
012:
013: import com.sun.portal.log.common.PortalLogger;
014: import com.sun.portal.rproxy.server.GatewayContext;
015: import com.sun.portal.rproxy.server.GatewayContextFactory;
016:
017: /**
018: *
019: * @author mm132998
020: * @version
021: */
022: public class PACFileIntranetInfo implements IntranetInfo {
023:
024: private static final char PIPE = '|';
025:
026: private static final char SPACE = ' ';
027:
028: private static final char DOT = '.';
029:
030: private static final String STAR_DOT_STRING = "*.";
031:
032: private static final String STAR_STRING = "*";
033:
034: // static Logger logger = Logger.getLogger("com.sun.portal.sra.rproxy");
035: private static Logger logger = PortalLogger
036: .getLogger(PACFileIntranetInfo.class);
037:
038: private String defaultDomain;
039:
040: private String defaultSubDomainAndDomain;
041:
042: private void initDefaultDomainSubDomain() {
043:
044: GatewayContext gatewayContext = GatewayContextFactory
045: .getGatewayContext();
046:
047: String defaultDomainSubDomain = gatewayContext
048: .getDefaultDomainAndSubDomain(); // GatewayProfile.getString(DEFAULT_DOMAIN_AND_SUBDOMAINS,"").toLowerCase();
049:
050: String[] splitEntry = StringHelper.split(
051: defaultDomainSubDomain, PIPE);
052:
053: if (splitEntry.length == 0) {
054: defaultDomain = "";
055: defaultSubDomainAndDomain = "";
056: // logger.severe("The default sub-domain / domain not specified in
057: // gateway profile!");
058: logger.severe("PSSR_CSPU085");
059: } else if (splitEntry.length == 1) {
060: defaultDomain = DOT + splitEntry[0];
061: defaultSubDomainAndDomain = defaultDomain;
062: } else {
063: defaultDomain = DOT + splitEntry[0];
064: defaultSubDomainAndDomain = DOT + splitEntry[1]
065: + defaultDomain;
066: }
067: }
068:
069: private String pacFileLocation = null;
070:
071: /** Creates new PACFileIntranetInfo */
072: public PACFileIntranetInfo(String pacFileLocation) throws Exception {
073: this .pacFileLocation = pacFileLocation;
074: initDefaultDomainSubDomain();
075: EvalPAC.initPACFile(pacFileLocation);
076: }
077:
078: public String internGetWebProxy(String protocol, String host) {
079:
080: String proxy = EvalPAC.getProxy(protocol, host, "127.0.0.1");
081: if (proxy == null || proxy.trim().length() == 0
082: || proxy.trim().equalsIgnoreCase("null")) {
083: return null;
084: }
085: StringTokenizer st = new StringTokenizer(proxy);
086: String type = st.nextToken();
087:
088: if (type.equalsIgnoreCase("SOCKS")) {
089: // logger.severe("Gateway does not support SOCKS proxies !\n" +
090: // "Socks proxy \"" + proxy+ "\" returned for host : " + host);
091: Object[] params = { "\n", proxy, host };
092: logger.log(Level.SEVERE, "PSSR_CSPU086", params);
093: return null;
094: } else if (type.equalsIgnoreCase("DIRECT")) {
095: return null;
096: }
097: StringTokenizer st1 = new StringTokenizer(st.nextToken(), ";");
098: String retval = st1.nextToken();
099: return retval;
100: }
101:
102: public String getWebProxy(String protocol, String host) {
103: String proxy = internGetWebProxy(protocol, host);
104:
105: if (proxy == null && host.indexOf('.') == -1) {
106: proxy = internGetWebProxy(protocol, host
107: + defaultSubDomainAndDomain);
108: }
109: return proxy;
110: }
111:
112: public boolean internContainHost(String host) {
113: // It does not matter whether it is http or https to decide
114: // whether this is part of the intranet.
115: String proxy = EvalPAC.getProxy("http", host, "127.0.0.1");
116: if (proxy == null || proxy.trim().length() == 0
117: || proxy.trim().equalsIgnoreCase("null")) {
118: return false;
119: }
120: StringTokenizer st = new StringTokenizer(proxy);
121: String type = st.nextToken();
122:
123: if (type.equalsIgnoreCase("STARPROXY")) {
124: return false;
125: }
126: return true;
127: }
128:
129: public boolean containHost(String host) {
130: boolean retval = internContainHost(host);
131:
132: if (!retval && host.indexOf('.') == -1) {
133: retval = internContainHost(host + defaultSubDomainAndDomain);
134: }
135: return retval;
136: }
137: }
|