Thanks again, Tamás. It is comforting to know that my implementation was not far off.
From: Tamás Cservenák <ta...@cservenak.net> Date: Wednesday, June 5, 2024 at 3:38 AM To: Maven Users List <users@maven.apache.org> Subject: [EXTERNAL] Re: Re: Custom auth plugin/extension - how to? [You don't often get email from ta...@cservenak.net. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] Howdy, I'd do it as this: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgist.github.com%2Fcstamas%2F5c787875fc3196dbd200e3bd24692c98&data=05%7C02%7CDavid.Grieve%40microsoft.com%7Cc5e5dc98de28474fb72808dc85328934%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638531699300812986%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=GYJefX6wgOXA0SDH%2BuNpHqlYYq9hp26r6bfGRttFrf4%3D&reserved=0<https://gist.github.com/cstamas/5c787875fc3196dbd200e3bd24692c98> Facts: - make priority higher than than of HTTP - this makes sure your transport will be always asked before Http one - just delegate/reuse http transport, no need to reimplement anything (make it also a JSR330 component!) - in newInstance there is a check (copied from http transport) to ensure httpTransport will not throw, then do your thing, and call into httpTransport HTH T On Tue, Jun 4, 2024 at 8:34 PM David Grieve <david.gri...@microsoft.com.invalid> wrote: > Thank you for the hint, Tamás. > > The problem I’m trying to solve is that I want a custom Authentication for > a particular server. I do not want to re-implement HttpTransporter. Here > are the important bits of what I’ve come up with. > ---------------------------------- > public class MyTransporterFactory implements TransporterFactory { > > // copied from org.eclipse.aether.transport.http.HttpTransporterFactory > private static Map<String, ChecksumExtractor> > getManuallyCreatedExtractors() { > HashMap<String, ChecksumExtractor> map = new HashMap<>(); > map.put(Nexus2ChecksumExtractor.NAME, new > Nexus2ChecksumExtractor()); > map.put(XChecksumChecksumExtractor.NAME, new > XChecksumChecksumExtractor()); > return Collections.unmodifiableMap(map); > } > > // I’m not happy with this... > private final HttpTransporterFactory httpTransporterFactory = new > HttpTransporterFactory(getManuallyCreatedExtractors()); > > @Override > public Transporter newInstance(RepositorySystemSession session, > RemoteRepository repository) throws NoTransporterException { > > if (requiresSpecialAuth(repository)) { > repository = new RemoteRepository.Builder(repository) > .setAuthentication(new MyAuthentication(repository)) > .build(); > } > return httpTransporterFactory.newInstance(session, repository); > } > ---------------------------------- > > Then “MyAuthentication” does the right thing for the fill method. > > This approach is working for me, but I’d be interested to know if there is > a better way. I do not want to re-implement HttpTransport! > > > On 2024/06/03 20:25:48 Tamás Cservenák wrote: > > Howdy, > > > > What are you trying to do? You may go better if you implement custom > > (resolver) transport maybe? > > > > Thanks > > T > > > > On Mon, Jun 3, 2024, 22:22 David Grieve <da...@microsoft.com.inva > <mailto:da...@microsoft.com.inva>lid> > > wrote: > > > > > My questions are: Is this doable and, if so, how would one go about it? > > > > > > I’m trying to cobble together a plugin/extension that will either get > an > > > auth token for resolving an artifact before the artifact is resolved, > or > > > will get an auth token if the resolution returns a 401. > > > The plugin route happens too late in the execution, but I’ve found that > > > with an AbstractMavenLifecycleParticipant at least afterProjectsRead > gets > > > called before artifact resolution. However, I can’t seem to affect the > > > server password in a way that allows artifact resolution to succeed. > > > I’ve also tried overriding some default implementations, but I don’t > see > > > the extension getting invoked (I see that Maven is aware of the > extension, > > > but it doesn’t get used AFAICT). > > > > > > >