gnodet-bot commented on PR #14104:
URL: https://github.com/apache/maven/pull/14104#issuecomment-7127877446

   One interaction worth considering: the server aliases feature from #2333 and 
the credential scoping fix here may not compose correctly.
   
   **Scenario**: a user configures `central` as an alias on another server:
   
   ```xml
   <server>
     <id>my-publishing-server</id>
     <username>...</username>
     <password>...</password>
     <aliases>
       <alias>central</alias>
     </aliases>
   </server>
   ```
   
   The `SettingsBuilder` expands this into a virtual server with id `central`, 
so `request.getServers()` contains the right credentials. However, 
`addCentralPublishingOrigins` has this condition:
   
   ```java
   Set<String> origins = declaredOrigins.get(CENTRAL_ID);
   if (origins != null && origins.equals(Set.of(CENTRAL_ORIGIN))) {
       origins.addAll(CENTRAL_PUBLISHING_ORIGINS);
   }
   ```
   
   Since no repository or mirror carries the id `central` in this case, 
`declaredOrigins.get("central")` returns `null`, the condition never fires, and 
the publishing origins are never added. Under `strict` scope, the deploy would 
fail.
   
   **Suggested fix**: relax the condition to also cover the alias case 
(`origins == null`), but only when the default repository is present at its 
standard URL — to avoid activating for a fully custom `central` server. 
Something like:
   
   In `DefaultRepositorySystemSessionFactory`, track whether the default 
central repo was added at the standard origin, then pass a `boolean 
hasDefaultCentralRepo` flag to `addCentralPublishingOrigins`:
   
   ```java
   public static void addCentralPublishingOrigins(
           Map<String, Set<String>> declaredOrigins, boolean 
hasDefaultCentralRepo) {
       if (!hasDefaultCentralRepo) {
           return;
       }
       Set<String> origins = declaredOrigins.get(CENTRAL_ID);
       // Cover both cases:
       // - explicit <server id="central"> with default repo → origins == 
{repo.maven.apache.org}
       // - <aliases><alias>central</alias> without a declared repo → origins 
== null
       if (origins == null || origins.equals(Set.of(CENTRAL_ORIGIN))) {
           declaredOrigins.computeIfAbsent(CENTRAL_ID, k -> new HashSet<>())
                          .addAll(CENTRAL_PUBLISHING_ORIGINS);
       }
   }
   ```
   
   This keeps the existing guard (a mirror or `<repositoryOrigins>` giving 
`central` a non-standard origin takes over and nothing is added) while 
extending coverage to the alias case.
   
   _This comment was generated by an AI agent, Hermès on behalf of @gnodet._
   <!-- reviewer: gnodet-bot -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to