package at.gv.util.client.szr; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.xml.namespace.QName; import javax.xml.ws.BindingProvider; import javax.xml.ws.Holder; import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.Handler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.util.LaxHostNameVerifier; import at.gv.util.LoggingHandler; import at.gv.util.MiscUtil; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.szr.SZR; import at.gv.util.wsdl.szr.SZRException; import at.gv.util.wsdl.szr.SZRService; import at.gv.util.xsd.szr.FremdBPKRequestType; import at.gv.util.xsd.szr.FremdBPKType; import at.gv.util.xsd.szr.IdentityLinkType; import at.gv.util.xsd.szr.PersonInfoType; import at.gv.util.xsd.szr.pvp.PvpTokenType; import at.gv.util.xsd.szr.xmldsig.KeyValueType; import com.sun.xml.ws.developer.JAXWSProperties; public class SZRClient { @Resource WebServiceContext wsContext; private EgovUtilConfiguration config = null; Logger log = LoggerFactory.getLogger(SZRClient.class); private SZR szr = null; public SZRClient(EgovUtilConfiguration config) throws EgovUtilException { MiscUtil.assertNotNull(config, "config"); this.config = config; initialize(); } public IdentityLinkType getIdentityLink(PersonInfoType personInfo, List keyValue, Boolean insertERnP) throws SZRException { MiscUtil.assertNotNull(personInfo, "personInfo"); MiscUtil.assertNotNull(keyValue, "keyValue"); return this.szr.getIdentityLink(personInfo, keyValue, insertERnP); } public String getStammzahl(PersonInfoType personInfo) throws SZRException { MiscUtil.assertNotNull(personInfo, "personInfo"); return this.szr.getStammzahl(personInfo); } public String getBPK(PersonInfoType personInfo, String target, String vkz) throws SZRException, EgovUtilException { MiscUtil.assertNotNull(personInfo, "personInfo"); MiscUtil.assertNotNull(target, "target"); String targetPrefix = "urn:publicid:gv.at:cdid+"; String targetString = null; if (target.length() == 2) { targetString = targetPrefix + target; } else if (!target.startsWith(targetPrefix)) { throw new EgovUtilException("Target must start with " + targetPrefix); } else { targetString = target; } Holder returnBPK = new Holder(); this.szr.getBPK(personInfo, targetString, vkz, null, false, returnBPK, null, null); return returnBPK.value; } public String transformBPK(PersonInfoType personInfo, String inputBpk, String inputTarget, String target, String vkz) throws SZRException, EgovUtilException { MiscUtil.assertNotNull(personInfo, "personInfo"); MiscUtil.assertNotNull(target, "target"); String targetPrefix = "urn:publicid:gv.at:cdid+"; String targetString = null; if (target.length() == 2) { targetString = targetPrefix + target; } else if (!target.startsWith(targetPrefix)) { throw new EgovUtilException("Target must start with " + targetPrefix); } else { targetString = target; } Holder returnBPK = new Holder(); FremdBPKRequestType rt = new FremdBPKRequestType(); rt.setBereichsKennung(target); rt.setVKZ(vkz); List list = new ArrayList(); list.add(rt); List response = this.szr.transformBPK(personInfo, inputBpk, inputTarget, "kt", list); if (response == null) { return null; } return response.get(0).getFremdBPK(); } @SuppressWarnings({ "rawtypes", "unchecked" }) private void initialize() throws EgovUtilException { URL url = SZRClient.class.getResource("/wsdl/szr/SZR_v2.0.wsdl"); SZRService szrService = null; if (config.isSZRTestEnvironment()) { log.trace("Initializing SZR test configuration."); //szrService = new SZRService(url, new QName("urn:SZRServices", "SZRTestumgebung")); szrService = new SZRService(url, new QName("urn:SZRServices", "SZRService")); szr = szrService.getSZRTestumgebung(); } else { log.trace("Initializing SZR productive configuration."); szrService = new SZRService(url, new QName("urn:SZRServices", "SZRService")); szr = szrService.getSZRProduktionsumgebung(); } String szrURL = null; if (config.isSZRTestEnvironment()) { szrURL = config.getSZRTestEnvironmentURL(); } else { szrURL = config.getSZRProductionEnvironmentURL(); } log.trace("SZR connection URL: " + szrURL); BindingProvider bindingProvider = (BindingProvider) szr; Map requestContext = bindingProvider.getRequestContext(); requestContext.put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, szrURL); log.trace("Adding JAX-WS request/response trace handler."); List handlerList = bindingProvider.getBinding().getHandlerChain(); if (handlerList == null) { handlerList = new ArrayList(); } LoggingHandler loggingHandler = new LoggingHandler(); handlerList.add(loggingHandler); log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getPVPToken(); SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); // check for ssl if (szrURL.toLowerCase().startsWith("https")) { log.trace("Using ssl for SZR client request."); SSLContext sslContext = this.config.getSZRsslConfiguration().getSSLContext(false); if (sslContext == null) { throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first."); } requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory()); // check for lax hostname if (this.config.getSZRsslConfiguration().useLaxHostNameVerifier()) { log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier()); } } } }