HTTP Client – Form-Based Authentication
•Robert Broeckelmann
This article continues the discussion started in the Servlet Authentication article. Here we discuss Form-Based authentication; another common form of authentication when Servlet technology is used.
Form-Based Authentication
Form-based Authentication, like Basic Authentication, requires the user to submit a userid and password. However, instead of relying upon the HTTP AUTHORIZATION header to propagate the security credentials, a Form-based login request implements a simple “work flow” based upon 302 redirects, a simple HTML form, and a POST operation to Servlet-spec defined Servlet that all Servlet Containers must implement.
Form-based Authentication uses a Servlet that is required to be available to all Web Applications. This doesn’t mean each WAR must have this Servlet class. The container must simply be able to process requests to this Servlet’s spec-defined path under each Context Root.
Figure 4 below shows the steps involved in accessing a page protected by JEE Security using Form-based Authentication. A Browser initially makes an HTTP GET call to index.html. The Server sees that the requested path is protected; it also sees that there is no existing security session that belongs to this request. So, the Server responds to the request with a 302 REDIRECT to a login page, login.jsp. What login page to display in this step is configurable in the WAR’s web.xml deployment descriptor. The login page must define a form similar to the following:

