亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 WebLogic 中運行的 JAX-WS 客戶端中的 PasswordDigest 身份驗證失敗

在 WebLogic 中運行的 JAX-WS 客戶端中的 PasswordDigest 身份驗證失敗

滄海一幻覺 2022-01-19 10:27:53
我正在嘗試實現一個使用 PasswordDigest 身份驗證的 JAX-WS Web 服務客戶端。這是我的網絡服務客戶端:import java.io.ByteArrayInputStream;import java.io.IOException;import java.util.ArrayList;import java.util.List;import javax.annotation.PostConstruct;import javax.ejb.Stateless;import javax.xml.ws.Binding;import javax.xml.ws.BindingProvider;import javax.xml.ws.WebServiceRef;import javax.xml.ws.handler.Handler;import javax.xml.ws.soap.AddressingFeature;@Statelesspublic class JaxWsService {    /**     * We cache the web service client, but on a thread local variable to avoid any potential multi-threading     * issues.     */    private ThreadLocal<MyService> threadLocalClient = new ThreadLocal<MyService>();    @WebServiceRef(wsdlLocation = "http://localhost:9999/mockMyService?WSDL")    private MyServiceInterface service;    @PostConstruct    private void init() {      AddressingFeature feature = new AddressingFeature(true, false);      MyService proxy = service.getMyService(feature);      List<Handler> handlerChain = new ArrayList<Handler>();      //Add a handler to the handler chain      handlerChain.add( new PasswordDigestHeaderHandler() );      Binding binding = ( ( BindingProvider )proxy ).getBinding();      binding.setHandlerChain(handlerChain);      threadLocalClient.set(proxy);    }    public Response doSomething(String guid) {      MyService client = threadLocalClient.get();      return client.doSomething(guid);  }}..這些是我由 ClientGenTask 生成的 Web 服務工件:@WebServiceClient...public class MyServiceInterface    extends Service{...@WebService...@XmlSeeAlso({    ObjectFactory.class})public interface MyService {
查看完整描述

2 回答

?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

試試這個init()方法,你可能需要添加一個WebLogic憑證提供者:


private void init() {

    AddressingFeature feature = new AddressingFeature(true, false);

    MyService proxy = service.getMyService(feature);


    List<Handler> handlerChain = new ArrayList<>();

    // Add a handler to the handler chain

    handlerChain.add(new PasswordDigestHeaderHandler());


    BindingProvider bindingProvider = (BindingProvider) proxy;

    Binding binding = bindingProvider.getBinding();

    binding.setHandlerChain(handlerChain);


    // weblogic.xml.crypto.wss.provider.CredentialProvider

    // weblogic.wsee.security.unt.ClientUNTCredentialProvider

    List<CredentialProvider> credProviders = new ArrayList<>();

    credProviders.add(new ClientUNTCredentialProvider(USERNAME.getBytes(), PASSWORD.getBytes()));


    Map<String, Object> context = bindingProvider.getRequestContext();

    // weblogic.xml.crypto.wss.WSSecurityContext

    context.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);

    // weblogic.security.SSL.TrustManager

    context.put(

        WSSecurityContext.TRUST_MANAGER,

        new TrustManager() {

            public boolean certificateCallback(X509Certificate[] chain, int validateErr) {

                return true;

            }

        }

    );


    threadLocalClient.set(proxy);

}


查看完整回答
反對 回復 2022-01-19
?
慕田峪9158850

TA貢獻1794條經驗 獲得超8個贊

試試這個。

  1. 下載描述您的服務的 WSDL 文件并通過注釋掉定義wsp:PolicyReference:的行來修改它。

http://img1.sycdn.imooc.com//61e7774b00016d7a16970158.jpg

將它放在一個文件夾中,該文件夾將包含在您的 jar/war/ear 文件中(例如 META-INF/wsdl)。


在您的 Web 服務客戶端中,更改您的 @WebServiceRef 注入以引用此本地/捆綁版本的 WSDL:


@WebServiceRef(wsdlLocation = "META-INF/wsdl/MyService.wsdl")

private MyServiceInterface service;

將您的客戶端初始化代碼修改為如下所示:


AddressingFeature feature = new AddressingFeature(true, false);

MyService proxy = service.getMyService(feature);

BindingProvider bindingProvider = (BindingProvider) proxy;


List<Handler> handlerChain = new ArrayList<Handler>();

//Add a handler to the handler chain

handlerChain.add( new PasswordDigestHeaderHandler() );

Binding binding = bindingProvider.getBinding();

binding.setHandlerChain(handlerChain);


// Add these two lines, to point to the remote service

Map<String, Object> context = bindingProvider.getRequestContext();

context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, REMOTE_SERVICE_ENDPOINT);


threadLocalClient.set(proxy);

... 其中 REMOTE_SERVICE_ENDPOINT 是您正在訪問的遠程 Web 服務的 URL。


那應該這樣做。您不必修改 PasswordDigestHeaderHandler 實現。


我在完全相同的問題上花了相當多的時間,但這個線程讓我走上了正確的道路:https ://community.oracle.com/thread/2485783 。


祝你好運。


查看完整回答
反對 回復 2022-01-19
  • 2 回答
  • 0 關注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號