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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 0203ade  CAMEL-17458: Bearer Access Token authentication (#6696)
0203ade is described below

commit 0203ade5eac1c4c11bd88febf04bc7a22624692b
Author: Federico Mariani <[email protected]>
AuthorDate: Mon Jan 10 11:54:31 2022 +0100

    CAMEL-17458: Bearer Access Token authentication (#6696)
---
 .../resources/org/apache/camel/component/jira/jira.json |  4 ++--
 components/camel-jira/src/main/docs/jira-component.adoc |  9 ++++++++-
 .../apache/camel/component/jira/JiraConfiguration.java  |  2 +-
 .../org/apache/camel/component/jira/JiraEndpoint.java   |  7 +++++++
 .../component/jira/JiraComponentConfigurationTest.java  | 17 +++++++++++++++++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-jira/src/generated/resources/org/apache/camel/component/jira/jira.json
 
b/components/camel-jira/src/generated/resources/org/apache/camel/component/jira/jira.json
index 4712da9..7d8342d 100644
--- 
a/components/camel-jira/src/generated/resources/org/apache/camel/component/jira/jira.json
+++ 
b/components/camel-jira/src/generated/resources/org/apache/camel/component/jira/jira.json
@@ -28,7 +28,7 @@
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start 
Producer", "group": "producer", "label": "producer", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "Whether the producer 
should be started lazy (on the first message). By starting lazy you can use 
this to allow CamelContext and routes to startup in situations where a producer 
may otherwise fail during star [...]
     "autowiredEnabled": { "kind": "property", "displayName": "Autowired 
Enabled", "group": "advanced", "label": "advanced", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": true, "description": "Whether autowiring is 
enabled. This is used for automatic autowiring options (the option must be 
marked as autowired) by looking up in the registry to find if there is a single 
instance of matching type, which t [...]
     "configuration": { "kind": "property", "displayName": "Configuration", 
"group": "advanced", "label": "advanced", "required": false, "type": "object", 
"javaType": "org.apache.camel.component.jira.JiraConfiguration", "deprecated": 
false, "autowired": false, "secret": false, "description": "To use a shared 
base jira configuration." },
-    "accessToken": { "kind": "property", "displayName": "Access Token", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth only) The access token generated by the 
Jira server." },
+    "accessToken": { "kind": "property", "displayName": "Access Token", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth or Personal Access Token 
authentication) The access token generated by the Jira server." },
     "consumerKey": { "kind": "property", "displayName": "Consumer Key", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth only) The consumer key from Jira 
settings." },
     "password": { "kind": "property", "displayName": "Password", "group": 
"security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(Basic authentication only) The password to 
authenticate to the Jira server. Use only if username basic authentication is 
used." },
     "privateKey": { "kind": "property", "displayName": "Private Key", "group": 
"security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth only) The private key generated by the 
client to encrypt the conversation to the server." },
@@ -47,7 +47,7 @@
     "exceptionHandler": { "kind": "parameter", "displayName": "Exception 
Handler", "group": "consumer (advanced)", "label": "consumer,advanced", 
"required": false, "type": "object", "javaType": 
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", 
"deprecated": false, "autowired": false, "secret": false, "description": "To 
let the consumer use a custom ExceptionHandler. Notice if the option 
bridgeErrorHandler is enabled then this option is not in use. By default the 
con [...]
     "exchangePattern": { "kind": "parameter", "displayName": "Exchange 
Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", 
"required": false, "type": "object", "javaType": 
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", 
"InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets the exchange pattern when the consumer creates an 
exchange." },
     "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start 
Producer", "group": "producer", "label": "producer", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": false, "description": "Whether the producer 
should be started lazy (on the first message). By starting lazy you can use 
this to allow CamelContext and routes to startup in situations where a producer 
may otherwise fail during sta [...]
-    "accessToken": { "kind": "parameter", "displayName": "Access Token", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth only) The access token generated by the 
Jira server." },
+    "accessToken": { "kind": "parameter", "displayName": "Access Token", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth or Personal Access Token 
authentication) The access token generated by the Jira server." },
     "consumerKey": { "kind": "parameter", "displayName": "Consumer Key", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth only) The consumer key from Jira 
settings." },
     "password": { "kind": "parameter", "displayName": "Password", "group": 
"security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(Basic authentication only) The password to 
authenticate to the Jira server. Use only if username basic authentication is 
used." },
     "privateKey": { "kind": "parameter", "displayName": "Private Key", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "configurationClass": 
"org.apache.camel.component.jira.JiraConfiguration", "configurationField": 
"configuration", "description": "(OAuth only) The private key generated by the 
client to encrypt the conversation to the server." },
diff --git a/components/camel-jira/src/main/docs/jira-component.adoc 
b/components/camel-jira/src/main/docs/jira-component.adoc
index 99170c7..40619da 100644
--- a/components/camel-jira/src/main/docs/jira-component.adoc
+++ b/components/camel-jira/src/main/docs/jira-component.adoc
@@ -87,7 +87,7 @@ You can bind the `JiraRestClientFactory` with name 
*JiraRestClientFactory* in th
 
 == Authentication
 
-Camel-jira supports 
*https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/[Basic
 Authentication]* and 
*https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-oauth-authentication/[OAuth
 3 legged authentication]*.
+Camel-jira supports 
*https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/[Basic
 Authentication]*, 
*https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-oauth-authentication/[OAuth
 3 legged authentication]* and 
*https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html*.
 
 We recommend to use OAuth whenever possible, as it provides the best security 
for your users and system.
 
@@ -105,6 +105,13 @@ to generate the client private key, consumer key, 
verification code and access t
 * The consumer key, set in the Jira server settings.
 * An access token, generated by Jira server.
 
+=== Personal access token authentication requirements:
+
+Follow the tutorial in 
https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html
+to generate an access token bearer.
+
+* An access token
+
 == JQL:
 
 The JQL URI option is used by both consumer endpoints.  Theoretically,
diff --git 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraConfiguration.java
 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraConfiguration.java
index cc4df7f..c98d770 100644
--- 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraConfiguration.java
+++ 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraConfiguration.java
@@ -87,7 +87,7 @@ public class JiraConfiguration implements Cloneable {
     }
 
     /**
-     * (OAuth only) The access token generated by the Jira server.
+     * (OAuth or Personal Access Token authentication) The access token 
generated by the Jira server.
      */
     public void setAccessToken(String accessToken) {
         this.accessToken = accessToken;
diff --git 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
index aaa1398..b68d90a 100644
--- 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
+++ 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/JiraEndpoint.java
@@ -133,6 +133,13 @@ public class JiraEndpoint extends DefaultEndpoint {
                         LOG.debug("Connecting to JIRA with Basic 
authentication with username/password");
                         client = 
factory.createWithBasicHttpAuthentication(jiraServerUri, 
configuration.getUsername(),
                                 configuration.getPassword());
+                    } else if (configuration.getAccessToken() != null
+                            && configuration.getVerificationCode() == null
+                            && configuration.getPrivateKey() == null
+                            && configuration.getConsumerKey() == null) {
+                        client = factory.create(jiraServerUri, builder -> {
+                            builder.setHeader("Authorization", "Bearer " + 
configuration.getAccessToken());
+                        });
                     } else {
                         LOG.debug("Connecting to JIRA with OAuth 
authentication");
                         JiraOAuthAuthenticationHandler oAuthHandler = new 
JiraOAuthAuthenticationHandler(
diff --git 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/JiraComponentConfigurationTest.java
 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/JiraComponentConfigurationTest.java
index 89081d5..ab1c467 100644
--- 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/JiraComponentConfigurationTest.java
+++ 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/JiraComponentConfigurationTest.java
@@ -80,6 +80,23 @@ public class JiraComponentConfigurationTest extends 
CamelTestSupport {
     }
 
     @Test
+    public void createEndpointWithPersonalAccessTokenAuthentication() throws 
Exception {
+        JiraComponent component = new JiraComponent(context);
+        component.start();
+        String query = Joiner.on("&").join(
+                concat(JIRA_URL, JIRA_URL_VALUE),
+                concat(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
+        JiraEndpoint endpoint = (JiraEndpoint) 
component.createEndpoint("jira://updateIssue?" + query);
+
+        assertEquals("updateissue", endpoint.getType().name().toLowerCase());
+        assertEquals(JIRA_URL_VALUE, endpoint.getConfiguration().getJiraUrl());
+        assertEquals(null, endpoint.getConfiguration().getVerificationCode());
+        assertEquals(ACCESS_TOKEN_VALUE, 
endpoint.getConfiguration().getAccessToken());
+        assertEquals(null, endpoint.getConfiguration().getConsumerKey());
+        assertEquals(null, endpoint.getConfiguration().getPrivateKey());
+    }
+
+    @Test
     public void createWatchChangesEndpoint() throws Exception {
         JiraComponent component = new JiraComponent(context);
         component.start();

Reply via email to