Skip to content

Commit

Permalink
If MavenSettings specify http headers include those headers on HTTP r…
Browse files Browse the repository at this point in the history
…equests issued by MavenPomDownloader and MavenArtifactDownloader.
  • Loading branch information
sambsnyd committed Dec 2, 2023
1 parent 219eda9 commit d0704ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,15 @@ private MavenRepository applyAuthenticationToRepository(MavenRepository reposito
* Returns a request builder with Authorization header set if the provided repository specifies credentials
*/
private HttpSender.Request.Builder applyAuthenticationToRequest(MavenRepository repository, HttpSender.Request.Builder request) {
if(ctx.getSettings() != null && ctx.getSettings().getServers() != null) {
for (MavenSettings.Server server : ctx.getSettings().getServers().getServers()) {
if(server.getId().equals(repository.getId()) && server.getConfiguration() != null && server.getConfiguration().getHttpHeaders() != null) {
for (MavenSettings.HttpHeader header : server.getConfiguration().getHttpHeaders()) {
request.withHeader(header.getName(), header.getValue());
}
}
}
}
if (hasCredentials(repository)) {
return request.withBasicAuthentication(repository.getUsername(), repository.getPassword());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public Path downloadArtifact(ResolvedDependency dependency) {
private HttpSender.Request.Builder applyAuthentication(MavenRepository repository, HttpSender.Request.Builder request) {
MavenSettings.Server authInfo = serverIdToServer.get(repository.getId());
if (authInfo != null) {
if(authInfo.getConfiguration() != null && authInfo.getConfiguration().getHttpHeaders() != null) {
for (MavenSettings.HttpHeader header : authInfo.getConfiguration().getHttpHeaders()) {
request.withHeader(header.getName(), header.getValue());
}
}
return request.withBasicAuthentication(authInfo.getUsername(), authInfo.getPassword());
} else if (repository.getUsername() != null && repository.getPassword() != null) {
return request.withBasicAuthentication(repository.getUsername(), repository.getPassword());
Expand Down

0 comments on commit d0704ac

Please sign in to comment.