REST: Authenticating

I'm having trouble using the REST web service because I don't know how to get programmatic authentication working.
Right now, I'm trying to post data to the authentication service but I'm doing something wrong.
String.Format("https://jazzserver:9443/jazz/secure/web/console/j_security_check?j_username={0}&j_password={1}", username, password);
That's what I've been trying, but the response is always an authentication failed error.
How do you authenticate against Jazz?
Right now, I'm trying to post data to the authentication service but I'm doing something wrong.
String.Format("https://jazzserver:9443/jazz/secure/web/console/j_security_check?j_username={0}&j_password={1}", username, password);
That's what I've been trying, but the response is always an authentication failed error.
How do you authenticate against Jazz?
15 answers

It's really complex to programmatic login, but I found a useful class you may refer to.
com.ibm.team.jfs.app.oauth.client.OAuthConsumerClientHelper
com.ibm.team.jfs.app.oauth.client.OAuthConsumerClientHelper
Hello all,
I've been trying to use a Java HttpClient to authenticate with my RTC server, and didn't manage do to so.
I tried it using Form and Basic authentication.
I tried to follow this example: http://jazz.net/forums/viewtopic.php?p=13797#13797 (of course, transforming to Java)
Does anyone have a snippet that shows in Java how to use the HttpClient to do the same as this example (in curl) posted in the
documentation of the "Resource Oriented Work Item API v2" ?
COOKIES=./cookies.txt
USER=username
PASSWORD=password
HOST="https://localhost:9443/jazz"
curl -k -c $COOKIES "$HOST/authenticated/identity"
curl -k -L -b $COOKIES -c $COOKIES -d j_username=$USER -d j_password=$PASSWORD "$HOST/authenticated/j_security_check"
# If this line returns the JSON representation of work item 1, authentication was successful
#curl -k -b $COOKIES "$HOST/oslc/workitems/1.json"
Many Thanks!
Leila Naslavsky

Hello all,
I've been trying to use a Java HttpClient to authenticate with my RTC server, and didn't manage do to so.
I tried it using Form and Basic authentication.
I tried to follow this example: http://jazz.net/forums/viewtopic.php?p=13797#13797 (of course, transforming to Java)
Does anyone have a snippet that shows in Java how to use the HttpClient to do the same as this example (in curl) posted in the
documentation of the "Resource Oriented Work Item API v2" ?
COOKIES=./cookies.txt
USER=username
PASSWORD=password
HOST="https://localhost:9443/jazz"
curl -k -c $COOKIES "$HOST/authenticated/identity"
curl -k -L -b $COOKIES -c $COOKIES -d j_username=$USER -d j_password=$PASSWORD "$HOST/authenticated/j_security_check"
# If this line returns the JSON representation of work item 1, authentication was successful
#curl -k -b $COOKIES "$HOST/oslc/workitems/1.json"
Many Thanks!
Leila Naslavsky
I've been trying to use a Java HttpClient to authenticate with my RTC server, and didn't manage do to so.
I tried it using Form and Basic authentication.
I tried to follow this example: http://jazz.net/forums/viewtopic.php?p=13797#13797 (of course, transforming to Java)
Does anyone have a snippet that shows in Java how to use the HttpClient to do the same as this example (in curl) posted in the
documentation of the "Resource Oriented Work Item API v2" ?
COOKIES=./cookies.txt
USER=username
PASSWORD=password
HOST="https://localhost:9443/jazz"
curl -k -c $COOKIES "$HOST/authenticated/identity"
curl -k -L -b $COOKIES -c $COOKIES -d j_username=$USER -d j_password=$PASSWORD "$HOST/authenticated/j_security_check"
# If this line returns the JSON representation of work item 1, authentication was successful
#curl -k -b $COOKIES "$HOST/oslc/workitems/1.json"
Many Thanks!
Leila Naslavsky

The additional step required if using Tomcat are documented here under "Configuring the authentication method":
http://jazz.net/library/techtip/75
-Rob
http://jazz.net/library/techtip/75
-Rob
Was there anything else you needed to do other than commenting out the form based config and uncommenting:
<login>
<auth>BASIC</auth>
<realm>Jazz</realm>
</login>
... in the /jazz/server/tomcat/webapps/jazz/WEB-INF/web.xml file? (note that full element names are just not appearing correctly in this forum but they are complete in the web.xml file)
Thanks,
-Rob
I followed this guide I found for a completely unrelated problem and finally managed to make authenticating easy:
http://www.ibm.com/developerworks/rational/library/08/1014_ramamoorthy/?S_TACT=105AGX15&S_CMP=LP
(Changes Login mode from FORM to BASIC). This seems to resolve the problems some users have where they are forced to login twice as well.
Then for each web request in c#:
req.PreAuthenticate = true;
req.Proxy.Credentials =
req.Credentials = new System.Net.NetworkCredential("username@work.com", "password123");

Was there anything else you needed to do other than commenting out the form based config and uncommenting:
... in the /jazz/server/tomcat/webapps/jazz/WEB-INF/web.xml file? (note that full element names are just not appearing correctly in this forum but they are complete in the web.xml file)
Thanks,
-Rob
<login>
<auth>BASIC</auth>
<realm>Jazz</realm>
</login>
... in the /jazz/server/tomcat/webapps/jazz/WEB-INF/web.xml file? (note that full element names are just not appearing correctly in this forum but they are complete in the web.xml file)
Thanks,
-Rob
I followed this guide I found for a completely unrelated problem and finally managed to make authenticating easy:
http://www.ibm.com/developerworks/rational/library/08/1014_ramamoorthy/?S_TACT=105AGX15&S_CMP=LP
(Changes Login mode from FORM to BASIC). This seems to resolve the problems some users have where they are forced to login twice as well.
Then for each web request in c#:
req.PreAuthenticate = true;
req.Proxy.Credentials =
req.Credentials = new System.Net.NetworkCredential("username@work.com", "password123");

For using Form Authentication add a user/password check to Derek code:
After this code
Add the check:
After this code
request = WebRequest.Create(new Uri(String.Format(JAZZ_AUTH, username, password))) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Referer = JAZZ_BASE;
request.CookieContainer = container;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Add the check:
if (response.Headers["X-com-ibm-team-repository-web-auth-msg"] != null
&& response.Headers["X-com-ibm-team-repository-web-auth-msg"] == "authfailed")
{
throw new System.Security.Authentication.AuthenticationException("Authentication Error");
}

I followed this guide I found for a completely unrelated problem and finally managed to make authenticating easy:
http://www.ibm.com/developerworks/rational/library/08/1014_ramamoorthy/?S_TACT=105AGX15&S_CMP=LP
(Changes Login mode from FORM to BASIC). This seems to resolve the problems some users have where they are forced to login twice as well.
Then for each web request in c#:
http://www.ibm.com/developerworks/rational/library/08/1014_ramamoorthy/?S_TACT=105AGX15&S_CMP=LP
(Changes Login mode from FORM to BASIC). This seems to resolve the problems some users have where they are forced to login twice as well.
Then for each web request in c#:
req.PreAuthenticate = true;
req.Proxy.Credentials =
req.Credentials = new System.Net.NetworkCredential("username@work.com", "password123");

This is working C# code to get a workitem from the rest service as a
string. It's ugly, but if anyone else wants to do the same thing
it'll get you started.
const string SERVICE_BASE =
"https://jazzhost:9443/jazz/service/com.ibm.team.workitem.service.internal.roa.IRestService/workitems/{0}";
const string JAZZ_BASE =
"https://jazzhost:9443/jazz/";
const string JAZZ_AUTH =
"https://jazzhost:9443/jazz/j_security_check?j_username={0}&j_password={1}";
const string JAZZ_HOST = "jazzhost";
Please keep in mind that (as
https://jazz.net/wiki/bin/view/Main/ResourceOrientedWorkItems states) this
API is temporary and will change considerably for the 2.0 release.
--
Regards,
Patrick
Jazz Work Item Team
Are there documentation on how this is changing for the 2.0 release?
Can authentication work consistently across different types of servers ?
Ying
page 1of 1 pagesof 2 pages