Write an application that supports an agency-based firewall

zhaozj2021-02-08  368

Almost all companies are very concerned about protecting their own internal networks to prevent hackers and theft. One common security measures are completely disconnected from the Internet. If hackers cannot connect to any of your machines, they can't illegally enter your system. The adverse side effects of this strategy are that internal users cannot access external Internet servers, such as Yahoo or

Javaworld. In order to solve this problem, network administrators usually install "proxy server". In fact, the agent is a service installed between the Internet and the internal network to manage connections between these two areas. The agent helps reduce external threats, while also allowing internal users to access Internet services. Although Java makes it difficult to write Internet clients, if the client cannot pass the agent, they are useless. Fortunately, Java makes it difficult to use agency support - if you know the priest, this is the fact.

The secret combining Java and proxy is to activate specific system properties at Java runtime. These attributes are not written in a formal file, just as part of the Java legend, secret transmission in Java programmers. In order to support the agent, Java applications not only need to specify the information of the agent itself, but also need to specify user information for authentication. Before you start using the Internet Protocol, you need to add the following lines of code in the program:

System.getProperties (). Put ("proxyset", "true"); system.getproperties (). Put ("proxyhost", "myproxymachinename); system.getproperties (). Put (" proxyport "," 85 ") ;

The first line of the above informs Java you have to connect through the proxy, the second line specifies the machine where the agent is located, the third line specifies the port of the agent listening. Some agents require users to enter user names and passwords before authorizing users to access the Internet. If you use a web browser within the firewall, you may have encountered this situation. The following is a method of performing an authentication:

URLConnection connection = url.openConnection (); String password = "username: password"; String encodedPassword = base64Encode (password); connection.setRequestProperty ( "Proxy-Authorization", encodedPassword);

The idea of ​​this code is that you must adjust the HTTP header to issue user information. This is achieved by calling setRequestProperty (). This method allows you to handle the HTTP header before issuing a request. HTTP requires the username and password to encode with Base64. Fortunately, there is a set of public domain APIs that will execute you code (see Reference Resources).

If you see, adding proxy support in the Java application, don't do much work. With the current knowledge, do a little study (you must find out how your agent handles the protocol you are interested in and how to implement user authentication), you can use other protocols to achieve a proxy.

FTP proxy Scott D. Taylor presents this secret to handle FTP protocol proxy:

DefaultProperties.put ("ftpproxyset", "true"); defaultproperties, "proxy-host-name"); defaultproperties.put ("ftpproxyport", "85"); then you can pass the following The code uses the "FTP" protocol to access the file URL:

URL URL = New URL ("ftp://ftp.netscape.com/pub/navigator/3.04/windows/readme.txt");

If someone has an example of using other interval agents, I really want to see.

Note: The code example (Example.java) is only tested under JDK 1.1.4.

Subsequent skills!

转载请注明原文地址:https://www.9cbs.com/read-818.html

New Post(0)