使用用户名令牌保护axis2

时间:2014-01-24 10:29:01

标签: java web-services apache axis2 rampart

我尝试使用rampart在axis2中使用用户名令牌生成安全性。

String securityPolicyPath = "/WEB-INF/policy.xml";

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("/axis2-1.6.2/repository/", "/WEB-INF/conf/axis2.xml");

CalAddStub stub = new CalAddStub(ctx,"http://localhost:8090/RampartTest/services/CalAdd/");
ServiceClient sc = stub._getServiceClient();
sc.engageModule("rampart");

Options options = sc.getOptions();
options.setUserName("apache");
options.setPassword("password");
        options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,loadPolicy(securityPolicyPath));
Add_cal add = new Add_cal();
add.setX(6);
add.setY(9);
System.out.println("id = " + stub.add_cal(add).get_return());

但我得到了这个例外。

[INFO] Deploying Web service: version.aar - file:/C:/axis2-1.6.2/repository/services/version.aar
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/JaxenException
    at org.apache.rampart.handler.WSDoAllSender.processBasic(WSDoAllSender.java:108)
    at org.apache.rampart.handler.WSDoAllSender.processMessage(WSDoAllSender.java:72)
    at org.apache.rampart.handler.WSDoAllHandler.invoke(WSDoAllHandler.java:72)
    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)

1 个答案:

答案 0 :(得分:1)

您的类路径中需要Apache Jaxen依赖项。

请查看Rampart Project Dependencies官方页面上的 Rampart依赖关系树部分。