CAS Rest API Integration and Testing

Points To Remember

Step 1: Adding dependency in pom.xml

First thing that we need to do here is to add the CAS Rest Api dependencies to pom.xml so that we can get the related jars in the class path.
 <dependency>
     <groupId>org.jasig.cas</groupId>
     <artifactId>cas-server-integration-restlet</artifactId>
     <version>${cas.version}</version>
     <type>jar</type>
 </dependency>
Note : Here we are using CAS v4.0.0

Step 2: Mapping Servlet in web.xml

Now, we need to map the restlet servlet in the web.xml. For this copy the previously generated web.xml from the war file and add the following lines in the web.xml file. This will register the servlet and the url pattern with which this servlet can be accessed. Here we are using v1/* as the url mapping, you can customize it according to your use case.
  <servlet>
    <servlet-name>restlet</servlet-name>
    <servlet-class>org.restlet.ext.spring.RestletFrameworkServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 
  <servlet-mapping>
    <servlet-name>restlet</servlet-name>
    <url-pattern>/v1/*</url-pattern>
  </servlet-mapping>

Step 3 : Create war file

Create the war file using maven command
mvn clean package
This will create a war file, upload this war file on servlet container, tomcat for our case. Restart the tomcat server and launch the application.

Step 4 : Test our CAS rest application

  1. When you launch the application you will see the cas login screen. 
  2. Enter the username and password we created in the database in this blog (username = ekansh@ekiras.com, password = password).
  3. You will see the login success screen.
    CAS -  Login success screen
  4. Now, enter the url /cas/v1/tickets. You should see the following page.
    CAS - Rest api url = cas/vi/tickets/
    If you can see this page you are done configuring the CAS Rest API. 
You are seeing this page because this rest api, expects a POST method call and by hitting the url from browser we are giving a GET request.


No comments:

Powered by Blogger.