コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private Socket doTunnel(String urlString, int connectTimeout) throws java.io.IOException
        private Socket DoTunnel(String urlString, int connectTimeout)
        {
            Proxy             proxy   = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Server, Port_Renamed));
            URL               destURL = new URL(urlString);
            HttpURLConnection conn    = (HttpURLConnection)destURL.OpenConnection(proxy);

            conn.ConnectTimeout = connectTimeout;
            conn.ReadTimeout    = this.Timeout_Renamed;
            conn.Connect();
            DoTunneling(conn);
            try
            {
                Object httpClient = HttpField.get(conn);
                return((Socket)ServerSocketField.get(httpClient));
            }
            catch (IllegalAccessException x)
            {
                throw new InternalError("Should not reach here", x);
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns an input stream for reading the specified resource.
        /// If this loader is closed, then any resources opened by this method
        /// will be closed.
        ///
        /// <para> The search order is described in the documentation for {@link
        /// #getResource(String)}.  </para>
        /// </summary>
        /// <param name="name">
        ///         The resource name
        /// </param>
        /// <returns>  An input stream for reading the resource, or {@code null}
        ///          if the resource could not be found
        ///
        /// @since  1.7 </returns>
        public override InputStream GetResourceAsStream(String name)
        {
            URL url = GetResource(name);

            try
            {
                if (url == null)
                {
                    return(null);
                }
                URLConnection urlc = url.OpenConnection();
                InputStream   @is  = urlc.InputStream;
                if (urlc is JarURLConnection)
                {
                    JarURLConnection juc = (JarURLConnection)urlc;
                    JarFile          jar = juc.JarFile;
                    lock (Closeables)
                    {
                        if (!Closeables.ContainsKey(jar))
                        {
                            Closeables.Put(jar, null);
                        }
                    }
                }
                else if (urlc is sun.net.www.protocol.file.FileURLConnection)
                {
                    lock (Closeables)
                    {
                        Closeables.Put(@is, null);
                    }
                }
                return(@is);
            }
            catch (IOException)
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns the permissions for the given codesource object.
        /// The implementation of this method first calls super.getPermissions
        /// and then adds permissions based on the URL of the codesource.
        /// <para>
        /// If the protocol of this URL is "jar", then the permission granted
        /// is based on the permission that is required by the URL of the Jar
        /// file.
        /// </para>
        /// <para>
        /// If the protocol is "file" and there is an authority component, then
        /// permission to connect to and accept connections from that authority
        /// may be granted. If the protocol is "file"
        /// and the path specifies a file, then permission to read that
        /// file is granted. If protocol is "file" and the path is
        /// a directory, permission is granted to read all files
        /// and (recursively) all files and subdirectories contained in
        /// that directory.
        /// </para>
        /// <para>
        /// If the protocol is not "file", then permission
        /// to connect to and accept connections from the URL's host is granted.
        /// </para>
        /// </summary>
        /// <param name="codesource"> the codesource </param>
        /// <exception cref="NullPointerException"> if {@code codesource} is {@code null}. </exception>
        /// <returns> the permissions granted to the codesource </returns>
        protected internal override PermissionCollection GetPermissions(CodeSource codesource)
        {
            PermissionCollection perms = base.GetPermissions(codesource);

            URL url = codesource.Location;

            Permission    p;
            URLConnection urlConnection;

            try
            {
                urlConnection = url.OpenConnection();
                p             = urlConnection.Permission;
            }
            catch (IOException)
            {
                p             = null;
                urlConnection = null;
            }

            if (p is FilePermission)
            {
                // if the permission has a separator char on the end,
                // it means the codebase is a directory, and we need
                // to add an additional permission to read recursively
                String path = p.Name;
                if (path.EndsWith(File.Separator))
                {
                    path += "-";
                    p     = new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
                }
            }
            else if ((p == null) && (url.Protocol.Equals("file")))
            {
                String path = url.File.Replace('/', System.IO.Path.DirectorySeparatorChar);
                path = ParseUtil.decode(path);
                if (path.EndsWith(File.Separator))
                {
                    path += "-";
                }
                p = new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
            }
            else
            {
                /// <summary>
                /// Not loading from a 'file:' URL so we want to give the class
                /// permission to connect to and accept from the remote host
                /// after we've made sure the host is the correct one and is valid.
                /// </summary>
                URL locUrl = url;
                if (urlConnection is JarURLConnection)
                {
                    locUrl = ((JarURLConnection)urlConnection).JarFileURL;
                }
                String host = locUrl.Host;
                if (host != null && (host.Length() > 0))
                {
                    p = new SocketPermission(host, SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION);
                }
            }

            // make sure the person that created this class loader
            // would have this permission

            if (p != null)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SecurityManager sm = System.getSecurityManager();
                SecurityManager sm = System.SecurityManager;
                if (sm != null)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.security.Permission fp = p;
                    Permission fp = p;
                    AccessController.doPrivileged(new PrivilegedActionAnonymousInnerClassHelper3(this, sm, fp), Acc);
                }
                perms.Add(p);
            }
            return(perms);
        }