开发者社区> 问答> 正文

请教这个web service使用了什么安全策略,调用它时怎样才能通过验证??报错

这是一个.Net Framework 4.0创建的Web Service,WSDL如下:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="PrinterService" targetNamespace="http://tempuri.org/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/"
                  xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
                  xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
                  xmlns:wsa10="http://www.w3.org/2005/08/addressing"
        >
    <wsp:Policy wsu:Id="WSHttpBinding_IPrinterService_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy>
                        <sp:ProtectionToken>
                            <wsp:Policy>
                                <sp:SecureConversationToken
                                        sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                    <wsp:Policy>
                                        <sp:RequireDerivedKeys/>
                                        <sp:BootstrapPolicy>
                                            <wsp:Policy>
                                                <sp:SignedParts>
                                                    <sp:Body/>
                                                    <sp:Header Name="To"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="From"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="FaultTo"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="ReplyTo"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="MessageID"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="RelatesTo"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="Action"
                                                               Namespace="http://www.w3.org/2005/08/addressing"/>
                                                </sp:SignedParts>
                                                <sp:EncryptedParts>
                                                    <sp:Body/>
                                                </sp:EncryptedParts>
                                                <sp:SymmetricBinding>
                                                    <wsp:Policy>
                                                        <sp:ProtectionToken>
                                                            <wsp:Policy>
                                                                <sp:SpnegoContextToken
                                                                        sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                                                    <wsp:Policy>
                                                                        <sp:RequireDerivedKeys/>
                                                                    </wsp:Policy>
                                                                </sp:SpnegoContextToken>
                                                            </wsp:Policy>
                                                        </sp:ProtectionToken>
                                                        <sp:AlgorithmSuite>
                                                            <wsp:Policy>
                                                                <sp:Basic256/>
                                                            </wsp:Policy>
                                                        </sp:AlgorithmSuite>
                                                        <sp:Layout>
                                                            <wsp:Policy>
                                                                <sp:Strict/>
                                                            </wsp:Policy>
                                                        </sp:Layout>
                                                        <sp:IncludeTimestamp/>
                                                        <sp:EncryptSignature/>
                                                        <sp:OnlySignEntireHeadersAndBody/>
                                                    </wsp:Policy>
                                                </sp:SymmetricBinding>
                                                <sp:Wss11>
                                                    <wsp:Policy/>
                                                </sp:Wss11>
                                                <sp:Trust10>
                                                    <wsp:Policy>
                                                        <sp:MustSupportIssuedTokens/>
                                                        <sp:RequireClientEntropy/>
                                                        <sp:RequireServerEntropy/>
                                                    </wsp:Policy>
                                                </sp:Trust10>
                                            </wsp:Policy>
                                        </sp:BootstrapPolicy>
                                    </wsp:Policy>
                                </sp:SecureConversationToken>
                            </wsp:Policy>
                        </sp:ProtectionToken>
                        <sp:AlgorithmSuite>
                            <wsp:Policy>
                                <sp:Basic256/>
                            </wsp:Policy>
                        </sp:AlgorithmSuite>
                        <sp:Layout>
                            <wsp:Policy>
                                <sp:Strict/>
                            </wsp:Policy>
                        </sp:Layout>
                        <sp:IncludeTimestamp/>
                        <sp:EncryptSignature/>
                        <sp:OnlySignEntireHeadersAndBody/>
                    </wsp:Policy>
                </sp:SymmetricBinding>
                <sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy/>
                </sp:Wss11>
                <sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy>
                        <sp:MustSupportIssuedTokens/>
                        <sp:RequireClientEntropy/>
                        <sp:RequireServerEntropy/>
                    </wsp:Policy>
                </sp:Trust10>
                <wsaw:UsingAddressing/>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsp:Policy wsu:Id="WSHttpBinding_IPrinterService_PrintFile_Input_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                </sp:SignedParts>
                <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                </sp:EncryptedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsp:Policy wsu:Id="WSHttpBinding_IPrinterService_PrintFile_output_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                </sp:SignedParts>
                <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                </sp:EncryptedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsp:Policy wsu:Id="WSHttpBinding_IPrinterService_Test_Input_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                </sp:SignedParts>
                <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                </sp:EncryptedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsp:Policy wsu:Id="WSHttpBinding_IPrinterService_Test_output_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                </sp:SignedParts>
                <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                </sp:EncryptedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsdl:types>
        <xsd:schema targetNamespace="http://tempuri.org/Imports">
            <xsd:import schemaLocation="http://192.168.1.203:8080/PrinterService?xsd=xsd0"
                        namespace="http://tempuri.org/"/>
            <xsd:import schemaLocation="http://192.168.1.203:8080/PrinterService?xsd=xsd1"
                        namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="IPrinterService_PrintFile_InputMessage">
        <wsdl:part name="parameters" element="tns:PrintFile"/>
    </wsdl:message>
    <wsdl:message name="IPrinterService_PrintFile_OutputMessage">
        <wsdl:part name="parameters" element="tns:PrintFileResponse"/>
    </wsdl:message>
    <wsdl:message name="IPrinterService_Test_InputMessage">
        <wsdl:part name="parameters" element="tns:Test"/>
    </wsdl:message>
    <wsdl:message name="IPrinterService_Test_OutputMessage">
        <wsdl:part name="parameters" element="tns:TestResponse"/>
    </wsdl:message>
    <wsdl:portType name="IPrinterService">
        <wsdl:operation name="PrintFile">
            <wsdl:input wsaw:Action="http://tempuri.org/IPrinterService/PrintFile"
                        message="tns:IPrinterService_PrintFile_InputMessage"/>
            <wsdl:output wsaw:Action="http://tempuri.org/IPrinterService/PrintFileResponse"
                         message="tns:IPrinterService_PrintFile_OutputMessage"/>
        </wsdl:operation>
        <wsdl:operation name="Test">
            <wsdl:input wsaw:Action="http://tempuri.org/IPrinterService/Test"
                        message="tns:IPrinterService_Test_InputMessage"/>
            <wsdl:output wsaw:Action="http://tempuri.org/IPrinterService/TestResponse"
                         message="tns:IPrinterService_Test_OutputMessage"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="WSHttpBinding_IPrinterService" type="tns:IPrinterService">
        <wsp:PolicyReference URI="#WSHttpBinding_IPrinterService_policy"/>
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="PrintFile">
            <soap12:operation soapAction="http://tempuri.org/IPrinterService/PrintFile" style="document"/>
            <wsdl:input>
                <wsp:PolicyReference URI="#WSHttpBinding_IPrinterService_PrintFile_Input_policy"/>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <wsp:PolicyReference URI="#WSHttpBinding_IPrinterService_PrintFile_output_policy"/>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="Test">
            <soap12:operation soapAction="http://tempuri.org/IPrinterService/Test" style="document"/>
            <wsdl:input>
                <wsp:PolicyReference URI="#WSHttpBinding_IPrinterService_Test_Input_policy"/>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <wsp:PolicyReference URI="#WSHttpBinding_IPrinterService_Test_output_policy"/>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="PrinterService">
        <wsdl:port name="WSHttpBinding_IPrinterService" binding="tns:WSHttpBinding_IPrinterService">
            <soap12:address location="http://192.168.1.203:8080/PrinterService"/>
            <wsa10:EndpointReference>
                <wsa10:Address>http://192.168.1.203:8080/PrinterService</wsa10:Address>
                <Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
                    <Upn>VWINSRV-203\Administrator</Upn>
                </Identity>
            </wsa10:EndpointReference>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

用cxf生成客戶端后,调用直接报错:

三月 16, 2013 6:29:35 下午 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
WARNING: Interceptor for {http://tempuri.org/}PrinterService#{http://tempuri.org/}Test has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: General security error (An error occurred in trying to obtain a TGT: 无效空输入: 名称)
	at org.apache.cxf.ws.security.policy.interceptors.SpnegoContextTokenOutInterceptor.issueToken(SpnegoContextTokenOutInterceptor.java:108)
	at org.apache.cxf.ws.security.policy.interceptors.SpnegoContextTokenOutInterceptor.handleMessage(SpnegoContextTokenOutInterceptor.java:65)
	at org.apache.cxf.ws.security.policy.interceptors.SpnegoContextTokenOutInterceptor.handleMessage(SpnegoContextTokenOutInterceptor.java:46)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:532)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
	at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:734)
	at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:614)
	at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:606)
	at org.apache.cxf.ws.security.policy.interceptors.SecureConversationOutInterceptor.issueToken(SecureConversationOutInterceptor.java:159)
	at org.apache.cxf.ws.security.policy.interceptors.SecureConversationOutInterceptor.handleMessage(SecureConversationOutInterceptor.java:69)
	at org.apache.cxf.ws.security.policy.interceptors.SecureConversationOutInterceptor.handleMessage(SecureConversationOutInterceptor.java:44)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:532)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:89)
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
	at sun.proxy.$Proxy37.test(Unknown Source)
	at PrintServiceTest.main(PrintServiceTest.java:26)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.apache.ws.security.WSSecurityException: General security error (An error occurred in trying to obtain a TGT: 无效空输入: 名称)
	at org.apache.ws.security.spnego.SpnegoTokenContext.retrieveServiceTicket(SpnegoTokenContext.java:75)
	at org.apache.cxf.ws.security.policy.interceptors.SpnegoContextTokenOutInterceptor.issueToken(SpnegoContextTokenOutInterceptor.java:106)
	... 27 more
Caused by: javax.security.auth.login.LoginException: 无效空输入: 名称
	at javax.security.auth.login.LoginContext.init(LoginContext.java:246)
	at javax.security.auth.login.LoginContext.<init>(LoginContext.java:349)
	at org.apache.ws.security.spnego.SpnegoTokenContext.retrieveServiceTicket(SpnegoTokenContext.java:66)
	... 28 more
用了最简单的调用方法,没设置任何属性:

        String wsdl = "http://192.168.1.203:8080/PrinterService?wsdl";
        PrinterService printerService = new PrinterService(new URL(wsdl));
        IPrinterService service = printerService.getWSHttpBindingIPrinterService();
        System.out.println(service.test("TEST"));

展开
收起
爱吃鱼的程序员 2020-06-22 21:13:09 582 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    靠,ctrl+enter直接提交了。。。还没写完呢

    我觉得应该是这个:

    http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport%28includingSSLsupport%29-SpnegoAuthentication%28Kerberos%29

    2020-06-22 21:13:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载