'How to call Jenkins REST API without passing credentials using Java in already logged-in Jenkins?

I have used Jenkins REST API URL to get build status using Java (JAR). It is working successfully by passing user name and password to the API URL. I created a job in Jenkins and using that JAR file to get build status. But, my question is that why should the credential be passed again to API URL as I already logged-in in Jenkins to access the job? The API URL should be accessible without credentials. How to achieve the same?



Solution 1:[1]

REST does not persist any session information:

Relevant session data is sent to the receiver by the client in such a way that every packet of information transferred can be understood in isolation, without context information from previous packets in the session.

From https://en.wikipedia.org/wiki/Representational_state_transfer#Statelessness

That means, you must send the credentials with every call by design.

You can have a look at the Java API Client for Jenkins, but it uses the REST API under the hood as well I assume: https://github.com/jenkinsci/java-client-api

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Meiswjn