Showing posts with label Oracle Service Bus. Show all posts
Showing posts with label Oracle Service Bus. Show all posts

Thursday, January 22, 2015

Securing Oracle Service Bus (OSB) Proxy Services and Resources

It is a common requirement in enterprises that Only authorized external partners should be able to invoke your OSB/BPEL/Other web services. Others should not be able to access these services.

In this blog post, we will see how using the inbuilt functionality in OSB itself ( and without using any policies, wls9 or OWSM) we can secure OSB Proxy Services.

In gist, these are the steps that need to be done :

1.) Authentication : This step allows OSB to identify the subject ( the user or the client application) that is trying to access the proxy Service.
  Authenticating a user can be done in many ways, the aim however remains the same, establishing the identity of the user.
In this post, we will use simple http basic authentication to get this done.

2.) Authorization  : Create a set of rules in OSB that restrict access to this particular proxy service. These rules decide who gets to access these services and who does not.( You can create restrictions based on user, or group or role and a bunch of other stuff)

3.) Create the user or groups or roles necessary .
You would need to decide how many users and what users will be able to access this service.
The best way , IMO, is to create a group say an OSBAccessGroup and then work down from there, you can add sub-groups to it, directly put users in it and so on.


So, Let's get started !!!


1.) First, let's create the users and the groups required to access this ProxyService. This part is totally left up to how you want to structure your external users. Below is the way, I would generally do it:

a.) Create the following users in the weblogic console, these would represent external systems who would need access to your proxy service.
    I would recommend setting your users' name  in such  a way, that they can instantly be recognized .
    like CRM, SAP, 
b.) Create a group and put these users in that group, name that group something like 'ExternalSystems'
c.) Create another group, name it 'OSBAccessGroup' and put the group created above into this one.
      This will be the group I will give access to later by creating a rule in the sbconsole.
       I can add a single user to this group, I could add the whole administrator group to this one, whoever needs access goes into this group and I will not have to make any change to the OSB rules.

2.) In the configuration settings of your proxy service, turn the basic authentication to ON.


3.) On the security tab on the same page, go to the Access Control Section and click on the Transport Access Control link.





Here,you can decide, if you want to restrict access to a particular user, role or group.
We will select 'Group' here and move on.

d.) Now , we will type-in the group argument. This will be the name of the group we want to give access to. Type 'OSBAccessGroup' here ( or whatever group name you have chosen) and click on Add.


Click on OK, and move ahead.

You should see this page now.


Please note that you can combine conditions to create complex rules like : "Grant access to CRM from 6:00 AM to 6:00PM, and to SAP from 6:01 PM to 5:59 AM " !!!


Save all your work, activate your session changes and then go ahead and test it from any external client like SOAPUI!!

Friday, January 9, 2015

Invoking a RESTful webservice from OSB

For an introduction to REST and RESTful webservices, I recommend this great post on IBM DeveloperWorks.
http://www.ibm.com/developerworks/library/ws-restful/

In this post, we will see how we can invoke a web service based on REST from Oracle Service Bus.

We will be using the OpenWeather API, to get to know how REST invocations are simple,straight-forward yet effective and to know the weather in your city (or London), type this request in your browser:

http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml.

We are gonna invoke this WS from OSB !!


1.) Create a business service as per the configuration in the screenshot below.

Note that the endpoint URI is just http://api.openweathermap.org/data/2.5/weather  and the http request method is GET.


2.)  Test the above business service by providing the input for REST web service in query-parameters under transport header tab in the test console.






This is how you add URL query parameters to an outgoing http call from OSB test console  ( The part after ? in the http URL are the set of parameters, http://api.openweathermap.org/data/2.5/weather?q=London&mode=xml )

Test this business service, you would see a response similar to:

3.) Now we would need to create a Proxy Service over this Business Service and will use the input from the Proxy Service to populate the query parameters dynamically at run-time. 
Create a simple Any XML proxy service, I choose any XML because this is just a tutorial and using any XML would save me the time and effort to create an XSD/WSDL.

I will be using the below xml as an input request to this Proxy Service.

<WeatherInfoRequest>
<City></City>
</WeatherInfoRequest>

Please note how I have omitted the other parameter "Mode" that takes a value of xml. 
I do not believe this is something that an end user would be concerned with and hence it will be hardcoded later somewhere.

Next, Add a route node to this proxy service. Inside the route node, add a routing action that routes to the Business Service we had created earlier.

Inside the request actions, add an action to insert the query parameters into the outbound context variable.
Note how the value of parameter "q" has been dynamically picked from the incoming xml.
Also, I have hardcoded the other parameter "mode" as "xml" because I don't believe that a user would be inputing this as mentioned earlier.

and that is it , we are all set to go ahead and test this Proxy Service.

4.) Test this Proxy Service from the OSB Test Console using an appropriate input, London is one such appropriate city input.

and there you go !! London looks fairly cold at this time of the year !!

In my upcoming post, I will share , how we can achieve the same from Oracle SOA BPEL. 
We will also be learning how can we create RESTlike (note the change from RESTful :) ) services in OSB itself.


Thanks for Reading and enjoy the New Year !!