Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ApacheCXF的Java客户端的WCF Web服务消费_Wcf_Cxf_Ws Security - Fatal编程技术网

使用ApacheCXF的Java客户端的WCF Web服务消费

使用ApacheCXF的Java客户端的WCF Web服务消费,wcf,cxf,ws-security,Wcf,Cxf,Ws Security,我正试图使用Java客户端的以下web配置使用WCF服务 <binding name="WSHttpBinding_ISampleService"> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/> <security mode="None"> <transport clientCredentialTy

我正试图使用Java客户端的以下web配置使用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>

Web服务使用Windows身份验证进行保护

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

警告:{}SecurityTokenService{}RequestSecurityToken的侦听器引发异常,正在解除 org.apache.cxf.interceptor.Fault:在资源包“org/apache/xml/security/resource/xmlsecurity”中未找到ID为“kerberoslogin”的消息
.
.
.
原因:org.apache.wss4j.common.ext.WSSecurityException:在资源包“org/apache/xml/security/resource/xmlsecurity”中找不到ID为“kerberoslogin”的消息 最初的异常是javax.security.auth.login.LoginException:无效的空输入:name 位于org.apache.wss4j.common.spnego.SpnegoTokenContext.retrieveServicePicket(SpnegoTokenContext.java:127)
.
.
.
原因:javax.security.auth.login.login异常:无效的null输入: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 */
}
}
公共类测试服务{
公共最终静态QName服务=新QName(“http://tempuri.org/“,“样本服务”);
公共服务港;
公共客户;
使用CxFoutinterceptor()的公共无效测试权限{
org.apache.cxf.endpoint.endpoint cxfEndpoint=client.getEndpoint();
Map outProps=new HashMap();
put(WSHandlerConstants.ACTION,WSHandlerConstants.USERNAME\u令牌);
put(wshandlerstants.USER,“testuser”);
outProps.put(WSHandlerConstants.PASSWORD_类型,WSConstants.PW_文本);
put(WSHandlerConstants.PW_CALLBACK_类,ClientPasswordCallback.CLASS.getName());
拦截器wssOut=新的WSS4JOutInterceptor(输出站);
cxfEndpoint.getOutiterCeptors().add(wssOut);
}
public void testAuthWithRequestCtxAttrs(){
client.getRequestContext().put(“ws-security.username.sct”,“testuser”);
client.getRequestContext().put(“ws-security.passsword.sct”、“testpassword”);
}
public void testBasicAuth()引发了错误的FormedUrlexception{
httpconductor http=(httpconductor)client.getconductor();
HTTPClientPolicy HTTPClientPolicy=新的HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(32000);
AuthorizationPolicy policy=新的AuthorizationPolicy();
policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_协商);
policy.setUserName(“testuser”);
policy.setPassword(“testpassword”);
http.setClient(httpClientPolicy);
http.setAuthorization(策略);
port.getUsers();
}
public void testNTLMAuth(){
jcifs.Config.setProperty(“jcifs.smb.client.username”、“testuser”);
jcifs.Config.setProperty(“jcifs.smb.client.password”、“testpassword”);
jcifs.Config.registerSmbURLHandler();
httpconductor http=(httpconductor)client.getconductor();
HTTPClientPolicy HTTPClientPolicy=新的HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(32000);
http.setClient(httpClientPolicy);
port.getUsers();
}
public void init()引发畸形的DurLexException{
URL wsdlURL=新URL(“http://service_url/SampleService.svc?singleWsdl");
Init.Init();
SampleService服务=新的SampleService(wsdlURL,服务);
port=ss.getWSHttpBindingMasters();
client=ClientProxy.getClient(端口);
}
publicstaticvoidmain(字符串args[])引发畸形的异常{
TestService testing=新的TestService();
testing.init();
testing.testAuthWithCXFOutInterceptor();/*方法1*/
//testing.testAuthWithRequestCtxAttrs();/*方法2*/
//testing.testBasicAuth();/*方法3*/
//testing.testNTLMAuth();/*方法4*/
}
}
方法1和2产生与前面提到的相同的异常

我想知道如何从这里开始

  • 我的代码中是否缺少CXF端的某些配置?我应该尝试方法3还是方法4
  • 我的web配置文件是否缺少任何内容
  • 为什么Java异常线程指向特定的kerberos身份验证模式