Commit 3ddb0fd2 authored by Quxl's avatar Quxl

x

parent c8dbe771
......@@ -8,8 +8,6 @@ import java.net.URL;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
......@@ -18,9 +16,8 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.commons.logging.Log;
......@@ -29,10 +26,6 @@ import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.wss4j.common.ext.WSPasswordCallback;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -76,11 +69,13 @@ public class SAPServiceFactory {
assert serviceQName != null : "WebService serviceQName cannot be null";
Service dyService = Service.create(wsdlLocation, serviceQName);
T service = portQName == null ? dyService.getPort(requiredType) : dyService.getPort(portQName, requiredType);
Client client = ClientProxy.getClient(service);
if(isOpenUserAuth) {
client.getOutInterceptors().add(this.getWSS4JOutInterceptor());
BindingProvider bp = (BindingProvider) service;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
}
if(isOpenSSLAuth) {
Client client = ClientProxy.getClient(service);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
TLSClientParameters tlsParams = httpConduit.getTlsClientParameters();
tlsParams = tlsParams == null ? new TLSClientParameters() : tlsParams;
......@@ -163,25 +158,4 @@ public class SAPServiceFactory {
return new URL("file:////" + new File(WSDLPATH).getAbsolutePath());
}
private WSS4JOutInterceptor wss4JOutInterceptor = null;
public WSS4JOutInterceptor getWSS4JOutInterceptor() {
if (wss4JOutInterceptor == null) {
Map<String, Object> pro = new HashMap<String, Object>();
pro.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
pro.put(WSHandlerConstants.USER, username);
pro.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
pro.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
public void handle(Callback[] callbacks) {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
pc.setPassword(password);
}
}
});
wss4JOutInterceptor = new WSS4JOutInterceptor(pro);
}
return wss4JOutInterceptor;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment