The WSIT Tutorial

Example: Username Authentication with Symmetric Keys (UA)

The section describes the following tasks:

ProcedureTo Secure the Example Service Application (UA)

The following example application starts with the example provided in Chapter 3, WSIT Example Using a Web Container and NetBeans IDE and demonstrates adding security to both the web service and to the web service client.

For this example, the security mechanism of Username Authentication with Symmetric Keys is used to secure the application. To add security to the service part of the example, follow these steps.

  1. If you haven’t already completed these steps, complete them now:

    1. Update the GlassFish keystore and truststore files as described in To Update GlassFish Certificates.

    2. Create a user on GlassFish as described in Adding Users to GlassFish.

  2. Create the CalculatorApplication example by following the steps described in the following sections of Chapter 3, WSIT Example Using a Web Container and NetBeans IDE.

    1. Creating a Web Service

    2. Skip the section on adding Reliable Messaging.

    3. Deploying and Testing a Web Service (first two steps only, do not run the project yet)

  3. Expand CalculatorApplication->Web Services, then right-click the node for the web service (CalculatorWS) and select Edit Web Service Attributes.

  4. Deselect Reliable Messaging if it is selected.

  5. In the CalculatorWSPortBinding section, select Secure Service.

  6. From the drop-down list for Security Mechanism, select Username Authentication with Symmetric Keys.

  7. Click the Keystore button to provide your keystore with the alias identifying the service certificate. To do this, click the Load Aliases button and select xws-security-server, then click OK to close the dialog.

  8. Click OK to close the WSIT Configuration dialog.

    A new file is added to the project. To view the WSIT configuration file, expand Web Pages->WEB-INF, then double-click the file wsit-org.me.calculator.CalculatorWS.xml. This file contains the sc:KeyStore element.

    An example of this file can be viewed in the tutorial by clicking this link: Service-Side WSIT Configuration Files.

  9. Right-click the CalculatorApplication node and select Run Project. A browser will open and display the WSDL file for the application.

  10. Verify that the WSDL file contains the following elements: SymmetricBinding and UsernameToken.

  11. Follow the steps to secure the client application as described in To Secure the Example Web Service Client Application (UA).

ProcedureTo Secure the Example Web Service Client Application (UA)

This section demonstrates adding security to the web service client that references the web service created in the previous section. This web service is secured using the security mechanism described in Username Authentication with Symmetric Keys. When this security mechanism is used with a web service, the web service client must provide a username and password in addition to specifying the certificate of the server.

To add security to the client that references this web service, complete the following steps.

  1. Create the client application by following the steps described in Creating a Client to Consume a WSIT-Enabled Web Service.


    Note –

    Whenever you make changes on the service, refresh the client so that the client will pick up the change. To refresh the client, right-click the node for the Web Service Reference for the client, and select Refresh Client.


  2. Expand the node for the web service client application, CalculatorWSServletClient.

  3. Expand the node for Web Service References.

  4. Right-click CalculatorWSService and select Edit Web Service Attributes.

  5. Select the WSIT Configuration tab of the CalculatorWSService dialog.

  6. For this testing environment, provide a default username and password. To do this, follow these steps:

    1. Expand the Username Authentication node.

    2. Type the username and password that you created on GlassFish into the Default Username and Default Password fields. If you followed the steps in the section Adding Users to GlassFish, the user name is wsitUser and the password is changeit.


    Note –

    In a production environment, you should configure a Username Handler and a Password Handler class to eliminate the security risk associated with the default username and password options.


  7. Provide the server’s certificate by pointing to an alias in the client truststore. To do this, select the Certificates node, click the Load Aliases button for the Truststore, then select xws-security-server from the Truststore Alias list.

  8. Click OK to close this dialog.

  9. In the tree, drill down from the project to Source Packages->META-INF. Double-click on CalculatorWSService.xml, and verify that lines similar to the following are present:

    <wsp:All>
      <wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
      <sc:CallbackHandlerConfiguration wspp:visibility="private">
        <sc:CallbackHandler default="wsitUser" name="usernameHandler"/>
        <sc:CallbackHandler default="changeit" name="passwordHandler"/>
      </sc:CallbackHandlerConfiguration>
      <sc:TrustStore wspp:visibility="private" 
          location="home\glassfish\domains\domain1\config\cacerts.jks"
          storepass="changeit" peeralias="xws-security-server"/>
    </wsp:All>

    An example of this file can be viewed in the tutorial by clicking this link: Client-Side WSIT Configuration Files.

  10. Right-click the CalculatorWSServletClient node and select Run Project.