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:
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.
Click on the Web Services tree node of the Administration Console. This loads the Runtime View panel, which lists all service instances.
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.
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.
check the Authorization Required box, and the box for HttpBasic authentication provider, as shown in Figure 9.
Next, click Save Changes to propagate your settings to WSO2 SOA Enablement Server runtime.
![]() | 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 |