在 WebLogic 中运行的 JAX-WS 客户端中的 PasswordDigest 身份验证失败

我正在尝试实现一个使用 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;


@Stateless

public 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 {


沧海一幻觉
浏览 182回答 2
2回答

呼唤远方

试试这个init()方法,你可能需要添加一个WebLogic凭证提供者:private void init() {&nbsp; &nbsp; AddressingFeature feature = new AddressingFeature(true, false);&nbsp; &nbsp; MyService proxy = service.getMyService(feature);&nbsp; &nbsp; List<Handler> handlerChain = new ArrayList<>();&nbsp; &nbsp; // Add a handler to the handler chain&nbsp; &nbsp; handlerChain.add(new PasswordDigestHeaderHandler());&nbsp; &nbsp; BindingProvider bindingProvider = (BindingProvider) proxy;&nbsp; &nbsp; Binding binding = bindingProvider.getBinding();&nbsp; &nbsp; binding.setHandlerChain(handlerChain);&nbsp; &nbsp; // weblogic.xml.crypto.wss.provider.CredentialProvider&nbsp; &nbsp; // weblogic.wsee.security.unt.ClientUNTCredentialProvider&nbsp; &nbsp; List<CredentialProvider> credProviders = new ArrayList<>();&nbsp; &nbsp; credProviders.add(new ClientUNTCredentialProvider(USERNAME.getBytes(), PASSWORD.getBytes()));&nbsp; &nbsp; Map<String, Object> context = bindingProvider.getRequestContext();&nbsp; &nbsp; // weblogic.xml.crypto.wss.WSSecurityContext&nbsp; &nbsp; context.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);&nbsp; &nbsp; // weblogic.security.SSL.TrustManager&nbsp; &nbsp; context.put(&nbsp; &nbsp; &nbsp; &nbsp; WSSecurityContext.TRUST_MANAGER,&nbsp; &nbsp; &nbsp; &nbsp; new TrustManager() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public boolean certificateCallback(X509Certificate[] chain, int validateErr) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; );&nbsp; &nbsp; threadLocalClient.set(proxy);}

慕田峪9158850

试试这个。下载描述您的服务的 WSDL 文件并通过注释掉定义wsp:PolicyReference:的行来修改它。将它放在一个文件夹中,该文件夹将包含在您的 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 chainhandlerChain.add( new PasswordDigestHeaderHandler() );Binding binding = bindingProvider.getBinding();binding.setHandlerChain(handlerChain);// Add these two lines, to point to the remote serviceMap<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 。祝你好运。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java