All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.esec.icpm.signer.ws.soap.CxfUtils Maven / Gradle / Ivy

package br.com.esec.icpm.signer.ws.soap;

import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.handler.WSHandlerConstants;

import br.com.esec.icpm.signer.security.SecurityConfig;
import br.com.esec.icpm.signer.ws.rest.SslUtils;

public class CxfUtils {

	public static void config(Object port) {
		Client client = ClientProxy.getClient(port);
		client.getOutInterceptors().add(newSignerInterceptor());
		client.getRequestContext().put("crypto.properties", SecurityConfig.getConfig());
		client.getRequestContext().put("password", SecurityConfig.getKeystorePassword());
		
		client.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", SslUtils.buildSslContext().getSocketFactory());

	}

	private static SoapInterceptor newSignerInterceptor() {

		Map outProps = new HashMap();
		outProps.put(WSHandlerConstants.ACTION, "Signature");
		outProps.put(WSHandlerConstants.USER, SecurityConfig.getKeyAlias());
		outProps.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
		outProps.put(WSHandlerConstants.USE_REQ_SIG_CERT, WSHandlerConstants.SIGNATURE_USER);
		outProps.put(WSHandlerConstants.USE_SINGLE_CERTIFICATE, "false");
		outProps.put(WSHandlerConstants.SIG_PROP_REF_ID, "crypto.properties");
		return new WSS4JOutInterceptor(outProps);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy