The steps below demonstrate how you can apply security to a proxy service via WSO2 EI Tooling.
Prerequisites
Step 1: Creating a registry resource project
First, create a registry resource project in ESB tooling. We will use this project to store the security policy (which is a registry resource).
Open the Developer Studio Dashboard (click Developer Studio > Open Dashboard) and click Registry Resources Project.
- Enter a name for the project and click Next.
- Enter the Maven information about the project and click Finish.
- The new project will be listed in the project explorer as shown below.
Step 2: Creating the security policy file
Follow the instructions given below to create a WS-Policy resource in your registry project. This will be your security policy file.
- Right-click the registry resource project in the left navigation panel, click New, and then click Registry Resource. This will open the New Registry Resource window.
- Select the From existing template option as shown below and click Next.
- Enter a resource name and select the WS-Policy template along with the preferred registry path.
- Click Finish. The policy file is now listed in the project explorer as shown below
Double-click the policy file to open the file. Note that you get a Design View and Source View of the policy.
Let's use the Design View to enable the required security scenario. For example, enable the Sign and Encyrpt security scenario as shown below.
You can provide also provide encryption properties, signature properties, and advanced rampart configurations as shown below.
Specifying role-based access?
For certain scenarios, you can specify user roles. After you select the scenario, scroll to the right to see the User Roles button.
Either define the user roles inline or retrieve the user roles from the server.
Step 3: Add a proxy service
You can either create a new proxy service, or import an already created proxy service to your workspace.
Follow the steps given below.
- Open the Developer Studio Dashboard (Click Developer Studio -> Open Dashboard).
Click Proxy Service to open the New Proxy Service dialog. Let's import the proxy service you downloaded previously.
Click Import Poxy Service and Next. Enter values for the following fields:
Proxy Service Configuration File | Browse for the proxy service file that you downloaded previously. |
---|
Save in | The file you import should be saved in an ESB project in your Tooling workspace. To create a new ESB project: - Click Create New ESB Project.
- Select New ESB Config Project.
- Enter a project name. For example, enter 'ESB_Project' as the project name.
- Click Finish. The new ESB_Project is added to the Save in field.
|
---|
- Click Finish. You will now see a new ESB_Project folder (with the proxy service) in your project explorer.
Step 4: Add the security policy to the proxy service
You can now apply the security policy to the proxy service. Follow the steps given below.
- Double-click the proxy service on the project explorer to open the file.
- Select the Properties tab shown below and set the Security Enabled property to 'true'.
- Select the Browse icon for the Service Policies field. In the dialog box that opens, create a new record and click the Browse icon to open the Resource Key dialog as shown below.
- Click workspace, to add the security policy from the current workspace. You can select the path to the
sample_policy.
xml file that you created in the previous steps.
- Save the proxy service file.
Step 5: Deploying the proxy service in the ESB server
Once you have added the security policy to your proxy service as explained in the previous topics, you need to create a Composite Application project with a CAR file. You can then deploy the CAR file in the ESB server:
- Right-click the Project Explorer and click New > Project.
- From the window that opens, click Composite Application Project.
Give a name to the Composite Application project and select the projects that you need to group into your C-App from the list of available projects. You need to select the ESB project and the registry resource project, which contains the proxy service and security policy file respectively.
- Next, deploy the CAR file in the ESB server.
Step 6: Testing the secured proxy service
You can test the sign and encrypt security policy that is applied to the proxy service by following the steps given below. Let's start the back-end service (which is the SimpleStockQuoteService) and send messages using the SOAP UI. You can first send a message that is not encrypted to verify if the secured proxy service accepts the message. Then, apply encryption/decryption to the SOAP UI client and send messages to see how message encryption and decryption is facilitated by the secured proxy service.
1. Starting the back-end service
The SimpleStockQuoteService (back-end service) contains four operations:
getQuote
(in-out) - Generates a sample stock quote for a given symbol.getFullQuote
(in-out) - Generates a history of stock quotes for a symbol for a number of days.getMarketActivity
(in-out) - Returns stock quotes for a list of given symbols.placeOrder
(in-only) - Accepts a one way message for an order.
To build and deploy a back-end service in the Axis2 server:
- Open a command prompt (or a shell in Linux).
- Go to the
<EI_HOME>/samples/axis2Server/src/SimpleStockQuoteService
directory. Execute the 'ant' command.
To start the Axis2 server:
- Open a command prompt (or a shell in Linux) and go to the
<EI_HOME>/samples/axis2Server
directory. - Execute one of the following commands to start the axis2 server:
- On Windows:
axis2server.bat
- On Linux/Solaris:
./axis2server.sh
This starts the Axis2 server (with the deployed back-end service). The HTTP and HTTPS transports listen on ports 9000 and 9002 respectively.
2. Creating a SOAP UI project
- Download SOAP UI.
- Before starting the SOAP UI, apply the following changes.
- Download the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK 8 and extract the downloaded ZIP file.
- Copy the
local_policy.jar
file and US_export_policy.jar
file inside the extracted folder to the <JDK_HOME>/jre/lib/security
folder. - Download the
xmlsec-1.5.2.jar
file, and copy it to the <SOAP_HOME>/lib/
folder. Also, remove the existing xmlsec-1.4.5.jar
file.
- Start the SOAP UI.
Go to File > New SOAP Project to start creating a new SOAP project.
Enter the following values:
3. Sending a message (without encryption)
Let's send a message to the proxy service without encrypting the message.
Go to the SOAP request for the project.
- Click WS-Addressing relates setting as shown below.
Enter the following value:
Enter the following request and execute.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<soapenv:Header/>
<soapenv:Body>
<ser:getQuote>
<!--Optional:-->
<ser:request>
<!--Optional:-->
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soapenv:Body>
</soapenv:Envelope>
You will see the following in the output, which indicates that the message should be encrypted.
<soapenv:Body wsu:Id="Id-1384918051" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soapenv:Fault xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<faultcode>wsse:InvalidSecurity</faultcode>
<faultstring>Missing wsse:Security header in request</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
4. Configuring the SOAP UI for message encryption/decryption
Now, let's configure the SOAP UI so that the outgoing messages will be encrypted, and incoming messages will be decrypted. We will use the default wso2carbon.jks keystore file for the encryption and decryption of messages.
Adding keystore configurations
- Right-click the project and click Show Project View.
Go to WS-Security Configurations > Keystore tab and create a new record.
Then, enter the following details.
Source | Enter the path to the keystore that the SOAP UI will use for encypting and decrypting messages. Let's use the default keystore (wso2carbon.jks) that is shiped with your WSO2 product. The source path is as follows: <EI_HOME>/repository/resources/security/wso2carbon.jks . |
---|
Password | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Default Alias | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Alias Password | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Save the configurations.
Configuring outgoing message encryption
Now, let's configure the properties for outgoing messages.
- Go to WS-Security Configurations > Outgoing WS-Security Configurations tab.
Create a new record and enter a name for the outgoung configuration. For example, enter 'outgoing_configs'
Then, enter the following details:
Default Username | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Default Password | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Must Understand | Select this check box. |
---|
- Next, we will add WSS entries for the outgoing configuration. Create a new record in the bottom panel of the Outgoing WS-Security Configurations tab. You can select the type of entry from the dialog box that opens.
Create three WSS entries as explained below.
Create an entry of type Timestamp, and specify the following parameter:
Create an entry of type Signature, and specify the following:
Keystore | Select 'wso2carbon.jks' from the list. |
---|
Alias | Select 'wso2carbon' from the list. This is the default password of the wso2carbon.jks keystore file. |
---|
Password | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Key Identifier Type | Select 'X509 Certificate' from the list. |
---|
Use Single Certificate | Select this check box. |
---|
Parts | Create a new record and enter the following: |
---|
Create an entry of type Encryption, and specify the following:
Keystore | Select 'wso2carbon.jks' from the list. |
---|
Alias | Select 'wso2carbon' from the list. This is the default password of the wso2carbon.jks keystore file. |
---|
Password | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
Key Identifier Type | Select 'X509 Certificate' from the list. |
---|
Create Encrypted Key | Select this check box. |
---|
Parts | Create a new record and enter the following: |
---|
Save the configurations.
Now, let's configure the properties for incoming messages.
- Go to the WS-Security Configurations > Outgoing WS-Security Configurations tab.
Create new record and enter a name for the incoming configuration. For example, enter 'incoming_configs'.
Then, enter the following details:
Decrypt Keystore | Enter 'wso2carbon.jks'. |
---|
Signature Keystore | Enter 'wso2carbon.jks'. |
---|
Password | Enter 'wso2carbon'. This is the default password of the wso2carbon.jks keystore file. |
---|
- Save the configurations.
5. Testing message encryption
Let's send an encrypted message to the back-end service.
Go to the SOAP request for the project:
Click Auth (at the bottom of the screen) and select Add New Authorization.
Enter the following details:
Authorization | Basic |
---|
Pre-emptive auth | Select Use global preference. |
---|
Outgoing WSS | Select the outgoing configuration you created earlier: 'outgoing_configs' |
---|
Incoming WSS | leave this blank. |
---|
- Click WS-Addressing related setting as shown below.
Enter the following value:
Enter the following request and execute.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<soapenv:Header/>
<soapenv:Body>
<ser:getQuote>
<!--Optional:-->
<ser:request>
<!--Optional:-->
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soapenv:Body>
</soapenv:Envelope>
You will see the output shown below. The response sent from the ESB is encrypted.
<soapenv:Body wsu:Id="Id-1192123912" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<xenc:EncryptedData Id="EncDataId-12" Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Reference URI="#EncKeyId-0682F65EEB9824BB96152649580727415"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>9f7NHvCZDcppy6h8msnZGf47S1MpRE7YdsYgfuX7JCChlQLO00PtoD6qoxM68Pdp1UcCRWoUEqij
pzwmNOEiiYfp4n6dD6vrrALMP4NPy23PQZCAsG6wrENDQG0Tr2eBq2M5J35rL+uAHio3uLTd3bCo
Cy40P/mCCbQSdWVLtTPIkMneNr8DEaRbDygJ8UsZZWD3WGqDpL5ENVbuPzAW38bxX5dkCZMARdVK
R05WdPc6VexKAmdZh/r5/ZUds2zmj6KTfb6vCt5dRp7kx+CTK6oGdFwCC51f+t4BiT7BBnELw/Vv
W15nFAkg7FQrQAlhbuwAhxeumIyhKRwmVYzuwCy0jJBijQY9vCrAL4/1tjZVch37ErKxQTnCr7Zw
3Q9+E78DcwRZMl9GEq9fHNgUNZj3iZFQI3Mmewx2fi3qfIIMzMlgS7XS+nHpACHYiI06wa4veRkB
2qfzXFNYfMP4UZrfqqys/3XY2/z5QUDQS+DrmGsnbsRgmrjVs8mnKMmV0XqcKulCVS3ICr/2rYJ4
FfiaKJ0Z2TlsB2Q8kz0Y5aiFYxiE6Opqhi1o4CsUUzsdF6gIDJaOuMi1oXa8J2TPo1POwzd7gFyJ
yp6zFSWjihnr5Tnmor6w4ylsPft9ktWSBgxCY4HrWXa8XKRSNP0UHRaGqRWwVv+LseU0wJN0Ets1
4KbNL0YWEfuJkXRAdhzy9lY2SPDFPgevjN7AhTfpd8WrVC3et+/UiJhAk7ivc06tp2Pr+S2JIb/E
meajPPuLDmPHAeH8PiDRuu6693sj90mVrUn9xjaumPH8Hcvs0t8Zzj2mA62BYiu/E4pXC7kFwuW3
IsgaNqh3orRHqzo24kaA+xj/WmzV92oSfBsq3ZfIi4fTvgRmSzgWwqS2aMNkMetuTPLBRSaelmR2
yCXz2TARiNuNm9/F44C8P51AbGGZoTHT+MR0gwG1UnMErh2AZmA6vBrYgyHuqUeqnOf2jWyZgOUT
TuB3rbX+acMdu62iJL1/H2xOaGaqFe73RtVIDz+gsrntlg7bAbcr11g538tJHVLXBaR9vjeef/s+
9MI3RERPxk/N0ZVB12PcRkOEiTw/A2jzq2FQNyPofKiKLsmCxt0mTvL6tOExQz4bsJHpARrN/xZQ
WkNr0UhCHbZEheM1bAwtktvMr0hLqWGdDpa+Qc4ArvYgXHh0EP8LdXU=</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soapenv:Body>
6. Testing message decryption
Let's add the incoming message decryption configurations so that the encrypted response is decrypted.
Go to the same SOAP request for the project that you invoked previously.
Add the following to the Auth parameters.
Incoming WSS | Select the incoming configuration you created earlier: 'incoming_configs' |
---|
Execute the same request.
You will see the output shown below. The response is decrypted.
<soapenv:Body wsu:Id="Id-1431772327" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax21:change>-2.7365742496115466</ax21:change>
<ax21:earnings>-8.213251300512011</ax21:earnings>
<ax21:high>88.48726651174232</ax21:high>
<ax21:last>85.1003087966358</ax21:last>
<ax21:lastTradeTimestamp>Wed May 16 22:05:12 IST 2018</ax21:lastTradeTimestamp>
<ax21:low>87.51212833009488</ax21:low>
<ax21:marketCap>3.815294330622157E7</ax21:marketCap>
<ax21:name>IBM Company</ax21:name>
<ax21:open>87.32469564153132</ax21:open>
<ax21:peRatio>-19.818382705434033</ax21:peRatio>
<ax21:percentageChange>-2.9535759300931126</ax21:percentageChange>
<ax21:prevClose>92.6529168161685</ax21:prevClose>
<ax21:symbol>IBM</ax21:symbol>
<ax21:volume>19361</ax21:volume>
</ns:return>
</ns:getQuoteResponse>
</soapenv:Body>