Skip to content
Advertisement

CAS: Invoking a webservice programmatically from within a servlet

I have two applications running on 2 different servers (one on tomcat and other on JBoss). Both these applications are connected to the same CAS server for authentication. Right now this CAS server also resides within the same JBoss.

JavaScript

Now that I am invoking an url of App-1 from a browser. The CAS login page comes up and after username/password is provided, the request now successfully enters the servlet of App-1. From this servlet code, I am trying to invoke a webservice that resides inside App-2.

JavaScript

I could not make this webservice call work no matter what I do. Is there a way to achieve this?

JavaScript

Advertisement

Answer

This is possible by using the CAS Proxy feature. The link https://wiki.jasig.org/display/CAS/Proxy+CAS+Walkthrough helped a bit. But could not understand where to start with. First take the CAS client jar from http://downloads.jasig.org/cas-clients/ . In my case I took cas-client-core-3.3.3.jar jar. I have included this jar in my application war. In the web.xml of my application I have included the following 3 CAS Filters.

JavaScript

Note-1: The order of filter mapping should be as mentioned above. First CAS Validation filter mapping should come, followed by CAS Authentication Filter and last the CAS HttpServletRequest Wrapper filter.

Note-2: The URL pattern /ticket which is basically your proxy callback url need not be mentioned in the last two filters.

Once CAS client jar is included in the web-app and web.xml configured with these filters, then all the http requests go through these filters.

So once your http requests entered your servlet, then you can call the following code snippet to get a proxy ticket:

JavaScript

req is the HttpServletRequest Object and AttributePrincipal is a class which is present in the cas-client-core-3.3.3.jar

This proxyTicket can then be appended to your web-service’s URL as a query string like the following:

JavaScript

Once this URL is constructed, then you can make the web-service call programmatically.

Hope this helps.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement