Wednesday, March 16, 2016

Oracle API Gateway: Enable embedded JMS in OAG

I was working on one of the requirement in which we have to communicate third party application using JMS queues. We are using oracle application gateway as a inbound/outbound interface so all the communication done through OAG, so in this case we are using JMS configured on oracle application gateway. Well in this blog post I am not going to describe my usecase but I will describe the basic step required to enable JMS in oracle application gateway (OAG).

Scenario:

I am going to enable jms in OAG first. I will create two queues incoming and outgoing. OSB application put the data on to incoming queue then jms listener in oag listen this incoming queue and put the data on outgoing queue. Well I am just showing here how to create a api gateway policy for jms communication so I am not going to tell how to configure your osb application to put the data on incoming (I hope you all know how to configure that).

Steps require to enable JMS in OAG:

  • Enable Embedded Active MQ on OAG
  • Create JMS Service External Connection in OAG
  • Create Queue in OAG Embedded Active MQ
  • Create OAG outgoing policy
  • Create JMS listener in OAG
  • Configure Embedded Active MQ jms connection on osb server
  • Test application


Enable Embedded Active MQ on OAG
  • Open policystudio --> go to server setting --> Messaging --> Embedded Active MQ -> configure as below

  • Check the box Enable Embedded Active MQ Broker
  • Active MQ connection details.
    • Address - localhost
    • Port: 62626
    • username: weblogic
    • password: welcome1
  • Apply changes.

Create JMS Service External Connection in OAG

  • Expand External Connection --> JMS Service --> Add a JMS Service 
  • JMS service Connection Details
    • Name: Embedded OAG JMS Service
    • Provider url : tcp://localhost:62626
    • Initial Context Factory : org.apache.activemq.jndi.ActiveMQInitialContextFactory
    • Connection Factory : QueueConnectionFactory
    • Username : weblogic
    • Password : welcome1

  •   Click Ok. Deploy your configurations.
Create Queue in OAG Embedded Active MQ
  • open url : https://localhost:8090 in browser
  • Go to Messaging --> Queues --> Actions --> Create Queue
  • create two queues i.e. InQueue and OutQueue.


Create OAG outgoing policy
  • Under policies --> create a policy container name "JMS Policies"
  • Create policy i.e. "OAG Outgoing"
  • Drag and drop messaging system from the Routing menu (from right panel)
  • Configure as below:
  • Click Ok to create a policy.
Create JMS listener in OAG
  • In the left panel under Listeners --> right click on Oracle API Gateway --> Messaging --> JMS Session, select the jms session you have created before

  • Add JMS consumer inside this JMS listener.

  • Click ok and deploy.

Configure Embedded Active MQ jms connection on osb server

This step is not require if you are not using osb application to test, you can configure other applicatoin to put the data on the incoming queue so that OAG Policy will work. Well my configurations is like below: 


Test the application

Now test your application and check if you are getting the messages in outgoing queue as below : 







Oracle API Gateway: Binary file issue in file upload filter in OAG 12.1.2.3.0

I was working on the oracle api gateway policy and using the file upload filter to upload the file onto the  ftp server. But I was unable to upload the correct file i.e. whenever the binary file uploaded to the server it gets corrupted

Solution:

As recommended by oracle that you should apply the patch SP4 and its working fine then.

the patch number is 22805555

Oracle API Gateway: Role based authorization using oracle XE database

Role based authorization enables you to restrict service access to authorized users based on their assigned roles or groups. In this blog post I am going to show you how authorization could be achieved in oracle api gateway without using any ldap server but using oracle xe database for storing the roles or groups and requested URI.

Scenario:

Suppose we have four services as follows
  • http://www.codeconfuse.com/search/label/12c
  • http://www.codeconfuse.com/search/label/SOA
  • http://www.codeconfuse.com/search/label/OSB
  • http://www.codeconfuse.com/search/label/weblogic
now we want to authorize these service based on roles or groups.

Steps to enable authorization in OAG:
  • Create users in OAG
  • Create Groups in OAG
  • Create table in database
  • Create database connection in OAG
  • Create a Group Authorization policy
  • Create Role Based Policies in OAG
  • Create Http Listener in OAG
  • Test the service in browser

Create Users in OAG

Lets create 5 user to demonstrate the role based authorization. Five user needed because 4 user for each services and 1 user is authorize to access all the service
  • Open Policystudio -> left navigation expand users and groups -> select users -> Add new user name that user user12c and password as welcome1

  • Similarly create 4 other user with name usersoa, userosb, userweblogic and useradmin with password as welcome1


Create Groups in OAG

 we create four groups for example

Critical - can access 12c service url
High - can access SOA service url
Medium - can access OSB service url
Low - can access weblogic service url

  • Go to groups tab -> add new group name as Low and assign user userweblogic and useradmin to this group

  • Simlarly create 3 more groups with name as Critical, High and Medium
    • Assign user usersoa and useradmin to group High
    • Assign user userosb and useradmin to group Medium
    • Assign user user12c and useradmin to group Critical

Create table in database

  • Open Sqlplus -> create a table name URI with two columns Groups and URL

  • Insert the following data into the table URI
    • insert into URI value ('Critical','/12c');
    • insert into URI value ('High','/soa');
    • insert into URI value ('Medium','/osb');
    • insert into URI value ('Low','/weblogic');
    • Commit ;

Create database connection in OAG

  • Go to External Connection --> Database connection --> Add a database connection

  • Click Ok and finish the wizard
Create a Group Authorization policy

This policy is common policy which authorize user to access the service based on roles and groups

  • Go to Policies --> Add policy --> give name Group Authorization policy
  • Drag and drop HTTP Basic filter, configure as below 
  • set http basic as set as start
  • Drag and drop Retrieve from or write to database, configure as below

SELECT * FROM uri where url = ${http.request.path}
  • Go to Advance tab. and configure as below
  • Click OK.
  • Drag and Drop Scripting Language, configure as below 

Here what is happening is the db query executed in the previous step retuns the a groups and url, this data stored in the user attribute list as groups and url and it can be access as user.groups or user.url. After extracting the value of groups then it passed to userGroup attribute which is use in the next step to check the group membership. The code snippet is below:

function invoke(msg)         {           

java.lang.System.out.println("Message is " + msg.get("attribute.lookup.list"));
var userGroup = msg.get("user.groups");

java.lang.System.out.println("user group is " + userGroup );

msg.put("user.group", userGroup );

return true;       

 }
  • Drag and drop Check Group Memebership, configure as below 
  • Finally connect all the filters and it looks like below



Create Role Based Policies in OAG

This policy is created for each service URI and it reuse the Group Authorization Policy created above and finally connect to the url.

  • Add container in Policies and name Role Based Policies
  • Create 4 Policies
    • 12c Policy
    • SOA Policy
    • OSB Policy
    • Weblogic Policy

  • one by one configure each policies. Open Google policy --> drag and drop policy shortcut and select the Group Authorization Policy
  • Drag and drop Connect to URL filter and configure as below
  • Finally connect all the filter and it looks like below

  • Similarly configure for other policies.


Create Http Listener in OAG

  • Go to Listeners --> Oracle API Gateway --> Default Services --> Paths --> Click Add and select Relative Path, configure as below

  • Click OK
  • Similarly create for other 3 service url's
Test the service in browser

Now if your api gateway is configure with http port as 8080, so to access the above services from the api gateway is
  • http://localhost:8080/12c
  • http://localhost:8080/soa
  • http://localhost:8080/osb
  • http://localhost:8080/weblogic

Run the above url and it will prompt for the username and password. Pass the username and password you have created above and check the authorization is working or not.

Sunday, January 31, 2016

Oracle API Gateway : Getting started with FTPS server

In this blog post I going demonstrate how to create a FTPS server inside the Oracle API Gateway (OAG).

Below are the steps required to create FTPS server:

  • Generate SSL certificate for ftps server
  • Configure SSL certificate in OAG
  • Create ftps Incoming file policy
  • Create Password Authentication Policy
  • Create User in OAG
  • Configure ftps server in OAG
  • Test and verify ftps connection using client

Generate SSL certificate for ftps server

You need openssl to create ssl certificate. you can download the openssl from here : https://www.openssl.org/source/

Please follow below blog post to configure ssl certificate

http://www.codeconfuse.com/2016/01/how-to-generate-ssl-certificate-using.html

Configure SSL certificate in OAG

  • Open policy studio --> Go to Certificates and Keys --> Certificates --> Click on Create/Import



  • Import the certificate that you have created above, click on import certificate



  • Go to Private Key tab and import the private key

  • Click Ok and finish the certificate import wizard.

Create FTPS incoming file policy

This policy is used to handle the incoming file coming from the ftps client and this is required to create ftps server listener.
  • Under Policies --> Create container "File Transfer" --> Right click and Add Policy, give the name of the policy "FTPS Incoming"
  • Open the FTPS Incoming policy, from the right menu go to Routing --> drag n drop "Save to File" filter.


Note: For the demonstration purpose I am saving the file in local server, you can use other filters according to your usecases.

  • Open "Save to File" filter and configure as below
Create Password Authentication Policy

This policy required to authenticate the client using username and password.

  • Add new policy similary created for FTPS Incoming policy, give the name "Password Authentication"
  • Open the policy, from right menu go to Authentication --> drag n drop Attribute Authentication and configure as below

  • Click Finish.

Create a User in OAG
  • Go to Users and Groups --> Users --> Click on Add, add new user weblogic.


  • Click Ok.
Configure FTPS server in OAG
  • Go to Listeners --> Oracle API Gateway --> Right Click and selct "Add File Transfer Service"
  • Configure as shown below

  • Select Password Authentication policy and FTPS Incoming policy as shown in the picture above
  • Select the IA server Cert that you have created above.
  • The directory used above is default directory, you can change this directory by putting folder name like ${environment.VINSTDIR}/file-transfer/in/weblogic

Test FTPS server connection

You can use any client like Filezilla or WinScp to test the FTPS connection. 
Use the user weblogic that is created in Oracle API Gateway.

Reference
  • https://docs.oracle.com/cd/E39820_01/doc.11121/gateway_docs/content/general_file_transfer.html

Friday, January 29, 2016

java.lang.Error: Critical Error. Failed to write transaction file /osb/configfwk/core_wls_osb1/_xact_ctrl.ih

Sometimes when you deployed the osb project using /sbconsole you will get the following exception while activating the project i.e.


Cause: 

The possible reason for this exception is the disk is full

Solution:

Check the disk space using the follwoing command

df -h

if the disk is full, then empty the space by deleting the logs file.

Saturday, January 23, 2016

Oracle API Gateway 12c : Getting started with SFTP server

In this blog post I going demonstrate how to create a SFTP server inside the Oracle API Gateway (OAG).

Below are the steps required to create SFTP server:

  • Generate SSL certificate for sftp server
  • Configure SSL certificate in OAG
  • Create SFTP Incoming file policy
  • Create Password Authentication Policy
  • Create User in OAG
  • Configure SFTP server in OAG
  • Test and verify SFTP connection using client


Generate SSL certificate for sftp server

You need openssl to create ssl certificate. you can download the openssl from here : https://www.openssl.org/source/

Please follow below blog post to configure ssl certificate

http://www.codeconfuse.com/2016/01/how-to-generate-ssl-certificate-using.html

Configure SSL certificate in OAG

  • Open policy studio --> Go to Certificates and Keys --> Certificates --> Click on Create/Import



  • Import the certificate that you have created above, click on import certificate




  • Go to Private Key tab and import the private key

  • Click Ok and finish the certificate import wizard.

Create SFTP Incoming Policy

This policy is used to handle the incoming file coming from the sftp client and this is required to create sftp server listener.
  • Under Policies --> Create container "File Transfer" --> Right click and Add Policy, give the name of the policy "SFTP Incoming"
  • Open the SFTP Incoming policy, from the right menu go to Routing --> drag n drop "Save to File" filter.

Note: For the demonstration purpose I am saving the file in local server, you can use other filters according to your usecases.

  • Open "Save to File" filter and configure as below



Create Password Authentication Policy

This policy required to authenticate the client using username and password.

  • Add new policy similary created for SFTP Incoming policy, give the name "Password Authentication"
  • Open the policy, from right menu go to Authentication --> drag n drop Attribute Authentication and configure as below

  • Click Finish.

Create a User in OAG
  • Go to Users and Groups --> Users --> Click on Add, add new user weblogic.


  • Click Ok.

Configure SFTP server in OAG


  • Go to Listeners --> Oracle API Gateway --> Right Click and selct "Add File Transfer Service"
  • Configure as shown below


  • Select Password Authentication policy and SFTP Incoming policy as shown in the picture above
  • Select the IA server Cert that you have created above.
  • The directory used above is default directory, you can change this directory by putting folder name like ${environment.VINSTDIR}/file-transfer/in/weblogic

Test SFTP server connection

You can use any client like Filezilla or WinScp to test the SFTP connection. 
Use the user weblogic that is created in Oracle API Gateway.

Reference
  • https://docs.oracle.com/cd/E39820_01/doc.11121/gateway_docs/content/general_file_transfer.html


How to generate ssl certificate using openssl

This blog post is about how to create ssl certificate using openssl. you require openssl software to create certificate so you can download the openssl binaries from here
https://www.openssl.org/source/

Below are the steps required to create ssl certificate

  • Create Root CA Key
  • Create Root CA based on the CA Key
  • Create Subordinate certificate key
  • Create subordinate certificate request 
  • Signed the subordinate certificate with the Root CA


Create Root CA Key

genrsa -out ca.key 1024

This command create 1024-bit key with no password







genrsa -des3 -out ca.key 1024

This command generate 1024-bit key with password




Create Self Signed Root CA

req -new -x509 -days 730 -key ca.key -out ca.crt

ca.crt is root ca which is valid for 2 years.

Create subordinate certificate key

genrsa -out ia.key 1024

The key generated is 1024-bit with no password, you can create with password as created above for  Root CA.

Note: Size of the key should be same

Create subordinate certificate request

req -new -key ia.key -out ia.csr


Signed subordinate certificate with Root CA

x509 -req -days 365 -in ia.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out ia.crt



This is a signed certificate valid for 1 year and used for actual signing. so use the ia.crt as certificate and ia.key its private key.