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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Examples: SecuringWeb Applications<br />

882<br />

In general, the following steps are necessary to add basic authentication to a JAX-WS web<br />

service. In the example application included with this tutorial, many of these steps have been<br />

completed for you and are listed here simply to show what needs to be done should you wish to<br />

create a similar application.<br />

1. Create an application like the one in “Creating a Simple Web Service and Client with<br />

JAX-WS” on page 478. <strong>The</strong> example in this tutorial starts with that example and<br />

demonstrates adding basic authentication of the client to this application. <strong>The</strong> completed<br />

version of this application is located in the directories<br />

tut-install/javaeetutorial5/examples/jaxws/helloservice-basicauth and<br />

tut-install/javaeetutorial5/examples/jaxws/simpleclient-basicauth.<br />

2. If the port value was set to a value other than the default (8080), follow the instructions in<br />

“Setting the Port” on page 478 to update the example files to reflect this change.<br />

3. If you have not already done so, follow the steps in “Building the Examples” on page 69 for<br />

information on setting up your system to run the example.<br />

4. If you have not already done so, add a user to the file realm and specify user for the group<br />

of this new user. Write down the user name and password so that you can use them for<br />

testing this application in a later step. If you have not already completed this step, refer to the<br />

section “Managing Users and Groups on the Application Server” on page 779 for<br />

instructions.<br />

5. Modify the source code for the service, Hello.java, to specify which roles are authorized to<br />

access the sayHello (String name) method. This step is discussed in “Annotating the<br />

Service” on page 882.<br />

6. Add security elements that specify that basic authentication is to be performed to the<br />

application deployment descriptor, web.xml. This step is discussed in “Adding Security<br />

Elements to the Deployment Descriptor” on page 883.<br />

7. Modify the runtime deployment descriptor, sun-web.xml, to map the role used in this<br />

application (basicUser) to a group defined on the Application Server (user). This step is<br />

discussed in “Linking Roles to Groups” on page 884.<br />

8. Build, package, and deploy the web service. See “Building and Deploying helloservice<br />

with Basic Authentication Using NetBeans IDE” on page 885 or “Building and Deploying<br />

helloservice with Basic Authentication Using Ant” on page 886 for the steps to accomplish<br />

this.<br />

9. Build and run the client application. See “Building and Running the helloservice Client<br />

Application with Basic Authentication Using NetBeans IDE” on page 886 or “Building and<br />

Running the helloservice Client Application with Basic Authentication Using Ant” on<br />

page 887 for the steps to accomplish this.<br />

Annotating the Service<br />

In this example, annotations are used to specify which users are authorized to access which<br />

methods of this service. In this simple example, the @RolesAllowed annotation is used to<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!