[jboss-remoting-commits] JBoss Remoting SVN: r5016 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Apr 14 06:20:53 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-14 06:20:53 -0400 (Tue, 14 Apr 2009)
New Revision: 5016

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java	2009-04-14 10:20:18 UTC (rev 5015)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java	2009-04-14 10:20:53 UTC (rev 5016)
@@ -64,6 +64,9 @@
 import java.net.SocketAddress;
 import java.net.SocketTimeoutException;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -328,12 +331,12 @@
             conn.setDoInput(true);
             conn.setRequestMethod(type);
 
-            OutputStream stream = SecurityUtility.getOutputStream(conn);        
+            OutputStream stream = getOutputStream(conn);        
             if (marshaller instanceof VersionedMarshaller)
                ((VersionedMarshaller) marshaller).write(invocation, stream, getVersion());
             else
                marshaller.write(invocation, stream);
-            responseCode = SecurityUtility.getResponseCode(conn);
+            responseCode = getResponseCode(conn);
 
             Map headers = conn.getHeaderFields();
             if (metadata == null)
@@ -355,7 +358,7 @@
                }
             }
 
-            String responseMessage = SecurityUtility.getResponseMessage(conn);
+            String responseMessage = getResponseMessage(conn);
             metadata.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, responseMessage);
             metadata.put(HTTPMetadataConstants.RESPONSE_CODE, new Integer(responseCode));
             metadata.put(HTTPMetadataConstants.RESPONSE_HEADERS, headers);
@@ -372,9 +375,9 @@
             conn.setDoInput(true);
             conn.setRequestMethod(type);
 
-            SecurityUtility.connect(conn);
+            connect(conn);
 
-            InputStream is = (SecurityUtility.getResponseCode(conn) < 400) ? conn.getInputStream() : conn.getErrorStream();
+            InputStream is = (getResponseCode(conn) < 400) ? conn.getInputStream() : conn.getErrorStream();
             Map headers = conn.getHeaderFields();
 
             if (is != null || unmarshalNullStream)
@@ -387,9 +390,9 @@
                metadata = new HashMap();
             }
             metadata.putAll(headers);
-            String responseMessage = SecurityUtility.getResponseMessage(conn);
+            String responseMessage = getResponseMessage(conn);
             metadata.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, responseMessage);
-            responseCode = SecurityUtility.getResponseCode(conn);
+            responseCode = getResponseCode(conn);
             metadata.put(HTTPMetadataConstants.RESPONSE_CODE, new Integer(responseCode));
             metadata.put(HTTPMetadataConstants.RESPONSE_HEADERS, conn.getHeaderFields());
          }
@@ -402,8 +405,8 @@
  
          try
          {
-            String responseMessage = SecurityUtility.getResponseMessage(conn);
-            int code = SecurityUtility.getResponseCode(conn);
+            String responseMessage = getResponseMessage(conn);
+            int code = getResponseCode(conn);
             message += " Response: " + responseMessage + "/" + code + ".";
          }
          catch (IOException e1)
@@ -495,7 +498,7 @@
                conn.setRequestProperty(HTTPMetadataConstants.REMOTING_USER_AGENT, "JBossRemoting - " + Version.VERSION);
                conn.setRequestProperty(HTTPMetadataConstants.REMOTING_LEASE_QUERY, "true");
                conn.setRequestProperty("sessionId", request.getSessionId());
-               SecurityUtility.connect(conn);
+               connect(conn);
 
                //InputStream is = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
                Map headers = conn.getHeaderFields();
@@ -599,7 +602,7 @@
             {
                Class cl = conn.getClass();
                Class[] paramTypes = new Class[] {int.class};
-               Method setChunkedLengthMethod = SecurityUtility.getMethod(cl, "setChunkedStreamingMode", paramTypes);
+               Method setChunkedLengthMethod = getMethod(cl, "setChunkedStreamingMode", paramTypes);
                setChunkedLengthMethod.invoke(conn, new Object[]{new Integer(chunkedLength)});
             }
             catch (NoSuchMethodException e)
@@ -675,9 +678,9 @@
       {
          Class cl = conn.getClass();
          Class[] paramTypes = new Class[] {int.class};
-         Method setTimeoutMethod = SecurityUtility.getMethod(cl, "setConnectTimeout", paramTypes);
+         Method setTimeoutMethod = getMethod(cl, "setConnectTimeout", paramTypes);
          setTimeoutMethod.invoke(conn, new Object[]{new Integer(timeout)});
-         setTimeoutMethod = SecurityUtility.getMethod(cl, "setReadTimeout", paramTypes);
+         setTimeoutMethod = getMethod(cl, "setReadTimeout", paramTypes);
          setTimeoutMethod.invoke(conn, new Object[]{new Integer(timeout)});
          return -1;
       }
@@ -817,7 +820,7 @@
             }
             Constructor proxyConstructor = proxyClass.getConstructor(new Class[] {proxyTypeClass, SocketAddress.class});
             Object proxy = proxyConstructor.newInstance(new Object[] {proxyType, proxyAddress});
-            Method openConnection = SecurityUtility.getMethod(URL.class, "openConnection", new Class[] {proxyClass});
+            Method openConnection = getMethod(URL.class, "openConnection", new Class[] {proxyClass});
             httpURLConn = (HttpURLConnection)openConnection.invoke(externalURL, new Object[] {proxy});
          }
          catch (Exception e)
@@ -840,7 +843,7 @@
          httpURLConn = (HttpURLConnection) externalURL.openConnection();
          
          // Check if proxy is being configured by system properties.
-         if (SecurityUtility.getSystemProperty("http.proxyHost") != null)
+         if (getSystemProperty("http.proxyHost") != null)
          {
             String proxyAuth = getProxyAuth(metadata);
             if (proxyAuth != null)
@@ -865,7 +868,7 @@
       }
       if (username == null || username.length() == 0)
       {
-         username = SecurityUtility.getSystemProperty("http.proxy.username");
+         username = getSystemProperty("http.proxy.username");
       }
       if (metadata != null)
       {
@@ -873,7 +876,7 @@
       }
       if (password == null)
       {
-         password = SecurityUtility.getSystemProperty("http.proxy.password");
+         password = getSystemProperty("http.proxy.password");
       }
 
       if (username != null && password != null)
@@ -904,7 +907,7 @@
       }
       if (username == null || username.length() == 0)
       {
-         username = SecurityUtility.getSystemProperty("http.basic.username");
+         username = getSystemProperty("http.basic.username");
       }
       if (metadata != null)
       {
@@ -912,7 +915,7 @@
       }
       if (password == null)
       {
-         password = SecurityUtility.getSystemProperty("http.basic.password");
+         password = getSystemProperty("http.basic.password");
       }
 
       if (username != null && password != null)
@@ -1129,4 +1132,149 @@
          return "WaitingTaskWrapper[" + completeTimeout + "]";
       }
    }
+   
+   static private String getSystemProperty(final String name)
+   {
+      if (SecurityUtility.skipAccessControl())
+         return System.getProperty(name);
+      
+      String value = null;
+      try
+      {
+         value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.getProperty(name);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+      
+      return value;
+   }
+   
+   static private Method getMethod(final Class c, final String name, final Class[] parameterTypes)
+   throws NoSuchMethodException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return c.getMethod(name, parameterTypes);
+      }
+
+      try
+      {
+         return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws NoSuchMethodException
+            {
+               return c.getMethod(name, parameterTypes);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (NoSuchMethodException) e.getCause();
+      }
+   }
+   
+   static private void connect(final HttpURLConnection conn) throws IOException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         conn.connect();
+         return;
+      }
+
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               conn.connect();
+               return null;
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }
+   }
+   
+   static private OutputStream getOutputStream(final HttpURLConnection conn)
+   throws IOException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return conn.getOutputStream();
+      }
+      
+      try
+      {
+         return (OutputStream)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               return conn.getOutputStream();
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }
+   }
+   
+   static private int getResponseCode(final HttpURLConnection conn)
+   throws IOException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return conn.getResponseCode();
+      }
+      
+      try
+      {
+         return ((Integer) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               return new Integer(conn.getResponseCode());
+            }
+         })).intValue();
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }
+   }
+   
+   static private String getResponseMessage(final HttpURLConnection conn)
+   throws IOException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return conn.getResponseMessage();
+      }
+      
+      try
+      {
+         return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               return conn.getResponseMessage();
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }
+   }
 }
\ No newline at end of file




More information about the jboss-remoting-commits mailing list