HTTPS is actually SSL over HTTP, which encrypts the original data in the sender by SSL, and the receiver
Therefore, the transmitted data is not easily intercepted and cracked by network hackers. This article describes three ways to implement HTTPS
。
Method one static hyperlink
This is the most widely used method of the site, but also the simplest. Links to Web pages that require the use of SSL for transport
is directly marked with the HTTPS protocol, the following is a hyperlink to a webpage that needs to use SSL:
<a href= "https://192.168.100.100/ok/securePage.jsp" >ssl example </a>
It is necessary to note that hyperlinks in a Web page, if used relative paths, are enabled by default and reference to the hyper-
The transport protocol for a linked web page or resource is the same, for example, in a hyperlink "https://192.168.100.100/ok/l
Ogin.jps "page contains the following two hyperlinks:
<a href= "./bessl/exam.jsp" >ssl links </a>
<a href= "http://192.168.100.100/notssl/index.jsp" > Non-SSL links
Then, the first link uses the same transport protocol as "https://192.168.100.100/ok/login.jsp"
HTTPS, the second link uses the protocol HTTP that is identified by itself.
The benefits of using static hyperlinks are easy to implement and do not require additional development. However, it is not easy to maintain management; Because
For a Web application that is fully accessed using the HTTP protocol, each resource is stored in the application's specific root directory.
In each subdirectory, the link path to the resource uses a relative path, which is done for ease of application migration and easy
to management. However, if some resources of the application are to use the HTTPS protocol, the referenced link must use the full path
, so when the app migrates or needs to change any part of the URL that is involved, such as: domain name, directory, file name, etc., maintain
Need to be modified for each hyperlink, the workload of the large can be imagined. Furthermore, if the customer is in the browser address bar
Manually input the HTTPS protocol resources, then all sensitive confidential data in the transmission is not protected, it is easy to be black
Customer Intercept and tamper!
Method two resource access restrictions
In order to protect sensitive data in web applications, prevent illegal access to resources and ensure the security of transmission, Java Serv
The Let 2.2 specification defines a security constraint (Security-constraint) component, which is used to specify one or more we
The security constraints of the B resource set; the User data constraint (user-data-constraint) element is a security constraint element
Subclass that specifies how the data transferred between the client and the container is protected. User data constraint meta
Also includes a transmission assurance (transport-guarantee) component, which specifies the communication between the client and the server
The letter must be one of the following three modes: None, Integral, Confidential. None indicates that the specified Web capital
The source does not require any transmission guarantees; Integral indicates that the data transmitted between the client and the server is not
will be tampered with; Confidential indicates that the data is encrypted during transmission. In most cases, the integral or co
Nfidential is implemented using SSL.
This is an example of how BEA WebLogic Server 6.1 is implemented, and WebLogic is a performance-based J2
EE server, which can set access control on managed Web resources, including EJB, JSP, servlet applications
Terms. Suppose an app is built under the/mywebapp directory in WebLogic server, some of which servle
TS, JSPs require the use of SSL transmission, then you can put them all in the/mywebapp/sslsource/directory, and then compile
/secureapp/web-inf/web.xml file, the Web user can achieve access
Control.
When a Web user tries to access resources in the/sslsource directory over HTTP, Weblogic server looks for the We
Access constraint definition in b.xml, return hint message: Need SSL connection to access this Reso
Urce. Resource access restrictions are used in conjunction with static hyperlinks, which not only inherit the simplicity of the static hyperlink method
, and it effectively protects sensitive resource data. However, there is a problem: if a Web customer uses HT
The TP protocol accesses a network resource that needs to use SSL when you see a popup message: Need SSL connection to
Access this resource, most people probably do not know should use HTTPS to visit this webpage, the result of
Is that the user will give up access to the webpage, which is something the Web App service provider doesn't want to see.
Method three-Link redirection
In view of the current commercial web site resource data interactive access, require strict encryption of the transmission of data only a small part of it,
This means that a service program that requires SSL in a specific Web application accounts for only a small part of the whole. Well, I
We can consider the workaround from application development to the part of the JSPs, Servlets, or
EJBS is processed so that the program itself, when receiving an access request, first determines whether the protocol used by the request conforms to the
The requirements of the program, that is, whether the visit request uses the HTTPS protocol, and if not, redirect its Access Protocol to HTTPS
, which prevents customers from seeing error prompts when they use the HTTP protocol to access Web resources that require the HTTPS protocol
Information is at a loss, and these processes are transparent to web customers.
The realization idea is: first create a class, which can implement automatic bootstrap Web Client access request using HTT
PS protocol, each servlets or JSPs that requires SSL to be transferred is invoked at the beginning of the program for protocol re-setting
Data application processing.
The Java EE provides two linkage redirection mechanisms. The first mechanism is the forward () in the RequestDispatcher interface.
Method. Web applications that use the MVC (Model-view-controller) mechanism typically use this approach from the servlet
Transfer the request to the JSP. But this turn can only be the same as the transition between the same protocol, and can not redirect to different protocols. The
Two mechanisms are using the Sendredirect () method in the Httpservletreponse interface, which can use any protocol
Redirect to any URL, for example:
Besslresponse.sendredirect ("Https://192.168.100.100/order");
In addition, we need to use the two methods in the Java Servlet API: Gets in the ServletRequest interface
Cheme (), which is used to obtain the transport protocol used by the access request; Getrequesturl () in the Httputils class, which
To get the URL of the access request, be aware that the method has been moved to Httpservletreq in Servlet 2.3
Uest interface.
The following are the basic steps to implement protocol redirection:
1. The protocol used to obtain access to the request;
2. If the request agreement complies with the protocol required by the servlet being accessed, it indicates that the HTTPS protocol has been used and does not
Need to do any processing;
3. If not compliant, use the Protocol (HTTPS) required by the servlet to redirect to the same URL.
For example, a Web user uses the HTTP protocol to access a resource that requires the HTTPS protocol Besslservlet, typing "UR
L:http://192.168.100.100/besslservlet ", first use proces when executing besslservlet
Ssslservlet. Processssl () redirects to Https://192.168.100.100/BeSslServlet, and then
The besslservlet is transmitted to and from the customer's browser via the HTTPS protocol.
The only simple example described above is to have a preliminary understanding of this redirection approach. If you want to really
Being implemented in a Web application, there are several issues that you must consider:
The Get or post method is often used in Web applications, and some query strings are taken in the URL of the access request.
These strings are not available with Getrequesurl () and are lost after redirection, so you must
Add them to the new URL before redirecting them. We can use request.getquerystring () to get G
ET's query string, for POST request parameters, you can convert them into a query string and then processing.
Some web app requests use objects as their properties, and these properties must be saved before redirection in the
Session in order to be redirected after use.
Most browsers treat different ports on the same host as access to different hosts, sharing
Different sessions, in order for the redirect to be retained using the original session, a cookie must be applied to the application server
The domain name is set accordingly.
The above problems can be solved in the program design.
By implementing protocol redirection through the program itself, the part of the resource that is strictly protected and other common data can be
Logically separate processing, which requires the use of SSL resources and resources that do not require the use of SSL picking, to avoid wasting
The system resources for the Web site.
Source: >
(HTTPS) How Web projects implement HTTPS