Points To Remember
- Please refer to blog How to set up CAS server with database.
- Now we are going to use the same authentication process through rest api and test it.
Step 1: Adding dependency in pom.xmlFirst 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>Note : Here we are using CAS v4.0.0
Step 2: Mapping Servlet in web.xmlNow, 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.
Step 3 : Create war fileCreate the war file using maven command
mvn clean packageThis 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
- When you launch the application you will see the cas login screen.
- Enter the username and password we created in the database in this blog (username = firstname.lastname@example.org, password = password).
- You will see the login success screen.
CAS - Login success screen
- Now, enter the url /cas/v1/tickets. You should see the following page.
CAS - Rest api url = cas/vi/tickets/
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.