Jira authentication with Java

Pumper1 December 22, 2017

Hi,

I try to create user using Java and REST API, but when i do it i have a 401 error. It is a user is not authenticated error. How i can authenticat with java and REST?

Maybe somebody have some code exfmple?

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2017

With Jersey Client

ClientResponse response;
String auth = new String(Base64.encode("username" + ":" + "password"));
final String headerAuthorization = "Authorization";
final String headerAuthorizationValue = "Basic " + auth;
final String headerType = "application/json";
Client client = Client.create();

WebResource webResource = client.resource("url");
response =  webResource.header(headerAuthorization, headerAuthorizationValue).type(headerType).accept(headerType).get(ClientResponse.class);
Pumper1 December 27, 2017

Thank you!

Sohail Anwar July 3, 2019

Most easiest way in java Thanks

Kanishk.Kejriwal January 13, 2020

what is the package of Base64

Adir D October 19, 2020

@Alexey Matveev 

It doesn't work for me :(

 

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I used this URL:

WebResource webResource = client.resource("https://deljira");
Nhac Tat Nguyen February 2, 2021

@Kanishk.Kejriwal you can use the Base64 class from these locations:

// From the Jersey Client dependency
import
com.sun.jersey.core.util.Base64;
String auth = new String(Base64.encode("username" + ":" + "password"));


// From Java
import java.util.Base64;
import java.nio.charset.StandardCharsets;

Abhishek Jaswal February 3, 2021

How to do it with OAUTH2.0 

as you are using  basic auth here for authentication

Nhac Tat Nguyen February 3, 2021
Abhishek Jaswal February 3, 2021

I am asking for JIRA software 

the way to do OAUTH2.0 authentication call is here: https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/

from this document I got to know how to authenticate using OAUTH2.0 But the thing is I have to put the Authorization code URI in Browser to get the auth code you can refer to this

video: https://www.youtube.com/watch?v=ayiGEctaky0&t=4s

timestamp: 2:48 onwards

then after that I can make the access token request with the help of that AUTH code

but what I want to know is , how can I do this AUTHORIZATION CALL  thing in POSTMAN

How can i do the Authorization call inside postman?????

Suggest an answer

Log in or Sign up to answer