background image

Example of Basic Authentication

<< Running Web Application | Declaring Security Roles >>
<< Running Web Application | Declaring Security Roles >>

Example of Basic Authentication

Note ­
For repetitive testing of this example, you may need to close and reopen your browser.
You should also run the ant clean and ant undeploy commands to ensure a fresh build if
using the Ant tool, or select Clean and Build Project then Deploy Project if using NetBeans IDE.
Example: Basic Authentication with a Servlet
This example discusses how to use basic authentication with a servlet. With basic
authentication of a servlet, the web browser presents a standard login dialog that is not
customizable. When a user submits their name and password, the server determines if the user
name and password are those of an authorized user and sends the requested web resource if the
user is authorized to view it. If the topic of authentication is new to you, please refer to the
section
"Specifying an Authentication Mechanism" on page 858
.
In general, the following steps are necessary for adding basic authentication to an unsecured
servlet, such as the one described in
"Web Modules" on page 81
. In the example application
included with this tutorial, many of these steps have been completed for you and are listed here
simply to show what needs to be done should you wish to create a similar application. The
completed version of this example application can be found in the directory
tut-install/javaeetutorial5/examples/web/hello2_basicauth/.
FIGURE 30­8
The Running Form-Based Authentication Example
Examples: Securing Web Applications
Chapter 30 · Securing Web Applications
877