简体   繁体   中英

Axis2/rampart cryptography problem with signaturePropFile

I have problem with WebService client that has to use WS-Security. My client is written with axis2 . It works when I do not enable cryptography (of course with my server emulator). I enabled cryptography by adding to axis.xml :

<!--Signature and Encryption : Using the request's certificate-->
<module ref="rampart" />

<parameter name="OutflowSecurity">
  <action>
    <items>Signature</items>
    <user>mn</user>
      <passwordCallbackClass>PWCallback</passwordCallbackClass>
      <signaturePropFile>client.properties</signaturePropFile>
    <signatureKeyIdentifier>SKIKeyIdentifier</signatureKeyIdentifier>
    <signatureParts>{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body</signatureParts>
  </action>
</parameter> 

Now, when I invoke client from Eclipse with arguments:

-Daxis2.xml=axis-repo/conf/axis2.xml -Daxis2.repo=axis-repo

I got:

org.apache.axis2.AxisFault: CryptoFactory: Cannot load properties: client.properties
at org.apache.rampart.handler.WSDoAllSender.processMessage(WSDoAllSender.java:67)
at org.apache.rampart.handler.WSDoAllHandler.invoke(WSDoAllHandler.java:72)
at org.apache.axis2.engine.Phase.invoke(Phase.java:318)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:251)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:416)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
...
Caused by: java.lang.RuntimeException: CryptoFactory: Cannot load properties: client.properties
at org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:258)
at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:171)
at org.apache.ws.security.handler.WSHandler.loadSignatureCrypto(WSHandler.java:431)
at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:137)
at org.apache.rampart.handler.WSDoAllSender.processBasic(WSDoAllSender.java:201)
at org.apache.rampart.handler.WSDoAllSender.processMessage(WSDoAllSender.java:64)
... 9 more
Caused by: java.lang.NullPointerException
at org.apache.ws.security.components.crypto.CryptoFactory.getProperties(CryptoFactory.java:253)
... 14 more

I'm able to open client.properties as File object. I tried to put this file in various directories or changed its name to use full path (both with slashes, and backslashes while I work on Windows) but nothing helps.

My client.properties file looks like:

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=mn
org.apache.ws.security.crypto.merlin.file=mn_keystore.ks

Any idea why I got this error?

I have found that I have to add client.properties and mn_keystore.ks to wss4j-1.5.8.jar . I don't know if it is by design. My preference is to have both files out of this .jar library.

EDIT : on other environment I tried with separate client.properties and it worked! Now wss4j-1.5.8.jar is as original, without configuration and keystore. I don't know why this work, and this not worked earlier :(

EDIT2 : when Eclipse run application it probably does not add project directory to claaspath. I resigned from adding .properies file to some .jar and now I use: from menu select Run->Debug Configurations, locate your Java application and its classpath tab. Then select "User Entries" and click the "Advanced" button from right panel, and select "Add External Folder". Now add directory with your .properties files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM