Creating and Securing a Service  Locate

First, we will create a simple Web service, then we will configure it to require authentication and method access authorization.

The source code for this service is shown in Example 1

Example 1. Simple Web Service Implementation Without Security

// Copyright 2002 Systinet Corp. All rights reserved.
// Use is subject to license terms.
package example.security;

public class Service1 {
    public String doIt(String message) {
        return message;
    }
}

The service must be compiled in order to be deployed. To compile it, use the following command for Windows, in the %WASP_HOME%\src directory. (On UNIX systems, change each backslash (\) to a forward slash (/).)

javac -d. example\security\Service1.java

Next, we will use single class deployment to create a Web service and its endpoint on the WSO2 SOA Enablement Server. To deploy this service, please use the following command in the %WASP_HOME%\bin directory (on UNIX systems, the command name is ./deploy). Note that deploy will ask for the administrator name and password. Default name is "admin" and the default password is "changeit."

Deploy --target http://localhost:6060 --classpath ../src --class example.security.Service1 --uri /Service1

Now the service should be successfully deployed and ready for client calls. Before we continue with the client side, we must configure the deployed Web service security settings.

We must set the required authorization and particular authentication mechanism to be used for a given Web service endpoint. This is done through the WSO2 SOA Enablement Server Administration Console.

To set authorization and authentication:

  1. Open the WSO2 SOA Enablement Server Administration console. With WSO2 SOA Enablement Server running, either use the desktop icon or point your browser to http://localhost:6060/admin/console assuming local installation on the default port.

  2. Click on the Web Services tree node of the Administration Console. This loads the Runtime View panel, which lists all service instances.

  3. Click on the relevant service instance, which in this case is /Service1. This opens the Web Service Management window, the top of which is shown in Figure 7.

Figure 7. Web Service Management Window

Web Service Management Window

This service instance has only one endpoint, which is automatically selected. Scroll down through the screen to the Service Endpoint section shown in Figure 8. Click Set Endpoint Security and then click Custom Security Providers.

Figure 8. Service Endpoint Window

Service Endpoint Window

check the Authorization Required box, and the box for HttpBasic authentication provider, as shown in Figure 9.

Figure 9. Setting Service1 Endpoint Authentication and Authorization

Setting Service1 Endpoint Authentication and Authorization

Next, click Save Changes to propagate your settings to WSO2 SOA Enablement Server runtime.

[Note]Note

You can also use the ProvidersManager tool to set authentication and authorization requirements.

On UNIX systems, use ./ProvidersManager.

ProvidersManager.bat -t http://localhost:6060 -b /Service1 -a HttpBasic --az-on