Java Axis2带城墙:未定义';安全策略命名空间不能为空。';资源属性
我按照“使用ApacheAxis2开发web服务”的示例创建web服务 我正在将axis 1.6.2与rampart 1.6.2一起使用,当我执行客户端时,我会得到下一个异常:Java Axis2带城墙:未定义';安全策略命名空间不能为空。';资源属性,java,web,service,axis2,rampart,Java,Web,Service,Axis2,Rampart,我按照“使用ApacheAxis2开发web服务”的示例创建web服务 我正在将axis 1.6.2与rampart 1.6.2一起使用,当我执行客户端时,我会得到下一个异常: Exception in thread "main" java.lang.RuntimeException: Undefined 'Security policy namespace cannot be null.' resource property at org.apache.rampart.RampartExcep
Exception in thread "main" java.lang.RuntimeException: Undefined 'Security policy namespace cannot be null.' resource property
at org.apache.rampart.RampartException.getMessage(RampartException.java:81)
at org.apache.rampart.RampartException.<init>(RampartException.java:41)
at org.apache.rampart.RampartException.<init>(RampartException.java:57)
at org.apache.rampart.RampartMessageData.setWSSecurityVersions(RampartMessageData.java:387)
at org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:261)
at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65)
at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:427)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.ttdev.secure.client.SecureServiceStub.concat(SecureServiceStub.java:188)
at com.ttdev.secure.client.SecureClient.main(SecureClient.java:51)
线程“main”java.lang.RuntimeException中的异常:未定义的“安全策略命名空间不能为null”。资源属性
位于org.apache.rampart.RampartException.getMessage(RampartException.java:81)
位于org.apache.rampart.RampartException。(RampartException.java:41)
位于org.apache.rampart.RampartException。(RampartException.java:57)
位于org.apache.rampart.RampartMessageData.setWSSecurityVersions(RampartMessageData.java:387)
位于org.apache.rampart.RampartMessageData。(RampartMessageData.java:261)
位于org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
位于org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65)
位于org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
位于org.apache.axis2.engine.Phase.invoke(Phase.java:313)
位于org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
位于org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:427)
位于org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
在org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)上
位于org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
位于com.ttdev.secure.client.SecureServiceStub.concat(SecureServiceStub.java:188)
位于com.ttdev.secure.client.SecureClient.main(SecureClient.java:51)
这是我的WSDL文件:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="SecureService" targetNamespace="http://ttdev.com/ss" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ttdev.com/ss" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsdl:types>
<xsd:schema targetNamespace="http://ttdev.com/ss" xmlns:xsd="http://www.w3.org /2001/XMLSchema">
<xsd:element name="concat">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="s1" type="xsd:string"/>
<xsd:element name="s2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="concatResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="r" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="concatResponse">
<wsdl:part name="parameters" element="tns:concatResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="concatRequest">
<wsdl:part name="parameters" element="tns:concat">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="SecureService">
<wsdl:operation name="concat">
<wsdl:input message="tns:concatRequest">
</wsdl:input>
<wsdl:output message="tns:concatResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SecureServiceSOAP" type="tns:SecureService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="concat">
<wsp:PolicyReference URI="#p1" wsdl:required="true"/>
<soap:operation soapAction="http://ttdev.com/ss/NewOperation"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SecureService">
<wsdl:port name="SecureServiceSOAP" binding="tns:SecureServiceSOAP">
<soap:address location="http://localhost:8081/axis2/services/SecureService"/>
</wsdl:port>
</wsdl:service>
<wsp:Policy wsu:Id="p1" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401- wss-wssecurity-utility-1.0.xsd">
<sp:AsymmetricBinding>
<wsp:Policy>
<sp:InitiatorToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken /AlwaysToRecipient">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
<sp:RecipientToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
<wsp:Policy>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:RecipientToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:TripleDesRsa15/>
</wsp:Policy>
</sp:AlgorithmSuite>
</wsp:Policy>
</sp:AsymmetricBinding>
<sp:Wss10>
<wsp:Policy>
<sp:MustSupportRefEmbeddedToken/>
<sp:MustSupportRefIssuerSerial/>
</wsp:Policy>
</sp:Wss10>
<sp:SignedParts>
<sp:Body/>
</sp:SignedParts>
</wsp:Policy>
</wsdl:definitions>
这是我的策略文件:
<?xml version="1.0" encoding="UTF-8"?>
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns="http://ws.apache.org/rampart/policy">
<RampartConfig>
<user>c1</user>
<passwordCallbackClass>
com.ttdev.secure.client.PasswordCallbackHandler
</passwordCallbackClass>
<signatureCrypto>
<crypto
provider="org.apache.ws.security.components.crypto.Merlin">
<property
name="org.apache.ws.security.crypto.merlin.keystore.type">
JKS
</property>
<property
name="org.apache.ws.security.crypto.merlin.file">
E:\\Temp\\OK_Axis2Development\\keys\\client.ks
</property>
<property
name="org.apache.ws.security.crypto.merlin.keystore.password">
client-ks-pass
</property>
</crypto>
</signatureCrypto>
</RampartConfig>
</wsp:Policy>
c1
com.ttdev.secure.client.PasswordCallbackHandler
JKS
E:\\Temp\\OK\u Axis2开发\\keys\\client.ks
客户ks通行证
这是我在这里的第一篇帖子,希望信息足够
根据这本书,在这一点上,如果我执行客户机,我应该会得到一个错误,因为有更多的配置来完成这个示例,但至少我应该看到通过tcp监视器发送到服务器的soap xml
我找不到答案,在这个网站上有其他的帖子有同样的问题,但他们没有回应
最后,这是客户端代码,我不知道确切的原因,但我想这是版本的问题
package com.ttdev.secure.client;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.PolicyInclude;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
public class SecureClient {
public static void main(String[] args) {
try {
ConfigurationContext ctx = ConfigurationContextFactory
.createConfigurationContextFromFileSystem(
"repository\\modules\\rampart-1.6.2.mar",
null);
SecureServiceStub stub = new SecureServiceStub(ctx,"http://localhost:9000/axis2/services/SecureService");
stub._getServiceClient().engageModule("rampart");
StAXOMBuilder builder = new StAXOMBuilder("rampart-config.xml");
OMElement configElement = builder.getDocumentElement();
Policy rampartConfig = PolicyEngine.getPolicy(configElement);
//stub._getServiceClient().getOptions().setProperty(RampartMessageData.KEY_RAMPART_POLICY, rampartConfig); <= NO LONGER USED
stub._getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_SERVICE_POLICY, rampartConfig);
//stub._getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.SERVICE_POLICY, rampartConfig); <= IT IS USED IN THE BOOK
//stub._getServiceClient().getAxisService().getPolicySubject().attachPolicy(rampartConfig); <= IT IS ANOTHER WAY TO ADD POLICIES IN THIS VERSION, TRY IT
// List it = (List)rampartConfig.getAlternatives().next();
// for (int i=0; i<it.size(); i++) {
// Assertion assertion = (Assertion)it.get(i);
// System.out.format("i: %s | type: %s | name: %s | namespace uri: %s", i, assertion.getClass().getName(), assertion.getName(), assertion.getName().getNamespaceURI());
// }
// System.out.println("\n");
//
//stub._getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.SERVICE_POLICY,rampartConfig);
//stub._getServiceClient().getAxisService().getPolicySubject().attachPolicy(rampartConfig);
String result = stub.concat("xyz", "111");
System.out.println(result);
} catch (AxisFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
}
package com.ttdev.secure.client;
导入java.io.FileNotFoundException;
导入java.rmi.RemoteException;
导入java.util.List;
导入javax.xml.stream.XMLStreamException;
导入org.apache.axiom.om.OMElement;
导入org.apache.axiom.om.impl.builder.statxombuilder;
导入org.apache.axis2.AxisFault;
导入org.apache.axis2.context.ConfigurationContext;
导入org.apache.axis2.context.ConfigurationContextFactory;
导入org.apache.axis2.description.policyclude;
导入org.apache.neethi.Assertion;
导入org.apache.neethi.Policy;
导入org.apache.neethi.PolicyEngine;
导入org.apache.rampart.RampartMessageData;
公共类安全客户端{
公共静态void main(字符串[]args){
试一试{
ConfigurationContext ctx=ConfigurationContextFactory
.createConfigurationContextFromFileSystem(
“存储库\\模块\\rampart-1.6.2.mar”,
无效);
SecureServiceStub存根=新的SecureServiceStub(ctx)http://localhost:9000/axis2/services/SecureService");
存根。_getServiceClient().engageModule(“rampart”);
StatxonBuilder builder=新的StatxonBuilder(“rampart config.xml”);
OmeElement configElement=builder.getDocumentElement();
策略rampartConfig=PolicyEngine.getPolicy(configElement);
//stub.\u getServiceClient().getOptions().setProperty(RampartMessageData.KEY\u RAMPART\u POLICY,rampartConfig);我在客户端出错:
我改变了这一行:
stub._getServiceClient().getOptions().setProperty(RampartMessageData.KEY_RAMPART_POLICY, rampartConfig);
通过这个:
stub.\u getServiceClient().getAxisService().getPolicyInclude().addPolicyElement(PolicyInclude.AXIS\u SERVICE\u POLICY,rampartConfig)
这个例子还不完整,但我需要先解决这个问题。在我的例子中,我使用soapui创建了一个ws-client来使用安全的web服务。
我使用了提供者提供的WSDL。
当生成我的类(和我的jar)时,一切都会执行,但当它到达附加策略的代码时,就会引发异常
我检查的最后一件事是wsdl,因为我的提供者对此非常小心……但令我惊讶的是,它遗漏了策略部分……这就是引发异常的原因
因此,我强烈建议检查wsdl是否包含策略部分
问候