Author: channa
Date: Wed Jan 23 21:28:14 2008
New Revision: 12795
Log:
Changed localhost check to be more reliable.
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
Wed Jan 23 21:28:14 2008
@@ -15,8 +15,8 @@
*/
package org.wso2.mashup.utils;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
@@ -36,8 +36,12 @@
import org.apache.rampart.RampartMessageData;
import org.apache.rampart.policy.model.CryptoConfig;
import org.apache.rampart.policy.model.RampartConfig;
+import org.wso2.javascript.rhino.JavaScriptEngineConstants;
import org.wso2.mashup.MashupConstants;
import org.wso2.mashup.MashupFault;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.jdbc.JDBCRegistry;
import org.wso2.usermanager.UserManagerException;
import org.wso2.utils.ServerConfiguration;
import org.wso2.utils.security.CryptoUtil;
@@ -45,16 +49,25 @@
import org.wso2.wsas.ServerManager;
import org.wso2.wsas.persistence.PersistenceManager;
import org.wso2.wsas.persistence.dataobject.ServiceUserDO;
-import org.wso2.registry.jdbc.JDBCRegistry;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.RegistryException;
-import org.wso2.javascript.rhino.JavaScriptEngineConstants;
-import javax.management.*;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.namespace.QName;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
import javax.servlet.http.HttpServletRequest;
-import java.io.*;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Properties;
@@ -638,8 +651,23 @@
* @return true if the request was for localhost.
*/
public static boolean isFromLocalHost(HttpServletRequest request) {
- String hostName = request.getLocalName();
- return MashupConstants.LOCALHOST.equalsIgnoreCase(hostName) ||
MashupConstants.
- LOCALHOST_IP.equals(hostName);
+ String urlString = request.getRequestURL().toString();
+ String hostPart;
+
+ // Try to get using the utility method, failing which try using string
manipulation.
+ try {
+ URL url = new URL(urlString);
+ hostPart = url.getHost();
+ } catch (MalformedURLException e) {
+ // Attempting this manually for bad URL's as start page is
critical.
+ String protocolSeparator = "://";
+ int startHostName = urlString.indexOf(protocolSeparator) +
protocolSeparator.length();
+ int portSeparator = urlString.indexOf(":", startHostName);
+ int endHostName = portSeparator != -1 && portSeparator <
urlString.indexOf("/",
+ startHostName) ? portSeparator : urlString.indexOf("/",
startHostName);
+ hostPart = urlString.substring(startHostName, endHostName);
+ }
+ return MashupConstants.LOCALHOST.equalsIgnoreCase(hostPart) ||
MashupConstants.LOCALHOST_IP.
+ equals(hostPart);
}
}
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev