You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2019/05/20 16:16:12 UTC

[sling-org-apache-sling-committer-cli] branch feature/SLING-8337 created (now 3709823)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to branch feature/SLING-8337
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git.


      at 3709823  SLING-8337 - Create sub-command to manage the Jira update when staging a release

This branch includes the following new commits:

     new 3709823  SLING-8337 - Create sub-command to manage the Jira update when staging a release

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-committer-cli] 01/01: SLING-8337 - Create sub-command to manage the Jira update when staging a release

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/SLING-8337
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git

commit 3709823fcfbf5b8bc76826d3cf31318b6a8c79a3
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon May 20 18:15:41 2019 +0200

    SLING-8337 - Create sub-command to manage the Jira update when staging a release
    
    Properly set preemptive authentication for creating Jira versions.
---
 .../sling/cli/impl/http/HttpClientFactory.java     | 29 +++++++++++++++++++---
 .../apache/sling/cli/impl/jira/VersionClient.java  |  3 ++-
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/cli/impl/http/HttpClientFactory.java b/src/main/java/org/apache/sling/cli/impl/http/HttpClientFactory.java
index f881594..fe2bf2f 100644
--- a/src/main/java/org/apache/sling/cli/impl/http/HttpClientFactory.java
+++ b/src/main/java/org/apache/sling/cli/impl/http/HttpClientFactory.java
@@ -16,8 +16,13 @@
  */
 package org.apache.sling.cli.impl.http;
 
+import org.apache.http.HttpHost;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.AuthCache;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
@@ -31,7 +36,7 @@ import org.osgi.service.component.annotations.Reference;
 @Component(service = HttpClientFactory.class)
 public class HttpClientFactory {
     
-    private static final String DEFAULT_JIRA_HOST = "jira.apache.org";
+    private static final String DEFAULT_JIRA_HOST = "issues.apache.org";
     private static final int DEFAULT_JIRA_PORT = 443;
     
     @Reference
@@ -49,6 +54,12 @@ public class HttpClientFactory {
 
     public CloseableHttpClient newClient() {
         
+        return HttpClients.custom()
+                .setDefaultCredentialsProvider(newCredentialsProvider())
+                .build();
+    }
+
+    private BasicCredentialsProvider newCredentialsProvider() {
         Credentials asf = credentialsService.getAsfCredentials();
         Credentials jira = credentialsService.getJiraCredentials();
         
@@ -59,9 +70,19 @@ public class HttpClientFactory {
                 new UsernamePasswordCredentials(asf.getUsername(), asf.getPassword()));
         credentialsProvider.setCredentials(new AuthScope(jiraHost, jiraPort), 
                 new UsernamePasswordCredentials(jira.getUsername(), jira.getPassword()));
+        return credentialsProvider;
+    }
+    
+    public HttpClientContext newPreemptiveAuthenticationContext() {
         
-        return HttpClients.custom()
-                .setDefaultCredentialsProvider(credentialsProvider)
-                .build();
+        AuthCache authCache = new BasicAuthCache();
+        authCache.put(new HttpHost(jiraHost, jiraPort, "https"), new BasicScheme());
+        
+        HttpClientContext ctx = HttpClientContext.create();
+        ctx.setAuthCache(authCache);
+        ctx.setCredentialsProvider(newCredentialsProvider());
+        
+        return ctx;
     }
+    
 }
diff --git a/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java b/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java
index 1c1938c..98778e6 100644
--- a/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java
+++ b/src/main/java/org/apache/sling/cli/impl/jira/VersionClient.java
@@ -132,6 +132,7 @@ public class VersionClient {
      * @throws IOException In case of any errors creating the version in Jira
      */
     public void create(String versionName) throws IOException {
+        
         StringWriter w = new StringWriter();
         try ( JsonWriter jw = new Gson().newJsonWriter(w) ) {
             jw.beginObject();
@@ -144,7 +145,7 @@ public class VersionClient {
         post.setEntity(new StringEntity(w.toString()));
 
         try (CloseableHttpClient client = httpClientFactory.newClient()) {
-            try (CloseableHttpResponse response = client.execute(post)) {
+            try (CloseableHttpResponse response = client.execute(post, httpClientFactory.newPreemptiveAuthenticationContext())) {
                 try (InputStream content = response.getEntity().getContent();
                         InputStreamReader reader = new InputStreamReader(content)) {