あなたは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を\ META-INF \のCXF内容で\バス-extensions.txt:
org.example.AuthenticatorReplacer::false
は次にとして新たに作成したプロジェクトを追加CXF-codegenを-プラグインへの依存:
<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拡張メカニズムによって初期化され、私たちとデフォルトの認証に置き換えられています。
あなたは今日これで私の人生を保存しました。誰もが "ハック"なしで同じことを達成する方法を見つけ出すことができればうれしいですが、ちょっと動作します。 – membersound