关于对加密无非是两件事情:
1,首先,当然是导入包
添加 CXF 提供的 WS-Security 的 Maven 依赖
2,在cxf.xml中配置
<bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<!-- 用户认证(明文密码) -->
<entry key="action" value="UsernameToken"/>
<entry key="passwordType" value="PasswordText"/>
<entry key="passwordCallbackRef" value-ref="serverPasswordCallback"/>
</map>
</constructor-arg>
</bean>
WSS4JInInterceptor 是一个 InInterceptor,表示对输入的消息进行拦截,同样还有 OutInterceptor,表示对输出的消息进行拦截
@Component
public class ServerPasswordCallback implements CallbackHandler {
private static final Map<String, String> userMap = new HashMap<String, String>();
static {
userMap.put("client", "clientpass");
userMap.put("server", "serverpass");
}
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
String clientUsername = callback.getIdentifier();
String serverPassword = userMap.get(clientUsername);
if (serverPassword != null) {
callback.setPassword(serverPassword);
}
}
}
下一步在去完成配置