webservice添加用户密码验证

发布于:2021-09-23 04:45:41

一、增加maven?依赖



org.apache.cxf
cxf-rt-ws-security
3.1.8

二、spring-context配置拦*

















三、编写PasswordCallback


import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import org.apache.wss4j.common.ext.WSPasswordCallback;

import java.io.IOException;


public class PasswordCallback implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
String idf = pc.getIdentifier();//ws传过来的用户名
String pwd = null;//需查数据库获得密码
String cfgUser = "aaa";
if(cfgUser!=null && cfgUser.equals(idf)) {
pwd = "123456";
}else {
pwd = "error";
}
pc.setPassword(pwd);
}

}

四、soapUI?调用时设置用户名密码


右键,show Interface view


相关推荐

最新更新

猜你喜欢