Sébastien Heilig created CAMEL-24495:
----------------------------------------

             Summary: Authentication-type detection is not triggered via 
camel-salesforce-maven-plugin. It still uses grant-type USERNAME_PASSWORD
                 Key: CAMEL-24495
                 URL: https://issues.apache.org/jira/browse/CAMEL-24495
             Project: Camel
          Issue Type: Bug
          Components: camel-salesforce
    Affects Versions: 4.22.0
            Reporter: Sébastien Heilig
             Fix For: Future


I am using camel-salesforce-maven-plugin to generate DTOs from salesforce for 
my customer. To do so, I was using grant_type=USERNAME_PASSWORD. It was working 
fine. In the Winter 27 update, that grant_type will be disabled.

 

It seems, on my sandbox, this is already the case. It was working fine up to 
last week. 

Thus, I wanted to switch to grant_type=CLIENT_CREDENTIALS.
By design, if no password (or empty password), the class 
org.apache.camel.component.salesforce.SalesforceLoginConfig seems to be able to 
determine the authenticationType via "getType" method.

However, using the camel-maven-salesforce-plugin, there is 2 issues:

 # The authenticationType is not a Parameter of 
[https://github.com/apache/camel/blob/main/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/AbstractSalesforceMojo.java]
 so this is not possible to override the grant_type
 # The SalesforceLoginConfig instanciated here : 
[https://github.com/apache/camel/blob/main/components/camel-salesforce/camel-salesforce-codegen/src/main/java/org/apache/camel/component/salesforce/codegen/AbstractSalesforceExecution.java]
 enforces the constructor using USERNAME_PASSWORD, ignoring the fact that 
password is empty and that I want to use the CLIENT_CREDENTIALS authentication. 
The auto-detection of the grant_type is bypassed.

 

*Step to reproduce*
 * Having a salesforce instances with a connectedApp
 * Using a client_id, client_secret, username and NO PASSWORD
 ** 
<camelSalesforce.password></camelSalesforce.password>
 ** If you don't put it, the maven plugin refuses to start mentioning that 
field is mandatory.
 * Configuring the camel-salesforce-maven-plugin with

 
{code:java}
 <plugin>
        <groupId>org.apache.camel.maven</groupId>
        <artifactId>camel-salesforce-maven-plugin</artifactId>
        <version>${camel-salesforce-maven-plugin.version}</version>
        <configuration>
          
<outputDirectory>${project.build.directory}/generated-sources/camel</outputDirectory>
          <packageName>com.my.company.dtos</packageName>
          <clientId>${camelSalesforce.clientId}</clientId>
          <clientSecret>${camelSalesforce.clientSecret}</clientSecret>
          <userName>${camelSalesforce.userName}</userName>
<!--          <password>${camelSalesforce.password}</password>-->
          <loginUrl 
default-value="https://login.salesforce.com";>${camelSalesforce.loginUrl}
          </loginUrl>
          <isHttpProxySecure>false</isHttpProxySecure>
          <includes>
            <include>Account</include>
          </includes>
          <version>63.0</version>
          <httpProxyHost>${camelSalesforce.httpProxyHost}</httpProxyHost>
          <httpProxyPort>${camelSalesforce.httpProxyPort}</httpProxyPort>
        </configuration>
        <executions>
          <execution>
            <id>generate-dtos</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              
<outputDirectory>${project.build.directory}/generated-sources/camel</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin> {code}

*Error you get*

{errors:[\{"errorCode":"invalid_grant","message":"Login error 
code:[invalid_grant] description:[authentication 
failure]","fields":null}],statusCode:400}

If you debug the plugin, you see the constructor of SalesforceLoginConfig 
called is the following:

 
{code:java}
public SalesforceLoginConfig(String loginUrl, String clientId, String 
clientSecret, String userName, String password,
                             boolean lazyLogin) {
    this(AuthenticationType.USERNAME_PASSWORD, loginUrl, clientId, 
clientSecret, null, userName, password, lazyLogin, null);
} {code}
And you see that the getType method is never used using the automatic detection.



 

*Expected fix*

The fix must use the empty constructor and uses the setter to override the 
parameter authenticationType in case this one is provided AND auto-detect that 
if password is missing (or empty), the grant_type should be auto-detected via 
the getType method and not forced to USERNAME_PASSWORD.

*Versions impacted*

I am using the version 4.22.0 but the previous versions (down to 4.18.x as far 
as I have checked) are also concerned.
 

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to