CXF ws security 案例

一、相关概念
提到x509,就不得不提到几个相关概念。
1、Private key
2、Public key
3、KeyStore
4、TrustStore
Private key和Public key很简单,字面意思就可以理解,就是常说的私钥和公钥。
KeyStore和TrustStore简单的说就是存储私钥和密钥的容器。二者从存储结构上面都是一样的,只不过对其概念上做个区分,KeyStore主要用来存储私钥(也可能是Chain),TrustStore是用来存储公钥的。
更详细的可以看另外一篇文章:http://lukejin.iteye.com/blog/605634
在CXF中,使用加密签名的方式作为安全策略,配置上还有些麻烦。
先来看个图:

简单解释一下
1、客户端发送soap到服务端
首先A(客户端)需要使用自己的私钥进行签名,使用B(服务端)的公钥进行加密,然后将soap传给B,B用私钥进行解密,用A的公钥进行验签。
2、服务端返回数据到客户端
首先B用自己的私钥进行签名,用A的公钥进行加密,然后将soap传回给A,A用私钥进行解密,用B的公钥进行验签。
只要搞清楚这个过程,再使用CXF就显得比较容易了。

二、搭建环境

下面我们就可以搭建CXF的环境了
首先用maven创建一个简单的java工程,可以先创建好包com.tongtech.ti.cxf.demo.security
然后上pom文件,将下面的pom文件覆盖你自己工程中的pom文件。
Xml代码   收藏代码
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>ti-cxf</groupId>  
  5.     <artifactId>ti-cxf-security</artifactId>  
  6.     <version>0.0.1-SNAPSHOT</version>  
  7.     <packaging>jar</packaging>  
  8.     <name>Tongtech Demo for CXF Security with wss4j</name>  
  9.     <properties>  
  10.         <cxf.version>2.4.0-SNAPSHOT</cxf.version>  
  11.     </properties>  
  12.     <dependencies>  
  13.         <dependency>  
  14.             <groupId>org.apache.cxf</groupId>  
  15.             <artifactId>cxf-rt-frontend-jaxws</artifactId>  
  16.             <version>${cxf.version}</version>  
  17.         </dependency>  
  18.         <dependency>  
  19.             <groupId>org.apache.cxf</groupId>  
  20.             <artifactId>cxf-rt-transports-http</artifactId>  
  21.             <version>${cxf.version}</version>  
  22.         </dependency>  
  23.         <dependency>  
  24.             <groupId>org.apache.cxf</groupId>  
  25.             <artifactId>cxf-rt-ws-security</artifactId>  
  26.             <version>${cxf.version}</version>  
  27.         </dependency>  
  28.         <dependency>  
  29.             <groupId>org.apache.cxf</groupId>  
  30.             <artifactId>cxf-rt-transports-http-jetty</artifactId>  
  31.             <version>${cxf.version}</version>  
  32.         </dependency>  
  33.     </dependencies>  
  34.   
  35.     <build>  
  36.         <plugins>  
  37.             <plugin>  
  38.                 <groupId>org.apache.maven.plugins</groupId>  
  39.                 <artifactId>maven-compiler-plugin</artifactId>  
  40.                 <configuration>  
  41.                     <source>1.6</source>  
  42.                     <target>1.6</target>  
  43.                 </configuration>  
  44.             </plugin>  
  45.             <plugin>  
  46.                 <groupId>org.apache.cxf</groupId>  
  47.                 <artifactId>cxf-codegen-plugin</artifactId>  
  48.                 <version>${cxf.version}</version>  
  49.                 <executions>  
  50.                     <execution>  
  51.                         <id>generate-sources-static</id>  
  52.                         <phase>generate-sources</phase>  
  53.                         <configuration>  
  54.                             <sourceRoot>${basedir}/target/generate</sourceRoot>  
  55.                             <wsdlOptions
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值