Since you mentioned CXF, I suppose you meant cxf-codegen-plugin. This is a bit of a hack, but it works.
HTTP authentication credentials can be provided using java.net.Authenticator. You just need to define its own authenticator class, which overrides the getPasswordAuthentication (..) method. Then it should be installed as the default authenticator. As far as I know, this cannot be done declaratively (for example, using environment properties) only programmatically using Authenticator.setDefault (..).
To call Authenticator.setDefault (..), I would use the CXF extension mechanism. Create a separate maven project with a similar class:
public class AuthenticatorReplacer { public AuthenticatorReplacer(Bus bus) { java.net.Authenticator.setDefault(new java.net.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("test", "test123" .toCharArray()); } }); } }
and the src \ main \ resources \ META-INF \ cxf \ bus-extensions.txt file with the contents:
org.example.AuthenticatorReplacer::false
Then add the newly created project to the cxf-codegen-plugin dependency:
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${project.version}</version> <dependencies> <dependency> <groupId>org.example</groupId> <artifactId>cxf-authenticator-replacer</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> ... </plugin>
Thus, the AuthenticatorReplacer is initialized by the CXF extension mechanism and replaces the default authenticator with ours.
Dawid pytel
source share