あなたがCXFに言及したので、cxf-codegen-pluginを意味していたと思います。ちょっとしたハックですが、うまくいきます。
HTTP 認証クレデンシャルは、java.net.Authenticator を使用して提供できます。getPasswordAuthentication(..) メソッドをオーバーライドする独自の Authenticator クラスを定義するだけで済みます。次に、デフォルトのオーセンティケーターとして設定する必要があります。私の知る限り、Authenticator.setDefault(..) を使用してプログラムでのみ宣言的に (たとえば、環境プロパティを使用して) 行うことはできません。
Authenticator.setDefault(..) を呼び出すには、CXF 拡張メカニズムを使用します。同様のクラスで別の Maven プロジェクトを作成します。
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());
}
});
}
}
およびファイル src\main\resources\META-INF\cxf\bus-extensions.txt の内容:
org.example.AuthenticatorReplacer::false
次に、新しく作成したプロジェクトを依存関係として cxf-codegen-plugin に追加します。
<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>
このように、AuthenticatorReplacer は CXF 拡張メカニズムによって初期化され、デフォルトの Authenticator を私たちのものに置き換えます。