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

hboutemy pushed a commit to branch maven-atr-plugin
in repository https://gitbox.apache.org/repos/asf/maven-studies.git


The following commit(s) were added to refs/heads/maven-atr-plugin by this push:
     new a54425911 use settings for ATR auth
a54425911 is described below

commit a54425911e4b307b86046686a247e21274682fdb
Author: HervĂ© Boutemy <[email protected]>
AuthorDate: Sun Mar 15 16:25:12 2026 +0100

    use settings for ATR auth
---
 pom.xml                                            | 11 +++++
 src/it/apache-release-profile/pom.xml              |  2 -
 src/it/settings.xml                                |  7 +++
 .../apache/maven/plugins/atr/AbstractAtrMojo.java  | 54 +++++++++++++++++++---
 .../org/apache/maven/plugins/atr/AtrClient.java    | 14 +++---
 .../org/apache/maven/plugins/atr/UploadMojo.java   |  2 +-
 6 files changed, 73 insertions(+), 17 deletions(-)

diff --git a/pom.xml b/pom.xml
index 006989c43..c3dedb98f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,5 +65,16 @@ under the License.
       <artifactId>jackson-databind</artifactId>
       <version>2.18.2</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-settings</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-sec-dispatcher</artifactId>
+      <version>2.0</version>
+    </dependency>
   </dependencies>
 </project>
diff --git a/src/it/apache-release-profile/pom.xml 
b/src/it/apache-release-profile/pom.xml
index b2b17e929..f72f722e3 100644
--- a/src/it/apache-release-profile/pom.xml
+++ b/src/it/apache-release-profile/pom.xml
@@ -67,8 +67,6 @@ under the License.
                 </goals>
                 <configuration>
                   <dryRun>true</dryRun>
-                  <asfuid>asfuid</asfuid>
-                  <token>some-token</token>
                   <project>${project.artifactId}</project>
                   <version>${project.version}</version>
                   <files>
diff --git a/src/it/settings.xml b/src/it/settings.xml
index c48fb3095..10d4faa9b 100644
--- a/src/it/settings.xml
+++ b/src/it/settings.xml
@@ -18,6 +18,13 @@ specific language governing permissions and limitations
 under the License.
 -->
 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 
https://maven.apache.org/xsd/settings-1.0.0.xsd";>
+  <servers>
+    <server>
+      <id>apache.atr</id>
+      <username>dummy-asfuid</username>
+      <password>dummy-token</password>
+    </server>
+  </servers>
   <profiles>
     <profile>
       <id>it-repo</id>
diff --git a/src/main/java/org/apache/maven/plugins/atr/AbstractAtrMojo.java 
b/src/main/java/org/apache/maven/plugins/atr/AbstractAtrMojo.java
index a1a3c338c..5b89e5019 100644
--- a/src/main/java/org/apache/maven/plugins/atr/AbstractAtrMojo.java
+++ b/src/main/java/org/apache/maven/plugins/atr/AbstractAtrMojo.java
@@ -23,7 +23,13 @@ import java.net.URL;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecryptionResult;
 
 /**
  * Abstract base class for ATR Mojos.
@@ -51,16 +57,52 @@ public abstract class AbstractAtrMojo extends AbstractMojo {
     protected boolean dryRun;
 
     /**
-     * Personal Access Token (PAT) for ATR API authentication.
+     * Server ID from settings.xml containing ATR credentials.
+     * The server's username should be the ASF user ID, and the password 
should be the Personal Access Token (PAT).
      */
-    @Parameter(property = "atr.token", required = true)
-    protected String token;
+    @Parameter(property = "atr.serverId", defaultValue = "apache.atr")
+    protected String serverId;
 
     /**
-     * ASF user ID for ATR API authentication.
+     * Maven settings.
      */
-    @Parameter(property = "atr.asfuid", required = true)
-    protected String asfuid;
+    @Parameter(defaultValue = "${settings}", readonly = true, required = true)
+    protected Settings settings;
+
+    /**
+     * Settings decrypter component.
+     */
+    @Component
+    protected SettingsDecrypter settingsDecrypter;
+
+    /**
+     * Get and decrypt the server configuration.
+     *
+     * @return the decrypted server
+     * @throws MojoExecutionException if server cannot be found or decrypted
+     */
+    protected Server getServer() throws MojoExecutionException {
+        Server server = settings.getServer(serverId);
+        if (server == null) {
+            throw new MojoExecutionException("Server '" + serverId + "' not 
found in settings.xml. "
+                    + "Please configure it with your ASF user ID as username 
and PAT as password.");
+        }
+
+        DefaultSettingsDecryptionRequest request = new 
DefaultSettingsDecryptionRequest(server);
+        SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
+
+        if (!result.getProblems().isEmpty()) {
+            getLog().warn("Problems decrypting server credentials: " + 
result.getProblems());
+        }
+
+        server = result.getServer();
+        if (server.getUsername() == null || server.getPassword() == null) {
+            throw new MojoExecutionException("Server '" + serverId
+                    + "' must have username (ASF user ID) and password (PAT) 
configured in settings.xml.");
+        }
+
+        return server;
+    }
 
     @Override
     public final void execute() throws MojoExecutionException, 
MojoFailureException {
diff --git a/src/main/java/org/apache/maven/plugins/atr/AtrClient.java 
b/src/main/java/org/apache/maven/plugins/atr/AtrClient.java
index 44d6ea57c..59e1cb5af 100644
--- a/src/main/java/org/apache/maven/plugins/atr/AtrClient.java
+++ b/src/main/java/org/apache/maven/plugins/atr/AtrClient.java
@@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.settings.Server;
 
 /**
  * Client for interacting with the ATR (Apache Test Release) API.
@@ -41,8 +42,7 @@ import org.apache.maven.plugin.logging.Log;
 public class AtrClient {
 
     private final URL baseUrl;
-    private final String pat;
-    private final String asfuid;
+    private final Server server;
     private final Log log;
     private final ObjectMapper objectMapper;
     private String jwt;
@@ -51,14 +51,12 @@ public class AtrClient {
      * Create a new ATR client.
      *
      * @param baseUrl the base URL of the ATR server
-     * @param pat the Personal Access Token for authentication
-     * @param asfuid the ASF user ID
+     * @param server the Maven server configuration containing credentials
      * @param log the Maven logger
      */
-    public AtrClient(URL baseUrl, String pat, String asfuid, Log log) {
+    public AtrClient(URL baseUrl, Server server, Log log) {
         this.baseUrl = baseUrl;
-        this.pat = pat;
-        this.asfuid = asfuid;
+        this.server = server;
         this.log = log;
         this.objectMapper = new ObjectMapper();
     }
@@ -75,7 +73,7 @@ public class AtrClient {
 
         try {
             // Create JWT request
-            JwtCreateRequest request = new JwtCreateRequest(asfuid, pat);
+            JwtCreateRequest request = new 
JwtCreateRequest(server.getUsername(), server.getPassword());
 
             // Create connection
             URL jwtUrl = new URL(baseUrl, "api/jwt/create");
diff --git a/src/main/java/org/apache/maven/plugins/atr/UploadMojo.java 
b/src/main/java/org/apache/maven/plugins/atr/UploadMojo.java
index c091bac5c..225829011 100644
--- a/src/main/java/org/apache/maven/plugins/atr/UploadMojo.java
+++ b/src/main/java/org/apache/maven/plugins/atr/UploadMojo.java
@@ -97,7 +97,7 @@ public class UploadMojo extends AbstractAtrMojo {
                 (directory != null ? directory + "/" : "") + 
file.getFileName().toString();
 
         // Upload using ATR client
-        AtrClient client = new AtrClient(url, token, asfuid, getLog());
+        AtrClient client = new AtrClient(url, getServer(), getLog());
         String revisionNumber = client.uploadFile(project, version, target, 
file);
 
         getLog().info("Upload successful. Revision: " + revisionNumber);

Reply via email to