Points To Remember

Program : Test CAS Rest Api from a Java Code

You can use the following piece of code to test the CAS Rest API.

You need to follow the following points for Authentication a user on CAS
  • You need to make a GET or POST call depending on your CAS server setup.
  • If the Username and Password are correct then you will get a TGT (Ticket Granting Token)
  • Now we will make a call to the service url of our application to get the Service Ticket.
  • On success you will get a Service Ticket
  • If you have service the Service Token,  then you have successfully authenticated the user.
  • Save this service ticket in a cookie or session, since a service ticket can be used only once

You will get the following type of response if everything is working fine.
string s = username=admin%40gmail.com&password=igdefault
Tgt is : TGT-3-eeSgMb35iv3TkqYzqekyhjZcGyNwKKq2s94reeoRINtdKJBvjx-ekansh
Service url is : service=http%3A%2F%2Fekansh%3A8090%2F
Response code is: 200
If the authentication fails at the server then you will get a response like the following
string s = username=ekansh%40ekiras.com&password=pwd
TGT - It is the token by the ticket granting token.
ST-3-Uagfse2pVB7hR5GL09WB-ekansh - It is the service token.