XFIRE安全整体方案
调用时验证密码+加密+签名
返回结果 加密
得到结果 解密
服务端配置:
XFIRE的配置文件修改点,applicationContext-webservice.xml:
<bean name="userServiceEnc" parent="baseWebService">
<property name="serviceBean" ref="UserServiceImpl" />
<property name="serviceClass"
value="com.megaeyes.ipcamera.service.webservice.iface.UserServiceEnc" />
<property name="inHandlers">
<list>
<ref bean="domInHandler" />
<ref bean="wss4jInHandlerEncSign" />
<ref bean="validateUserTokenHandler" />
</list>
</property>
<property name="outHandlers">
<list>
<ref bean="domOutHandler" />
<ref bean="wss4jOutHandlerEncSign" />
</list>
</property>
</bean>
<bean id="domOutHandler"
class="org.codehaus.xfire.util.dom.DOMOutHandler" />
<bean id="domInHandler"
class="org.codehaus.xfire.util.dom.DOMInHandler" />
<bean id="wss4jInHandlerEncSign"
class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
<property name="properties">
<props>
<prop key="action">
UsernameToken Encrypt Signature
</prop>
<prop key="decryptionPropFile">
insecurity_enc.properties
</prop>
<prop key="passwordCallbackClass">
com.megaeyes.ipcamera.service.webservice.tools.PasswordHandler
</prop>
<prop key="signaturePropFile">
insecurity_sign.properties
</prop>
</props>
</property>
</bean>
<bean id="wss4jOutHandlerEncSign"
class="org.codehaus.xfire.security.wss4j.WSS4JOutHandler">
<property name="properties">
<props>
<prop key="action">Encrypt</prop>
<prop key="encryptionUser">client</prop>
<prop key="encryptionPropFile">
outsecurity_enc.properties
</prop>
</props>
</property>
</bean>
insecurity_enc.properties配置文件:
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=kaishi
org.apache.ws.security.crypto.merlin.file=server_private.jks
insecurity_sign.properties配置文件:
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=kaishi
org.apache.ws.security.crypto.merlin.file=client_public.jks
outsecurity_enc.properties配置文件:
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=kaishi
org.apache.ws.security.crypto.merlin.file=client_public.jks
客户端配置
只用修改XFireClientFactory.java文件就可以了,不过可以改成配置的,不用每次都来修改,有空再改改吧
getEncSign(obj);
public void getEncSign(Object service) {
Client client = ((XFireProxy) Proxy.getInvocationHandler(service))
.getClient();
// 挂上WSS4JOutHandler,提供认证
client.addOutHandler(new DOMOutHandler());
Properties properties = new Properties();
properties.setProperty(WSHandlerConstants.ACTION,
WSHandlerConstants.USERNAME_TOKEN + " "
+ WSHandlerConstants.ENCRYPT + " "
+ WSHandlerConstants.SIGNATURE);
properties.setProperty(WSHandlerConstants.PASSWORD_TYPE,
WSConstants.PASSWORD_DIGEST);
properties.setProperty(WSHandlerConstants.USER, "server");
properties.setProperty(WSHandlerConstants.ENCRYPTION_USER, "server");
properties.setProperty(WSHandlerConstants.ENC_PROP_FILE,
"outsecurity_enc.properties");
properties.setProperty(WSHandlerConstants.USER, "client");
properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
PasswordHandler.class.getName());
properties.setProperty(WSHandlerConstants.SIG_PROP_FILE,
"outsecurity_sign.properties");
properties.setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
client.addOutHandler(new WSS4JOutHandler(properties));
