background image

Creating an Application

<< Troubleshooting the Example | Annotating the Service >>
<< Troubleshooting the Example | Annotating the Service >>

Creating an Application

If the topic of authentication is new to you, refer to the section titled
"Specifying an
Authentication Mechanism" on page 858
. For an explanation of how basic authentication
works, see
Figure 30­2
.
For this tutorial, you will add the security elements to the JAX-WS service and client; build,
package, and deploy the service; and then build and run the client application.
This example service was developed by starting with an unsecured service, helloservice,
which can be found in the directory
tut-install/javaeetutorial5/examples/jaxws/helloservice and is discussed in
"Creating a
Simple Web Service and Client with JAX-WS" on page 480
. You build on this simple
application by adding the necessary elements to secure the application using basic
authentication. The example client used in this application can be found at
tut-install/javaeetutorial5/examples/jaxws/simpleclient-basicauth, which only varies
from the original simpleclient application in that it uses the helloservice-basicauth
endpoint instead of the helloservice endpoint. The completed version of the secured service
can be found at tut-install/javaeetutorial5/examples/jaxws/helloservice-basicauth.
In general, the following steps are necessary to add basic authentication to a JAX-WS web
service. 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.
1. Create an application like the one in
"Creating a Simple Web Service and Client with
JAX-WS" on page 480
. The example in this tutorial starts with that example and
demonstrates adding basic authentication of the client to this application. The completed
version of this application is located in the directories
tut-install/javaeetutorial5/examples/jaxws/helloservice-basicauth and
tut-install/javaeetutorial5/examples/jaxws/simpleclient-basicauth.
2. If the port value was set to a value other than the default (8080), follow the instructions in
"Setting the Port" on page 480
to update the example files to reflect this change.
3. If you have not already done so, follow the steps in
"Building the Examples" on page 70
for
information on setting up your system to run the example.
4. If you have not already done so, add a user to the file realm and specify user for the group
of this new user. Write down the user name and password so that you can use them for
testing this application in a later step. If you have not already completed this step, refer to the
section
"Managing Users and Groups on the Application Server" on page 781
for
instructions.
5. Modify the source code for the service, Hello.java, to specify which roles are authorized to
access the sayHello (String name) method. This step is discussed in
"Annotating the
Service" on page 887
.
6. Add security elements that specify that basic authentication is to be performed to the
application deployment descriptor, web.xml. This step is discussed in
"Adding Security
Elements to the Deployment Descriptor" on page 888
.
Examples: Securing Web Applications
The Java EE 5 Tutorial · September 2007
886