package com.yh.saas.plugin.servicer.ws.client;

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

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;

/**
 * 类名称：客户端WS安全认证处理类
 * 内容摘要：
 *
 * @author yinghai
 * @version 1.0 2012-9-26
 */
public class SupplyWsClientAuthHandler implements CallbackHandler {

    /**
     * webservice调用的安全认证用户名
     */
    private static final String WEBSERVICE_USERNAME = "yh_webservice_username";
    /**
     * webservice调用的安全认证密码
     */
    private static final String WEBSERVICE_USERPASS = "yh_webservice_userpass";

    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
            WSPasswordCallback ps = (WSPasswordCallback) callbacks[i];
            ps.setPassword(WEBSERVICE_USERPASS);
            ps.setIdentifier(WEBSERVICE_USERNAME);
        }
    }

}
