Commit d0eda87
authored
Handle unresolved Maven credential placeholders gracefully (#6845)
* Add failing tests for unresolved Maven credential placeholders
When Maven settings.xml uses ${env.MAVEN_USER} placeholders for server
credentials and those env vars are not set, the literal placeholder
string is sent as the username, causing 403 errors on artifact downloads.
These tests verify:
- Unresolved credential placeholders are nulled out by the Interpolator
- MavenArtifactDownloader falls back to anonymous on 403 with credentials
* Null out unresolved credential placeholders in MavenSettings
When Maven settings.xml uses ${env.MAVEN_USER} / ${env.MAVEN_PASSWORD}
placeholders and those env vars are not set, the PropertyPlaceholderHelper
preserves the literal "${env.FOO}" string. This was then sent as actual
credentials, causing 403 errors.
Now the Interpolator checks for remaining "${" in server credentials
after interpolation and nulls them out, so no auth header is sent and
the download proceeds anonymously — matching Apache Maven behavior.
Also adds @nullable to Server.username and Server.password since
credentials can genuinely be absent.
Fixes moderneinc/customer-requests#1928
* Add anonymous fallback to MavenArtifactDownloader
When credentials are applied and the server responds with a 4xx client
error, retry the download without authentication. This mirrors the
existing behavior in MavenPomDownloader.requestAsAuthenticatedOrAnonymous()
and matches how Apache Maven handles credential failures gracefully.
This is defense-in-depth alongside the Interpolator fix — it also
protects against other credential mismatch scenarios.
* Revert the changes to MavenSettings
* Slight polish
* Revert nullable fields
* Minimize changes
* Move down repository field as well
* Do not pass username/password containing `${`
* Expect exactly one unauthenticated request
* Minimize diff1 parent de4f1d9 commit d0eda87
2 files changed
Lines changed: 74 additions & 7 deletions
File tree
- rewrite-maven/src
- main/java/org/openrewrite/maven/utilities
- test/java/org/openrewrite/maven/utilities
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
140 | | - | |
141 | | - | |
142 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
143 | 150 | | |
144 | 151 | | |
145 | 152 | | |
| |||
Lines changed: 64 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 32 | + | |
30 | 33 | | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
129 | 189 | | |
0 commit comments