Hi,

 

Thanks for your reply. I am able to get the CAS Ticket.

 

Manish Shah,


  _____  

From: Aksel Bruun [mailto:[email protected]] 
Sent: Wednesday, December 09, 2009 3:43 AM
To: [email protected]
Subject: Re: [cas-dev] CAS + Standalone authentication (using Java Swing
Client)

 

Here is a java example that im running for tests on a desktop client:

public static String getTGTFromCAS(String username, String password) throws
java.lang.Exception
    {
        String tgt = null;
        HttpsURLConnection hsu =
(HttpsURLConnection)openConn(CAS_TICKET_STORE);
        String s =   URLEncoder.encode("username","UTF-8") + "=" +
URLEncoder.encode(username,"UTF-8");
        s+="&" +URLEncoder.encode("password","UTF-8") + "=" +
URLEncoder.encode(password,"UTF-8");
 
            System.out.println(s);
            OutputStreamWriter out = new
OutputStreamWriter(hsu.getOutputStream());
            BufferedWriter bwr = new BufferedWriter(out);
            bwr.write(s);
            bwr.flush();
 
            tgt = hsu.getHeaderField("location");
            System.out.println( hsu.getResponseCode());
            if(tgt != null && hsu.getResponseCode() != 400)
            {
                System.out.println("Tgt is : " + tgt.substring(
tgt.lastIndexOf("/") +1));
                tgt = tgt.substring( tgt.lastIndexOf("/") +1);
                    
        }
        bwr.close();
        closeConn(hsu);    
        return tgt;
    }      
                
     
    
    public static String getSTFromCAS(String tgt, String serviceURL) throws
java.lang.Exception
    {
        String st = null;
        String s = URLEncoder.encode("service","utf-8") +"=" +
URLEncoder.encode(serviceURL,"utf-8");
        HttpsURLConnection hsu =
(HttpsURLConnection)openConn(CAS_TICKET_STORE+ "/"+ tgt);
        System.out.println(s);
        OutputStreamWriter out = new
OutputStreamWriter(hsu.getOutputStream());
        BufferedWriter bwr = new BufferedWriter(out);
        bwr.write(s);
        bwr.flush();
        bwr.close();
        System.out.println("Response code is:  " + hsu.getResponseCode());

                BufferedReader isr = new BufferedReader(   new
                            InputStreamReader(hsu.getInputStream()));
        String line;
        System.out.println( hsu.getResponseCode());
        while ((line = isr.readLine()) != null) {
            System.out.println( line);
            if (line.substring(0, 2).equals("ST"))
            {
                st = line;
            }
        }
        isr.close();
        hsu.disconnect();
        return st;
    }

CAS_TICKET_STORE = "https://localhost:8443/cas/v1/tickets";;

After you get the service ticket you just add it as an url parameter.

Aksel.



2009/12/8 Marvin Addison <[email protected]>

> Can you please elaborate or mention some steps on how did you achieved
this

You may find http://www.ja-sig.org/wiki/display/CASUM/RESTful+API
helpful.  It contains python sample code that demonstrates usage.


M

--
You are currently subscribed to [email protected] as:
[email protected]
To unsubscribe, change settings or access archives, see
http://www.ja-sig.org/wiki/display/JSG/cas-dev

 

-- 


You are currently subscribed to [email protected] as:
[email protected]


To unsubscribe, change settings or access archives, see
http://www.ja-sig.org/wiki/display/JSG/cas-dev

-- 
You are currently subscribed to [email protected] as: 
[email protected]
To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-dev

Reply via email to