Loading

401 Unauthorized Error when using Maven

Date de publication: May 10, 2024
Résolution

SYMPTOM

When executing the Maven command

mvn -Dusername=<username> -Dpassword=<password> mule:deploy

you get the following exception 

[ERROR] Failed to execute goal org.mule.tools.maven:mule-maven-plugin:2.2.1:deploy (default-cli) on project case-00170080-maven-deployment-v1.0-3.8.x: Execution default-cli of goal org.mule.tools.maven:mule-maven-plugin:2.2.1:deploy failed: 401 Unauthorized: Unauthorized -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mule.tools.maven:mule-maven-plugin:2.2.1:deploy (default-cli) on project case-00170080-maven-deployment-v1.0-3.8.x: Execution default-cli of goal org.mule.tools.maven:mule-maven-plugin:2.2.1:deploy failed: 401 Unauthorized: Unauthorized
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
Caused by: org.mule.tools.maven.plugin.mule.ApiException: 401 Unauthorized: Unauthorized
   at org.mule.tools.maven.plugin.mule.AbstractMuleApi.validateStatusSuccess(AbstractMuleApi.java:78)
   at org.mule.tools.maven.plugin.mule.AbstractMuleApi.getBearerToken(AbstractMuleApi.java:69)
   at org.mule.tools.maven.plugin.mule.AbstractMuleApi.init(AbstractMuleApi.java:60)
   at org.mule.tools.maven.plugin.mule.cloudhub.CloudhubDeployer.deploy(CloudhubDeployer.java:53) ...


CAUSE

Here are some common causes for this error:

  1. Incorrect password passed on argument -Dpassword or incorrectly configured in the pom XML file (<password> tag).
  2. Password passed on the -Dpassword argument contains the '$' character. Maven does not interpret correctly the '$' character in arguments passed from the command line - for example -Dpassword=test$ would be converted to test0.
  3. Incorrect host or region defined. 


SOLUTION

  1. When seeing this, it's advisable to first check that the password is correct. Simply use the same username/password to sign in against http://anypoint.mulesoft.com.
  2. Using the arguments -X -e with the Maven will help debug the command that you are using.
  3. Do not use the $ character as part of the password when entering the password from the command line or set the password in pom XML file (in <password> tag element) as this does not get wrongly converted.
  4. Kindly double-check the Anypoint host and region. 
  5. If your Anypoint Deployment uses External Identity or a Connected Applcation instead of a non-MFA user, you will have to check some extra configurations stated in the following article: Federated User Getting Unauthorized 401 While deploying Assets in Exchange
Numéro d’article de la base de connaissances

001118098

 
Chargement
Salesforce Help | Article