简体   繁体   中英

JIRA Integration

What are the authentication schemes available for integrating a third-party application with jira 4.3. Obviously, getting username and password from customer sounds absurd. Also, i get that oauth authentication is available only from version 5. Please let me know. Thanks.

PS. I'm not looking for developing a plugin or using rest version5. I'm just trying to pull data from jira using rest api version 4.4.1.

You can always just use one login (eg anonymous user) for connection with Jira behind the scenes without asking a user for a password. You can also allow user to create issues anonymously . Or setup projects for public browsing .

If it is local Jira(Installed on your system) you may call any Client API to pull data, by just providing url and encoded auth(with user name and password).

    String getUrl = applicationProperties.getjURL() + "/rest/api/1.0/XXX";
String jiraUser = applicationProperties.getJiraUser().trim();
String jiraPwd = applicationProperties.getJiraPassword().trim();
String auth = new String(Base64.encode(jiraUser + ":" + jiraPwd));

HttpGet get = new HttpGet(getUrl);
StringEntity postingString = new StringEntity(gson.toJson(descrptionBean));
            post.setEntity(postingString);
            post.setHeader("Authorization", "Basic " + auth);
            post.setHeader("Content-type", "application/json");
            HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient();
            HttpResponse response = httpClient.execute(get);

... but if it is SSL/https secure then you need to set system property with truststore, keystore, keyStorePassword, etc (in case if using Java as technology). You can use API JiraRestClientFactory to create a jira client as below.

public JiraRestClient getRestClient() {

    System.setProperty("javax.net.ssl.trustStore", Constants.KEYSTORE);
    System.setProperty("javax.net.ssl.keyStore", Constants.KEYSTORE);
    System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
    String trustStore = System.getProperty("javax.net.ssl.trustStore");
    System.setProperty("-Dlog4j.configuration", "log4j.properties");
    if (trustStore == null) {
        Constants.REPORT.info("javax.net.ssl.trustStore is not defined, Please generate \"KeyStore.jks\" of JIRA Instance");
    }
    final JiraRestClientFactory jiraRestClientFactory = new AsynchronousJiraRestClientFactory();
    final HttpClientOptions options = new HttpClientOptions();
    options.setConnectionTimeout(15, TimeUnit.MINUTES);
    options.setSocketTimeout(15, TimeUnit.MINUTES);
    options.setConnectionPoolTimeToLive(15, TimeUnit.MINUTES);
    options.setRequestPreparer(new Effect<Request>() {

        @Override
        public void apply(final Request request) {

            new BasicHttpAuthenticationHandler(applicationProperties.getJiraUser().trim(), applicationProperties.getJiraPassword().trim()).configure(request);
        }
    });
    try {
        URI serverUri = new URI(applicationProperties.getjURL().trim());
        defaultHttpClient = new DefaultHttpClient<>(new NoOpEventPublisher(), new RestClientApplicationProperties(serverUri), ThreadLocalContextManagers.noop(), options);
        return jiraRestClientFactory.create(serverUri, defaultHttpClient);
    } catch (Exception e) {
        String msg = "Terminating the application while connecting to RestClient : " + e.getMessage();
        Constants.REPORT.info("javax.net.ssl.trustStore is not defined, Please generate \"KeyStore.jks\" of JIRA Instance");
        Constants.REPORT.info(msg);
        Constants.ERROR.info(msg);
        Constants.ERROR.info(Level.SEVERE, e);
        System.exit(-1);
    }
    return null;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM