tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r644704 - /openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
Date Fri, 04 Apr 2008 13:02:42 GMT
Author: jlaskowski
Date: Fri Apr  4 06:02:40 2008
New Revision: 644704

URL: http://svn.apache.org/viewvc?rev=644704&view=rev
Log:
Fix for java.lang.IllegalArgumentException: Mask localhost is not supported. where localhost
is in only_from

Modified:
    openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java

Modified: openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java?rev=644704&r1=644703&r2=644704&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
(original)
+++ openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
Fri Apr  4 06:02:40 2008
@@ -81,28 +81,40 @@
         if (ipString == null) {
             permissions.add(new PermitAllPermission());
         } else {
-            try {
-                InetAddress[] localIps = InetAddress.getAllByName("localhost");
-                for (int i = 0; i < localIps.length; i++) {
-                    if (localIps[i] instanceof Inet4Address) {
-                        permissions.add(new ExactIPAddressPermission(localIps[i].getAddress()));
-                    } else {
-                        permissions.add(new ExactIPv6AddressPermission(localIps[i].getAddress()));
-                    }
-                }
-            } catch (UnknownHostException e) {
-                throw new ServiceException("Could not get localhost inet address", e);
-            }
+        	String hostname = "localhost";
+            addIPAddressPermissions(permissions, hostname);
 
             StringTokenizer st = new StringTokenizer(ipString, " ");
             while (st.hasMoreTokens()) {
                 String mask = st.nextToken();
-                permissions.add(IPAddressPermissionFactory.getIPAddressMask(mask));
+                try {
+                	permissions.add(IPAddressPermissionFactory.getIPAddressMask(mask));
+                } catch (IllegalArgumentException iae) {
+                	// it could be that it is a hostname not ip address
+                	addIPAddressPermissions(permissions, mask);
+                }
             }
         }
 
         hostPermissions = (IPAddressPermission[]) permissions.toArray(new IPAddressPermission[permissions.size()]);
     }
+
+	private void addIPAddressPermissions(
+			LinkedList<IPAddressPermission> permissions, String hostname)
+			throws ServiceException {
+		try {
+		    InetAddress[] localIps = InetAddress.getAllByName(hostname);
+		    for (int i = 0; i < localIps.length; i++) {
+		        if (localIps[i] instanceof Inet4Address) {
+		            permissions.add(new ExactIPAddressPermission(localIps[i].getAddress()));
+		        } else {
+		            permissions.add(new ExactIPv6AddressPermission(localIps[i].getAddress()));
+		        }
+		    }
+		} catch (UnknownHostException e) {
+		    throw new ServiceException("Could not get " + hostname + " inet address", e);
+		}
+	}
 
     public void init(Properties props) throws Exception {
         parseAdminIPs(props);



Mime
View raw message