Articles
Service-Oriented Architecture
by William Markito Oliveira and Fabio Mazanatti
Providing a secure environment for your Web Services
Published March 2012
Oracle Enterprise Gateway (OEG) and Oracle Web Services Manager (OWSM) are two central points of a SOA initiative when security is paramount. This article describes how to integrate these products with Oracle Service Bus (OSB), providing a secure environment for your Web Services. Although these products can do a lot more, the focus of this article is on authentication, a pressing concern when securing exposed services.
This article assumes the reader has knowledge in the following areas:
You will also need:

You may use Oracle SOA Suite's virtual machine (Pre-built Virtual Machine for SOA Suite and BPM Suite 11g) to save some time. In this case, you'll have to install Oracle Enterprise Gateway and Oracle Service Bus, creating a new Service Bus domain with the configuration mentioned above.
If you want to set up a brand new Oracle SOA Suite installation, follow the instructions in the Oracle SOA Suite Quick Start Guide document, then install OSB and configure a new domain as instructed. You can use the Oracle Service Bus for Developers option for this step (screenshot above) in order to save some memory and CPU (the Developer option creates only one server instead of an Admin plus a Managed server).
Oracle Enterprise Gateway is designed to secure SOA deployments across domain boundaries and, more specifically, web services calls going over wide-area networks. It does this by providing an easy way to secure (authenticate, introspect, etc.) and accelerate XML and other types of data. Oracle Enterprise Gateway offers rich integration with many identity and access management platforms and, more specifically, Oracle Identity Management solutions.
The procedure to install OEG is pretty straight-forward: create the folder on which you want the product to be installed and unzip the installation file there:
m@anakin:/oracle/$ mkdir oeg11.1.1.5 m@anakin:/oracle/$ cd oeg11.1.1.5 m@anakin:/oracle/oeg11.1.1.5$ unzip /tmp/ofm_oeg_linux_11.1.1.5.0_disk1_1of1.zip Archive: ofm_oeg_linux_11.1.1.5.0_disk1_1of1.zip creating: Linux/ creating: Linux/32bit/ inflating: Linux/32bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.i386.tar.gz inflating: Linux/32bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.i386_Policy_Center.tar.gz inflating: Linux/32bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.i386_Policy_Studio.tar.gz inflating: Linux/32bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.i386_Service_Explorer.tar.gz inflating: Linux/32bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.i386_Service_Monitor.tar.gz inflating: Linux/32bit/quickstart.txt inflating: Linux/32bit/readme.txt creating: Linux/64bit/ inflating: Linux/64bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64.tar.gz inflating: Linux/64bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Policy_Center.tar.gz inflating: Linux/64bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Policy_Studio.tar.gz inflating: Linux/64bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Service_Explorer.tar.gz inflating: Linux/64bit/Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Service_Monitor.tar.gz inflating: Linux/64bit/quickstart.txt inflating: Linux/64bit/readme.txt
This article uses the Linux 64-bit flavor, so we're going to unpack the files related to it:
m@anakin:/oracle/oeg11.1.1.5$ cd ./Linux/64bit/ m@anakin:/oracle/oeg11.1.1.5/Linux/64bit$ ls -h Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Policy_Center.tar.gz Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Policy_Studio.tar.gz Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Service_Explorer.tar.gz Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64_Service_Monitor.tar.gz Oracle_Enterprise_Gateway_11_1_1_5_0_Linux.x86_64.tar.gz quickstart.txt readme.txt m@anakin:/oracle/oeg11.1.1.5/Linux/64bit$ for a in `ls -1 *.tar.gz`; do tar -zxvf $a; done
The last command unpacks all modules at the current folder, creating a subfolder for each module. To check the final result:
m@anakin:/oracle/oeg11.1.1.5/Linux/64bit$ find -maxdepth 1 -type d
.
./oegpolicystudio
./oegpolicycenter
./oegservicemonitor
./oegserviceexplorer
./enterprisegateway
That's it, the installation is done.
Now, you'll need the following components of OEG running:
So, issue the respective commands from your terminal:
m@anakin:/oracle/oeg11.1.1.5/Linux/64bit$ ./enterprisegateway/posix/bin/enterprisegateway & m@anakin:/oracle/oeg11.1.1.5/Linux/64bit$ ./oegpolicystudio/policystudio & m@anakin:/oracle/oeg11.1.1.5/Linux/64bit$ ./oegserviceexplorer/serviceexplorer &
After issuing the commands, you can reach the Enterprise Gateway Administration interface accessing through a browser: http://localhost:8090/. You will be asked for username and password, which by default are admin/changeme respectively.
Oracle Service Bus virtualizes services in integration architecture, transforming complex and brittle architectures into agile integration networks by connecting, mediating, and managing interactions between service consumers and back end applications.
As previously mentioned, we're going to use a Bus domain with OWSM Extension and Enterprise Manager enabled:
If you haven't done it yet, start your Service Bus domain and log in to Service Bus Console (/sbconsole) to import the base project.


<cus:getCustomer xmlns:cus="http://customer.ws.examples.oracle.com/">
<arg0>1</arg0>
</cus:getCustomer>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> </soap:Header> <soapenv:Body> <cus:getCustomerResponse xmlns:cus="http://customer.ws.examples.oracle.com/"> <!--Optional:--> <return xmlns:cus="http://www.example.org/Customer"> <cus:id>1</cus:id> <cus:firstname>Customer1</cus:firstname> <cus:lastname>Lastname1</cus:lastname> <cus:address> <cus:street>One Streeth</cus:street> <cus:country>One Country</cus:country> <cus:city>One City</cus:city> </cus:address> </return> </cus:getCustomerResponse> </soapenv:Body> </soapenv:Envelope>
In this scenario, a company has an ongoing SOA approach, with several services already deployed and being used in production, with access restricted to internal consumers only, and there are no security requirements implemented.
The Weblogic instance on which OSB is running uses its default internal security provider (an embedded LDAP), since only basic administration console authentication/authorization is needed.
The Customer service we created above is one of the interfaces exposed by Oracle Service Bus. So, the basic access diagram is as follows:
![[FILENAME]](/ocom/groups/public/@otn/documents/digitalasset/1557061.png)
But now a new requirement has come up: some of these services must be exposed to our partners, using a standard Internet link. To be allowed to do so, the Security Officer requested that all external interfaces must implement some kind of access enforcement. And, since we're on the subject, there is also a demand that even internal interfaces must authenticate users. So our internal clients will have to change their calls accordingly. Since we're talking about system-to-system access inside an intranet, just ensuring that the caller is a "known system" is good enough for now. This characterizes a common scenario, usually called "system-to-system authentication," in which each system has security principles.
One last detail: upon receiving a request from a partner, authentication must carry out at the network perimeter in the DMZ, filtering out invalid requests. The user store we're going to query is segregated from the corporate store, in order to show how credential replacement is done. In real-world scenarios, usually the user store is unified.
To accomplish this, we're going to use Oracle Service Bus tight integration with OWSM (the default security solution for Oracle Fusion Middleware), with OEG acting as an external proxy for partner requests:

We will implement the business scenario via the following actions:
OEG can do a lot more than just authenticate a request, including filtering requests for known threats (e.g. Denial of Service, SQL injection, scan attachments for virus) and advanced routing. However, those features are beyond the scope of this article.
With this step we will register the OSB service on OEG, ensuring that the connectivity between OSB and OEG is working and exposing the service through OEG as well. We're not going to attach any security policies yet.
This section describes the basic steps to register a Web Service on OEG. For more information, please check the official documentation.
Assuming that both Service Bus and OEG are up and running as previously instructed, complete the following steps:

The left panel contains several items that represent the functionalities of OEG. At this point we only need to register a new Service in the Web Service Repository.



In the Services option in the left panel you should see the newly created CustomerService interface, under Default Services. Before testing it, we need to deploy the changes to the Enterprise Gateway server. This can be done by clicking the Deploy icon at the top right corner or by hitting F6 on your keyboard:

When the deploy process ends, access http://localhost:8080/Customer/CustomerService?WSDL from a web browser and confirm that the same WSDL we have on OSB is now exposed under OEG.
Now, let's test service we just exposed from OEG. To do so, we're going to use OEG's Service Explorer.
Service Explorer is a Web Services test client, which is used to generate test messages that are sent to the Enterprise Gateway and back to Service Explorer. Service Explorer supports both SOAP-based and REST-based invocations, includes support for multiple security scenarios (transport or message level), and is capable of generating stress tests and executing test cases scenarios.
To call the service, complete the following steps in Service Explorer:

<?xml version="1.0"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Header /> <env:Body> <cus:getCustomer xmlns:cus="http://customer.ws.examples.oracle.com/"> <arg0>1</arg0> </cus:getCustomer> </env:Body> </env:Envelope>


At this point we have a simple web service published in OSB and exposed through OEG with no security attached. The next steps will add it to both interfaces of the service – first the internal endpoint, exposed by Service Bus, then the public one, published by OEG.
Note: As an alternative, you can let Service Explorer create Request settings based on the WSDL. The process is described in the following steps:
Figure 15 - Service Explorer - Import WSDL

Oracle Web Services Manager allows the definition and storage of declarative policies to be applied to web services, enabling enforcement and monitoring of security, management and audit policies through configurable agents.
Web Services security has multiple facets (Authentication, Authorization, Confidentiality, Integrity), each with its own standards, which can be defined as service policies, or just plain policies. For this business scenario we will use a simple WS-Security Username/Token policy to enforce that only a user known by our system will be able to execute the service endpoint. In order to do that, we will use the default user from the Weblogic domain.
For more details about using different Realms or setting up LDAP or other Authentication Providers, please check the references at the end of this article.
In order to apply an OWSM policy to our CustomerService, execute the following steps in the OSB console:

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<wsse:Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
secext-1.0.xsd"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-
1.0.xsd">
<wsse:UsernameToken>
<Username>weblogic</Username>
<Password>welcome1</Password>
</wsse:UsernameToken>
</wsse:Security>
</env:Header>
<env:Body>
<cus:getCustomer xmlns:cus="http://customer.ws.examples.oracle.com/">
<arg0>1</arg0>
</cus:getCustomer>
</env:Body>
</env:Envelope>
[OSB Security - OWSM:387253]Failed to initialize Owsm Credential Manager. Please validate the Keystore Configuration....keep reading this section to setup an OWSM keystore.
The error message shown above indicates that you didn't set up the keystore for this OWSM/Weblogic domain. You can do this through the Java keytool command-line application, but we'd like to show you a very nice alternative, using OEG's Service Explorer to create a new keystore and a certificate. From this GUI you can open an existing keystore to check, add and change its entries.
Using Service Explorer, follow these steps:



Now we have a properly configured keystore, but we still have to set it up in Weblogic or, more precisely, in Web Services Manager's Security Provider. This keystore is used to store public and private keys for SOAP messages within the Weblogic domain.

After the server startup procedure ends, we have to create the credential to be used by the Service Bus Test Console to validate our configuration:
![[FILENAME]](/ocom/groups/public/@otn/documents/digitalasset/1557100.png)
Now that we have configured our keystore and credentials, login to sbconsole and test the CustomerService again with Service Bus Test Console. The payload is the same as before:
<?xml version="1.0"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Header /> <env:Body> <cus:getCustomer xmlns:cus="http://customer.ws.examples.oracle.com/"> <arg0>1</arg0> </cus:getCustomer> </env:Body> </env:Envelope>
Since we have already created the basic.credentials key, we don't need to pass any security information when using the Test Console – this is done automatically. As shown in Figure 24, the Security section references the key we just created by default.

The response will now display the expected business data.
Now we need to call our protected service on OSB from Service Explorer. Let's explore the tool and see how easy it is to add security tokens to service calls.


Now we're ready to go. Press the green arrow (execute) button and you will see the request output, authorized by Service Bus/OWSM, running on Weblogic.
Note: We're using the weblogic user for the sake of simplicity. In real world scenarios, please consider using an LDAP repository, a database, or Oracle Access Manager or a similar Identity Management product.
In the next section we will set up OEG to automatically add these authentication credentials to a service request using a Custom Policy. This strategy will allow OEG to call an OSB-protected endpoint.
The policy we created at OEG does not know that the WSDL exposed by Service Bus now requires a WS-Security token. Figure 27a, below, illustrates the WSDL exposed by Oracle Enterprise Gateway, while Figure 27b illustrates the WSDL exposed by Oracle Service Bus, and highlights the new WS-Security Policy.


So, we now need to update the service policy in order to send a user/password header on every request. This way, the calls going through OEG will work as expected.



Bring your Service Explorer up again, but this time try to execute without the security header - just remove the whole Header tag from the payload. Remember to modify the request endpoint to http://localhost:8080/Customer/CustomerService, since we changed it to call Service Bus directly in the previous section.
The service call will go through OEG and the policy will insert the user/password credentials required by Service Bus. Successfully authenticated to proceed, the service will execute the request.
So, at this point the service we have exposed on OWSM and OSB is checking for credentials, and OEG is passing a fixed, systemic user. The last thing we have to do to fully implement the business scenario is to command OEG to ask for credentials, check them against an isolated user store, and if the validation goes right, remove the received credentials and follow the course we already coded (insert the internal credentials and call the service provider).
As previously mentioned, we adopted an OEG internal store to keep the scope of this article as simple as possible. In a real-world architecture, OEG can be integrated with different credential providers, such as Oracle Access Manager or an LDAP server, in order to provide a better solution which will provide authentication or authorization outside of your network in a secure perimeter (DMZ).
First, we're going to add a new user to OEG's local store:

Now, we have to update the OEG policy to perform the authentication against its internal user store:


Back in Service Explorer, if you try to execute the service as it is (pointing to OEG and without any security information), you should receive a fault:MessageBlocked error, as OEG now demands you to pass a valid credential set:
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header />
<env:Body>
<env:Fault>
<env:Code>
<env:Value>env:Receiver</env:Value>
<env:Subcode>
<env:Value xmlns:fault="http://www.vordel.com/soapfaults">
fault:MessageBlocked
</env:Value>
</env:Subcode>
</env:Code>
<env:Reason />
<env:Detail xmlns:fault="http://www.vordel.com/soapfaults"
fault:type="faultDetails" />
</env:Fault>
</env:Body>
</env:Envelope>
Now, insert a new user token by clicking on Security Tokens, selecting WS-Security Username and filling the fields as indicated below (the password is oracle):

Execute the request, and you will get the expected business response.
Note: The security header generated by Service Explorer contains a Created tag with a timestamp. This info is checked by OEG to ensure that the request is being made inside the period determined by the Validity Period we set (5 minutes). If you remove this tag or execute a request with an interval between the creation of the token and the actual call greater than 5 minutes, you will receive a fault:MessageBlocked SOAP fault, blocking a possible Replay Attack. For more details please check the references.
If you want to avoid the capture-replay threat (check the references section for details), you must combine the Nonce (Number Once) and SHA1 Digest features - this way, if someone sniffs your request and try to tamper it, OEG will not acknowledge the bogus request, protecting your environment.
With this, we complete the implementation of the proposed scenario.
Note: Oracle Enterprise Gateway has two main monitoring components, Traffic Monitor and Real Time monitoring, which can be accessed through the product's management interface (http://localhost:8090). Traffic Monitor provides a web-based message log of the HTTP and HTTPS traffic processed by OEG, very useful for troubleshooting. Real Time monitoring shows usage statistics and displays graphic information about request status, SLA breach messages, Remote hosts access, and more.


Oracle Service Bus and Oracle Web Services Manager are great solutions for Web Services security, but Oracle Enterprise Gateway takes it to the next level, offering unique functionalities and a more advanced approach to Web Services Policies development. Also, having Oracle Enterprise Gateway in a DMZ is a strategic decision that will block unauthorized access to your internal network (intranet) and get less traffic on Oracle Service Bus or any other back end service. In this article we explored simple solutions for security, but Enterprise Gateway also offers throttling, caching, SSL termination, SAML token replication, XML threat protection (SQL injection, virus checking), faster XML/XLST parsing, and more.
Together, Oracle Enterprise Gateway, Oracle Service Bus and Oracle Web Services Manager offer a complete suite for Web Services security, providing performance, scalability and interoperability with open standards.
William Markito Oliveira
is a Senior Technologist with the Oracle Platform Technology Solutions team in Brazil where he focuses in Middleware, SOA, and Java technologies. He also contributed to the official Java EE Tutorial, providing write-ups and code examples covering CDI, EJB 3.1 and JAX-RS. William has more than 10 years experience in Software Development, Consulting and Architecture.
Fabio Mazanatti
is a Principal Consultant with Oracle Consulting Brazil, where he supports large-scale companies in their quest for SOA adoption. He has worked as consultant for over 20 years, covering a wide variety of technologies.