Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Rest Java Client: Why do I always get a “403 Forbidden” error

Eike May 3, 2020

Hi everyone,

I've been trying to connect to the Jira server (with basic auth) for several days now, but I can't get it to work. I always get a "403 Forbidden" error. In the meantime I am desperately despairing and hope that someone can help me.

The sample code looks like this:

public class Main
{
    private static final String JIRA_URL = "https://jira.mycompany.com/rest/api/latest/project/";
    private static String auth = new String(Base64.encode("admin" + ":" + "password"));
    private static String headerAuthorization = "Authorization";
    final static String headerAuthorizationValue = "Basic " + auth;
    final static String headerType = "application/json";


    public static void main(String[] args) throws Exception
    {
        Client client = Client.create();
        WebResource webResource = client.resource(JIRA_URL);

        ClientResponse response = webResource.header(headerAuthorization,headerAuthorizationValue).type(headerType).accept("application/json").get(ClientResponse.class);

        int statusCode = response.getStatus();
        if (statusCode == 401) {
            throw new AuthenticationException("401 Invalid Username or Password");
            } else if (statusCode == 403) {
                throw new AuthenticationException("403 Forbidden");
                }
    }

}

As already written, I always get a 403 error. :( If I enter the URL in the browser, it works without problems, so I am absolutely at a loss. Can anyone see what I'm doing wrong? 

 

Browser:

Here you can see the browser request:

mSLSL.png

Header:

EasSi.png

It looks the same to me, but unfortunately I don't know many details in the header. Are there differences to my code?

 

Postman:

Additionally I tried to make a request with Postman. That works, too. Authorization type is also "Basic Auth".

YRXYb.png

As you can see I got a 200 status code and everything worked. In my opinion the request is identical to my code, isn't it?

Additionally I tried the code from Postman, but strangely enough I get the 403 error even with this code.

K7yTY.png

Does anyone have any ideas? I'm running out of things to think of what could be wrong because the browser and postman request is working but unfortunately not my code... :(

Many thanks in advance!

 

Best regards

Benni

0 answers

Suggest an answer

Log in or Sign up to answer