package at.gv.util.client.szr; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; 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.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.transports.http.configuration.HTTPClientPolicy; 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.client.pvp.rprofile.Pvp18pSoapHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.szr_v4.SZR; import at.gv.util.wsdl.szr_v4.SZRException; import at.gv.util.wsdl.szr_v4.SZRService; import at.gv.util.xsd.szr_v4.FremdBPKRequestType; import at.gv.util.xsd.szr_v4.FremdBPKType; import at.gv.util.xsd.szr_v4.GetBPK; import at.gv.util.xsd.szr_v4.GetBPKResponse; import at.gv.util.xsd.szr_v4.GetIdentityLink; import at.gv.util.xsd.szr_v4.GetIdentityLinkResponse; import at.gv.util.xsd.szr_v4.GetStammzahl; import at.gv.util.xsd.szr_v4.GetStammzahlResponse; import at.gv.util.xsd.szr_v4.IdentityLinkType; import at.gv.util.xsd.szr_v4.PersonInfoType; import at.gv.util.xsd.szr_v4.TransformBPK; import at.gv.util.xsd.szr_v4.TransformBPKResponse; import at.gv.util.xsd.szr.pvp.PvpTokenType; import at.gv.util.xsd.szr.xmldsig.KeyValueType; 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"); GetIdentityLink idlReq = new GetIdentityLink(); idlReq.setInsertERnP(insertERnP); idlReq.setPersonInfo(personInfo); idlReq.getKeyValue().addAll(keyValue); GetIdentityLinkResponse idlResp = this.szr.getIdentityLink(idlReq); return idlResp.getGetIdentityLinkReturn(); } public String getStammzahl(PersonInfoType personInfo) throws SZRException { MiscUtil.assertNotNull(personInfo, "personInfo"); GetStammzahl req = new GetStammzahl(); req.setPersonInfo(personInfo); GetStammzahlResponse resp = this.szr.getStammzahl(req ); return resp.getStammzahl(); } 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; // } GetBPK req = new GetBPK(); req.setPersonInfo(personInfo); req.getBereichsKennung().add(targetString); req.setVKZ(vkz); req.setListMultiplePersons(false); GetBPKResponse resp = this.szr.getBPK(req); return resp.getGetBPKReturn().get(0); } public FremdBPKType 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(); TransformBPK req = new TransformBPK(); req.setPersonInfo(personInfo); req.setInputBereichsKennung(inputTarget); req.setInputBPK(inputBpk); req.setBegruendung("kt"); req.getTarget().add(rt); TransformBPKResponse resp = this.szr.transformBPK(req ); List response = resp.getTransformBPKReturn(); if (response == null) { return null; } return response.get(0); } @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(); } if (MiscUtil.isEmpty(szrURL)) { log.info("No SZR service URL found. SZR-Client initalisiation failed."); throw new EgovUtilException("No SZR service URL found. SZR-Client initalisiation failed."); } 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(); } log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getPVPToken(); Pvp18pSoapHandler szrSOAPHandler = new Pvp18pSoapHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); LoggingHandler loggingHandler = new LoggingHandler(); handlerList.add(loggingHandler); // 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."); } Client client = ClientProxy.getClient(szr); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(36000); httpClientPolicy.setReceiveTimeout(60000); http.setClient(httpClientPolicy); TLSClientParameters tlsParams = new TLSClientParameters(); tlsParams.setSSLSocketFactory(sslContext.getSocketFactory()); // check for lax hostname if (this.config.getSZRsslConfiguration().useLaxHostNameVerifier()) { log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); tlsParams.setHostnameVerifier(new LaxHostNameVerifier()); } http.setTlsClientParameters(tlsParams ); } } }