10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Examples: SecuringWeb Applications<br />

864<br />

application included with this tutorial, many of these steps have been completed for you and are<br />

listed here simply to show what needs to be done should you wish to create a similar<br />

application. <strong>The</strong> completed version of this example application can be found in the directory<br />

tut-install/javaeetutorial5/examples/web/hello1_formauth/.<br />

<strong>The</strong> following steps describe how to set up your system for running the example applications,<br />

describe the sample application, and provide the steps for compiling, packaging, deploying, and<br />

testing the example application.<br />

1. If you have not already done so, set up your system so that the Ant tool and/or NetBeans<br />

IDE will run properly. To do this, follow the instructions in “Building the Examples” on<br />

page 69.<br />

2. If you have not already done so, add an authorized user to the Application Server. For this<br />

example, add users to the file realm of the Application Server and assign the user to the<br />

group user. This topic is discussed more in “Adding Authorized Roles and Users” on<br />

page 868.<br />

3. Create a web module as described in “Web Modules” on page 81. <strong>The</strong> subsequent steps<br />

discuss adding security to this basic application. <strong>The</strong> resulting application is found in the<br />

directory tut-install/javaeetutorial5/examples/web/hello1_formauth/.<br />

4. Create the login form and login error form pages. Files for the example application can be<br />

viewed at tut-install/javaeetutorial5/examples/web/hello1_formauth/web. <strong>The</strong>se<br />

pages are discussed in “Creating the Login Form and the Error Page” on page 865.<br />

5. Create a web.xml deployment descriptor and add the appropriate security elements (the<br />

application on which this section is based did not originally require a deployment<br />

descriptor.) <strong>The</strong> deployment descriptor for the example application can be viewed at<br />

tut-install/javaeetutorial5/examples/hello1_formauth/web/WEB-INF. <strong>The</strong> security<br />

elements for the web.xml deployment descriptor are described in “Specifying a Security<br />

Constraint” on page 866.<br />

6. Map the role name defined for this resource (loginUser) to a group of users defined on the<br />

Application Server. For more information on how to do this, read “Mapping Application<br />

Roles to Application Server Groups” on page 869.<br />

7. Build, package, deploy, and run the web application by following the steps in “Building,<br />

Packaging, and Deploying the Form-Based Authentication Example Using NetBeans IDE”<br />

on page 869 or “Building, Packaging, and Deploying the Form-Based Authentication<br />

Example Using Ant” on page 870.<br />

8. Test the web client, following the steps in “Testing the Form-Based Authentication Web<br />

Client” on page 870.<br />

Creating aWeb Client for Form-Based Authentication<br />

<strong>The</strong> web client in this example is a standard JSP page, and annotations are not used in JSP pages<br />

because JSP pages are compiled as they are presented to the browser. <strong>The</strong>refore, none of the<br />

code that adds form-based authentication to the example is included in the web client. <strong>The</strong> code<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!