It's all about the answers!

Ask a question

Replacement of cookie in java application for fetching artifact details in RDNG


KT PD (597) | asked Jan 13 '22, 3:36 a.m.

 Hi Team,


I am using RDNG version 6.0.6.1. I have created one java application using jdk 1.8
My aim is to fetch artifact details from RDNG project area through java application. I am able to do the same. 
I am using fresh cookie every time (need to pass as a value) for getting required output by running the java application.
If I don't give the cookie, it will show 401 unauthorized error.
To use hard coded cookie every time is not a feasible way
Can anyone suggest me the replacement of cookie?


Thanks

4 answers



permanent link
Ralph Schoon (63.1k33645) | answered Jan 13 '22, 7:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jan 13 '22, 7:08 a.m.

This question lacks the useful information and , I think, confuses most of the concepts.


The Java context is irrelevant. If you want to use Java to use the RDNG APIs, that is fine, the main point is you use some kind of HTTP client.

You do not give cookies. The server sends cookies back to the http client. Usually the cookies are collected and used in a session. Usually you do not have to do anything.

Some of the Jazz APIs require a JSESSIONID header to be sent, where the value of the header must be the value of the session cookie. This is a security measure to make sure that there is no way to capture the connection. This is part of the authentication and cookie handling and part of the API.

All this is pretty much language independent and you have to do the same stuff e.g. in JSON or whatever other language.

So, what cookie and what is really the question?


permanent link
KT PD (597) | answered Jan 14 '22, 1:39 a.m.

Thanks for the reply.


I have  created one java application in which  I have given reportable rest API URL to fetch the artifact details in DNG.
I sent  the URL "https://{URL}/rm/publish/rootservices". For establishing connection and authentication purpose I have used HttpURLConnection, setrequestproperty, DefaultTrustManager etc. and connection ,  authorization is working fine also able to get all rootservices to particular project.
When I am sending the URL for fetching the artifacts details through java application, it is showing 401 unauthorized error. But, when I pass the value of cookie (I taken it from Postman), it is fetching required information.
So, is there any way to avoid passing cookie every time?

Thanks


Comments
Ralph Schoon commented Jan 14 '22, 2:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

WHAT COOKIE DO YOU GET FROM POSTMAN? AND HOW DO YOU PASS IT? 


permanent link
KT PD (597) | answered Jan 16 '22, 11:56 p.m.

 Hi ,


I am passing the cookie as string like below
public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException {
java.lang.System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom());
        SSLContext.setDefault(ctx);
        
Scanner sc= new Scanner(System.in); 
System.out.print("Enter URL");
//String baseURL  =sc.next();
String username = "";
String password = "";
String cookie= "JAZZ_AUTH_TOKEN=01d59b144a494c8a9685368bf25834f3&sk3vNDA9I5cAdJV8uhO4aSbvjStm7sxOxYuE5O2SY; JSESSIONID=0000bSzxQj5OeTgTP26qiiJ8660:1476c6ca-32a5-40d5-8bfe-332f61798b87";


permanent link
Ralph Schoon (63.1k33645) | answered Jan 17 '22, 2:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 You have to perform a proper login operation and use the session handling of the HTTP client. That makes sure the cookies are handled appropriately. See https://rsjazz.wordpress.com/2021/10/15/elm-authentication/

Your answer


Register or to post your answer.