It's all about the answers!

Ask a question

Problems with Form Based Authentication in Java

Edwin Chan (3631) | asked Mar 03 '11, 4:01 p.m.
I want to use REST to query and update work items in RTC I looked at some guides to get a good concept of it:

I'm trying to use the discovery chain and I can get the catalog link successfully from rootservices. But to access the catalog, I would need to be authenticated, which is where I'm stuck.

I tried following this guide for form based authentication, but I'm not having any luck. Tomcat 5 is the application server.

I outputted my cookie store and I can see that it has a JSESSIONID and JazzFormAuth.

httpClient = new DefaultHttpClient();

CookieStore cookieStore = new BasicCookieStore();
localContext = new BasicHttpContext();
HttpGet httpGetID = new HttpGet("http://"+rtcHost+":"+rtcPort+"/jazz/authenticated/identity");
httpClient.execute(httpGetID, localContext);
List<NameValuePair> authFormParams = new ArrayList<NameValuePair>();
authFormParams.add(new BasicNameValuePair("j_username", rtcUsername));
authFormParams.add(new BasicNameValuePair("j_password", rtcPassword));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(authFormParams, "UTF-8");
HttpPost httpPostAuth = new HttpPost("http://"+rtcHost+":"+rtcPort+"/jazz/authenticated/j_security_check");
httpClient.execute(httpPostAuth, localContext);

HttpGet httpget = new HttpGet("http://"+rtcHost+":"+rtcPort+"/jazz/oslc/workitems/catalog");
httpget.setHeader("Accept", "text/xml");
HttpResponse response = httpClient.execute(httpget, localContext);

One answer

permanent link
Edwin Chan (3631) | answered Mar 04 '11, 10:31 a.m.

After authenticating (posting to j_security_check), you need hit another page (ex. identity) to receive the another cookie:

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.