在http://blog.csdn.net/wangchsh2008/article/details/6708270中,我做了一個最簡單的cxf安全認證的demo,在其過程中,出現了很多問題。
一開始lib下缺少xalan-2.7.1.jar、opensaml-1.1.jar、serializer-2.7.1.jar,老是報錯。
以上3個jar的下載下傳位址分别為:
http://www.jarfinder.com/index.php/jars/versionInfo/69677
http://d.download.csdn.net/down/337408/wuwenlong527
http://www.jarfinder.com/index.php/jars/versionInfo/69675
後來又出現以下異常:
org.apache.ws.security.WSSecurityException: WSHandler: Encryption: error during message processingorg.apache.ws.security.WSSecurityException: An unsupported signature or encryption algorithm was used (unsupported key transport encryption algorithm: No such algorithm: http://www.w3.org/2001/04/xmlenc#rsa-1_5)
at org.apache.ws.security.action.EncryptionAction.execute(EncryptionAction.java:65)
at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:197)
at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor.access$200(WSS4JOutInterceptor.java:47)
at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:219)
... 8 more
在網上做了一些工作之後,發現是因為系統環境中預設的jre的JCE(Java Cryptography Extension)是受限的,應把它替換成不受限的版本。
解決方法:
下載下傳bcprov-jdk15-1.44.jar包置于%JRE_HOME%/lib/ext目錄下。
下載下傳jce_policy-1_5_0.zip,把解壓得到的US_export_policy.jar和local_policy.jar兩個jar包置于%JRE_HOME%/lib/security目錄下。(替換原來的)
修改%JRE_HOME%/lib/security/java.security檔案,新增配置:security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider。
把bcprov-jdk15-1.44.jar導入工程。
我從網上找了bcprov-jdk13-132.jar和jce_policy-1_4_2,已上傳至:http://download.csdn.net/source/3539611
雖然版本比上面的低,但是經測試是可用的。
本文參考文章位址如下:
http://wxu.iteye.com/blog/284884
http://blog.163.com/jxguo_05/blog/static/71940100201151654322361/
http://magicbear.iteye.com/blog/234125