使用Apache CXF使用Java客户端使用WCF Web服务

时间:2015-03-03 12:17:19

标签: wcf cxf ws-security

我正在尝试使用 Java客户端中的以下web-config使用 WCF服务

<binding name="WSHttpBinding_ISampleService">

      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>

      <security mode="None">

        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>

        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>

      </security>
</binding>

使用Windows身份验证保护Web Service。

当我尝试使用 Apache CXF 生成的WSDL客户端存根来调用Web服务的方法时,我得到以下异常:

警告:{http://schemas.xmlsoap.org/ws/2005/02/trust/wsdl} SecurityTokenService的拦截器#{http://schemas.xmlsoap.org/ws/2005/02/trust/wsdl} RequestSecurityToken抛出异常,现在展开 org.apache.cxf.interceptor.Fault:没有带ID的消息&#34; kerberosLoginError&#34;在资源包中找到&#34; org / apache / xml / security / resource / xmlsecurity&#34;



引起:org.apache.wss4j.common.ext.WSSecurityException:没有带ID的消息&#34; kerberosLoginError &#34;在资源包中找到&#34; org / apache / xml / security / resource / xmlsecurity&#34; 原始异常是javax.security.auth.login.LoginException:无效的null输入:name     在org.apache.wss4j.common.spnego.SpnegoTokenContext.retrieveServiceTicket(SpnegoTokenContext.java:127)



引起:javax.security.auth.login.LoginException:无效的空输入:name     在javax.security.auth.login.LoginContext.init(LoginContext.java:238)

以下是我的Java客户端:

public class TestService {
public final static QName SERVICE = new QName("http://tempuri.org/", "SampleService");
public ISampleService port;
public Client client;

public void testAuthWithCXFOutInterceptor() {
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

    Map<String,Object> outProps = new HashMap<String,Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.USER, "testuser");
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());

    Interceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);
}

public void testAuthWithRequestCtxAttrs() {
    client.getRequestContext().put("ws-security.username.sct", "testuser");
    client.getRequestContext().put("ws-security.passsword.sct", "testpassword");
}

public void testBasicAuth() throws MalformedURLException {
    HTTPConduit http = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(32000);

    AuthorizationPolicy policy = new AuthorizationPolicy();
    policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_NEGOTIATE);
    policy.setUserName("testuser");
    policy.setPassword("testpassword");

    http.setClient(httpClientPolicy);
    http.setAuthorization(policy);

    port.getUsers();
}

public void testNTLMAuth() {
    jcifs.Config.setProperty("jcifs.smb.client.username", "testuser");
    jcifs.Config.setProperty("jcifs.smb.client.password", "testpassword");
    jcifs.Config.registerSmbURLHandler();

    HTTPConduit http = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(32000);

    http.setClient(httpClientPolicy);
    port.getUsers();
}

public void init()  throws MalformedURLException {
    URL wsdlURL = new URL("http://service_url/SampleService.svc?singleWsdl");

    Init.init();
    SampleService service = new SampleService(wsdlURL, SERVICE);
    port = ss.getWSHttpBindingINGMASTERS();

    client = ClientProxy.getClient(port);
}

public static void main(String args[]) throws MalformedURLException {

    TestService testing = new TestService();
    testing.init();
    testing.testAuthWithCXFOutInterceptor(); /* Method 1 */
    //testing.testAuthWithRequestCtxAttrs(); /* Method 2 */
    //testing.testBasicAuth(); /* Method 3 */
    //testing.testNTLMAuth(); /* MEthod 4 */
}
}

方法1和2产生与上述相同的例外。

想要了解如何从这里开始。

  1. 我的代码中是否缺少CXF方面的某些配置?我应该尝试方法3还是4?
  2. 我的网络配置文件丢失了什么吗?
  3. 为什么Java异常线程指向特定的kerberos auth模式?

0 个答案:

没有答案