diff options
Diffstat (limited to 'src/main/java/at/gv/util/client')
3 files changed, 166 insertions, 21 deletions
diff --git a/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java b/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java index 334df87..4d23a1e 100644 --- a/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java +++ b/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java @@ -2,14 +2,11 @@ package at.gv.util.client.mis.usp_v2; import java.net.URL; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.net.ssl.SSLContext; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.namespace.QName; import javax.xml.ws.BindingProvider; import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.Handler; @@ -26,20 +23,15 @@ import org.slf4j.LoggerFactory; import at.gv.util.LaxHostNameVerifier; import at.gv.util.LoggingHandler; import at.gv.util.MiscUtil; -import at.gv.util.client.szr.SZRSOAPHandler; +import at.gv.util.client.szr.SZRHTTPHeaderHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; -import at.gv.util.wsdl.mis.usp.GetMandatesPortType; -import at.gv.util.wsdl.mis.usp.GetMandatesService; import at.gv.util.wsdl.mis.usp_v2.ISyncService; import at.gv.util.wsdl.mis.usp_v2.ListMandatesFault; import at.gv.util.wsdl.mis.usp_v2.SynchronisationServiceServiceagent; -import at.gv.util.xsd.mis.usp.GetMandatesRequest; -import at.gv.util.xsd.mis.usp.GetMandatesRequest.MandateFilters; -import at.gv.util.xsd.mis.usp.GetMandatesResponse; -import at.gv.util.xsd.mis.usp.IdentificationType; import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.ListMandatesRequest; import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.ListMandatesResponseType; +import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.MandateAttributesSearchFilterType; import at.gv.util.xsd.szr.pvp.PvpTokenType; public class USPClient { @@ -98,10 +90,21 @@ public class USPClient { public void getMandates(String bpkType, String bpkValue, List<String> mandateFilters) { ListMandatesRequest parameters = new ListMandatesRequest(); + MandateAttributesSearchFilterType searchFilterType = new MandateAttributesSearchFilterType(); + + Object searchFilter = null; + searchFilterType.setFilter(searchFilter ); + + + //request USP try { + log.trace("Request pre-processing finished. Requesting USP ... "); + ListMandatesResponseType results = this.uspSuche.listMandates(parameters ); + log.trace("Receive response from USP. Starting response post-processing ... "); + } catch (ListMandatesFault e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -134,17 +137,20 @@ public class USPClient { if (handlerList == null) { handlerList = new ArrayList(); } - LoggingHandler loggingHandler = new LoggingHandler(); - if (this.logEnabled) { - handlerList.add(loggingHandler); - } - + // PV authentication log.trace("Adding WS-Security Header handler."); - PvpTokenType pvpToken = config.getURPVPToken(); - SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); + PvpTokenType pvpToken = config.getUSPPVPToken(); + SZRHTTPHeaderHandler szrSOAPHandler = new SZRHTTPHeaderHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); + + LoggingHandler loggingHandler = new LoggingHandler(); + if (this.logEnabled) { + handlerList.add(loggingHandler); + } + + // set handler bindingProvider.getBinding().setHandlerChain(handlerList); Client client = ClientProxy.getClient(uspSuche); @@ -156,7 +162,8 @@ public class USPClient { httpClientPolicy.setAllowChunking(false); httpClientPolicy.setReceiveTimeout(32000); http.setClient(httpClientPolicy); - + + // check for ssl if (uspURL.toLowerCase().startsWith("https")) { log.trace("Using ssl for SZR client request."); diff --git a/src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java b/src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java new file mode 100644 index 0000000..bde6b7b --- /dev/null +++ b/src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java @@ -0,0 +1,138 @@ +package at.gv.util.client.szr; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +import org.apache.commons.lang.StringUtils; +import org.apache.cxf.message.Message; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import at.gv.util.MiscUtil; +import at.gv.util.xsd.szr.pvp.Param; +import at.gv.util.xsd.szr.pvp.PvpTokenType; +import at.gv.util.xsd.szr.pvp.PvpTokenType.Accounting; +import at.gv.util.xsd.szr.pvp.PvpTokenType.Accounting.GvCostCenterId; +import at.gv.util.xsd.szr.pvp.Role; + +public class SZRHTTPHeaderHandler implements SOAPHandler<SOAPMessageContext> { + + private PvpTokenType pvpTokenType = null; + + private Logger log = LoggerFactory.getLogger(SZRHTTPHeaderHandler.class); + + public static final String PVP_HEADER_COSTCENTERID_DEFAULT = "<default>"; + public static final String PVP_HEADER_VALUE_DELIMITER = ","; + public static final String PVP_HEADER_ROLE_VALUE_DELIMITER = ";"; + + public void close(MessageContext arg0) { + } + + + public boolean handleFault(SOAPMessageContext arg0) { + return true; + } + + public void configure(PvpTokenType pvpToken) { + MiscUtil.assertNotNull(pvpToken, "pvpToken"); + this.pvpTokenType = pvpToken; + } + + + public boolean handleMessage(SOAPMessageContext smc) { + log.trace("Initializing SZR SOAP message handler."); + + boolean isOutMessage = ((Boolean) smc.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue(); + log.trace("Outbound message: " + isOutMessage); + if (pvpTokenType == null) { + throw new NullPointerException("Please configure first the PVP token."); + } + + if (!isOutMessage) { + return true; + } + Map<String, List> headers = (Map<String, List>) smc.get(Message.PROTOCOL_HEADERS); + setHeader(headers, "X-VERSION", pvpTokenType.getVersion()); + setHeader(headers, "X-AUTHENTICATE-UserID", pvpTokenType.getAuthenticate().getUserPrincipal().getUserId()); + setHeader(headers, "X-AUTHENTICATE-GVGID", pvpTokenType.getAuthenticate().getUserPrincipal().getGvGid()); + setHeader(headers, "X-AUTHENTICATE-PARTICIPANTID", pvpTokenType.getAuthenticate().getParticipantId()); + setHeader(headers, "X-AUTHENTICATE-GVOUID", pvpTokenType.getAuthenticate().getUserPrincipal().getGvOuId()); + setHeader(headers, "X-AUTHENTICATE-OU", pvpTokenType.getAuthenticate().getUserPrincipal().getOu()); + setHeader(headers, "X-AUTHENTICATE-GVFUNCTION", pvpTokenType.getAuthenticate().getUserPrincipal().getGvFunction()); + setHeader(headers, "X-AUTHENTICATE-gvSecClass", String.valueOf(pvpTokenType.getAuthenticate().getUserPrincipal().getGvSecClass().intValue())); + setHeader(headers, "X-AUTHENTICATE-cn",pvpTokenType.getAuthenticate().getUserPrincipal().getCn()); + + //set roles attribute + String roleString = null; + List<Role> roles = pvpTokenType.getAuthorize().getRole(); + if (roles != null && !roles.isEmpty()) { + for (Role role : roles) { + String roleElement = role.getValue(); + List<Param> roleParams = role.getParam(); + if (roleParams != null && !roleParams.isEmpty()) { + roleElement = roleElement + "("; + for (Param el : roleParams) { + roleElement = roleElement + el.getKey() + "=" + el.getValue() + PVP_HEADER_VALUE_DELIMITER; + + } + roleElement = roleElement.substring(0, roleElement.length()-1) + ")"; + } + + if (roleString == null) + roleString = roleElement; + else + roleString = roleString + PVP_HEADER_ROLE_VALUE_DELIMITER + roleElement; + } + } + setHeader(headers, "X-AUTHORIZE-ROLES", roleString); + + //set optional headers + String costCenterId = null; + String invoiceRecptId = null; + + Accounting accounting = pvpTokenType.getAccounting(); + if (accounting != null) { + invoiceRecptId = accounting.getInvoiceRecptId(); + if (accounting.getGvCostCenterId() != null && !accounting.getGvCostCenterId().isEmpty()) { + for (GvCostCenterId el : accounting.getGvCostCenterId()) { + String value = StringUtils.EMPTY; + if (el.isDefault()) + value = PVP_HEADER_COSTCENTERID_DEFAULT; + + value = value + el.getValue(); + + if (costCenterId == null) + costCenterId = value; + else + costCenterId = PVP_HEADER_VALUE_DELIMITER + value; + + } + } + } + + setHeader(headers, "X-ACCOUNTING-CostCenterId", costCenterId); + setHeader(headers, "X-ACCOUNTING-InvoiceRecptId", invoiceRecptId); + + return true; + + + } + + public Set<QName> getHeaders() { + return null; + } + private void setHeader(Map<String, List> headers, String name, String value) { + if (MiscUtil.isEmpty(value)) + headers.put(name, null); + else + headers.put(name, Collections.singletonList(value)); + + } + +} diff --git a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java b/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java index 9ee672c..0441bd5 100644 --- a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java +++ b/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java @@ -47,10 +47,10 @@ public class SZRSOAPHandler implements SOAPHandler<SOAPMessageContext> { return true; } - public void configure(PvpTokenType pvpToken) { - MiscUtil.assertNotNull(pvpToken, "pvpToken"); + public void configure(PvpTokenType pvpToken) { + MiscUtil.assertNotNull(pvpToken, "pvpToken"); this.pvpTokenType = pvpToken; - } + } public boolean handleMessage(SOAPMessageContext smc) { |