From f7c97e3423fa51f9f3d32f0285f2468d95d5987d Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Thu, 23 Jan 2020 13:47:25 +0100 Subject: add first version of SZR client v4.0 --- .../java/at/gv/util/client/ersb/ERsBClient.java | 4 +- .../java/at/gv/util/client/mis/usp/USPClient.java | 4 +- .../at/gv/util/client/mis/usp_v2/USPClient.java | 4 +- .../mis/usp_v2/VDDSRoleGenerationStrategy.java | 2 +- .../pvp/rprofile/IRoleGenerationStrategy.java | 15 ++ .../client/pvp/rprofile/Pvp18pSoapHandler.java | 120 +++++++++++++ .../client/pvp/rprofile/Pvp19pSoapHandler.java | 124 ++++++++++++++ .../pvp/rprofile/Pvp2xHttpHeaderHandler.java | 188 +++++++++++++++++++++ .../util/client/szr/IRoleGenerationStrategy.java | 15 -- .../gv/util/client/szr/PVP2XHTTPHeaderHandler.java | 188 --------------------- src/main/java/at/gv/util/client/szr/SZRClient.java | 3 +- .../java/at/gv/util/client/szr/SZRSOAPHandler.java | 120 ------------- .../java/at/gv/util/client/ur_V2/URClient.java | 4 +- .../java/at/gv/util/client/ur_V5/URClient.java | 4 +- 14 files changed, 460 insertions(+), 335 deletions(-) create mode 100644 src/main/java/at/gv/util/client/pvp/rprofile/IRoleGenerationStrategy.java create mode 100644 src/main/java/at/gv/util/client/pvp/rprofile/Pvp18pSoapHandler.java create mode 100644 src/main/java/at/gv/util/client/pvp/rprofile/Pvp19pSoapHandler.java create mode 100644 src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java delete mode 100644 src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java delete mode 100644 src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java delete mode 100644 src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java (limited to 'src/main/java/at/gv/util/client') diff --git a/src/main/java/at/gv/util/client/ersb/ERsBClient.java b/src/main/java/at/gv/util/client/ersb/ERsBClient.java index e15c844..a4008ff 100644 --- a/src/main/java/at/gv/util/client/ersb/ERsBClient.java +++ b/src/main/java/at/gv/util/client/ersb/ERsBClient.java @@ -23,7 +23,7 @@ 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.pvp.rprofile.Pvp18pSoapHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.ersb.ErsbService; @@ -73,7 +73,7 @@ public class ERsBClient { log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getERsBPVPToken(); - SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); + Pvp18pSoapHandler szrSOAPHandler = new Pvp18pSoapHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); diff --git a/src/main/java/at/gv/util/client/mis/usp/USPClient.java b/src/main/java/at/gv/util/client/mis/usp/USPClient.java index fb88e05..69ab439 100644 --- a/src/main/java/at/gv/util/client/mis/usp/USPClient.java +++ b/src/main/java/at/gv/util/client/mis/usp/USPClient.java @@ -26,7 +26,7 @@ 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.pvp.rprofile.Pvp18pSoapHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.mis.usp.GetMandatesPortType; @@ -120,7 +120,7 @@ public class USPClient { // PV authentication log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getURPVPToken(); - SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); + Pvp18pSoapHandler szrSOAPHandler = new Pvp18pSoapHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); 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 7bbdef9..4b9f5c5 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 @@ -25,7 +25,7 @@ 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.PVP2XHTTPHeaderHandler; +import at.gv.util.client.pvp.rprofile.Pvp2xHttpHeaderHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.mis.usp_v2.ISyncService; @@ -197,7 +197,7 @@ public class USPClient { config.getConfigurationValue("egovutil.usp.role.dynamic.secret")); - PVP2XHTTPHeaderHandler szrSOAPHandler = new PVP2XHTTPHeaderHandler(roleStrategy); + Pvp2xHttpHeaderHandler szrSOAPHandler = new Pvp2xHttpHeaderHandler(roleStrategy); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); diff --git a/src/main/java/at/gv/util/client/mis/usp_v2/VDDSRoleGenerationStrategy.java b/src/main/java/at/gv/util/client/mis/usp_v2/VDDSRoleGenerationStrategy.java index c5573d3..f4bb02f 100644 --- a/src/main/java/at/gv/util/client/mis/usp_v2/VDDSRoleGenerationStrategy.java +++ b/src/main/java/at/gv/util/client/mis/usp_v2/VDDSRoleGenerationStrategy.java @@ -11,7 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.util.MiscUtil; -import at.gv.util.client.szr.IRoleGenerationStrategy; +import at.gv.util.client.pvp.rprofile.IRoleGenerationStrategy; import at.gv.util.ex.EgovUtilException; public class VDDSRoleGenerationStrategy implements IRoleGenerationStrategy { diff --git a/src/main/java/at/gv/util/client/pvp/rprofile/IRoleGenerationStrategy.java b/src/main/java/at/gv/util/client/pvp/rprofile/IRoleGenerationStrategy.java new file mode 100644 index 0000000..1e37214 --- /dev/null +++ b/src/main/java/at/gv/util/client/pvp/rprofile/IRoleGenerationStrategy.java @@ -0,0 +1,15 @@ +package at.gv.util.client.pvp.rprofile; + +import at.gv.util.ex.EgovUtilException; + +public interface IRoleGenerationStrategy { + + /** + * Generates a request specific role string + * @param roleString Role from configuration + * + * @return Dynamic generated role + * @throws EgovUtilException + */ + public String generateRoleString(String roleString) throws EgovUtilException; +} diff --git a/src/main/java/at/gv/util/client/pvp/rprofile/Pvp18pSoapHandler.java b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp18pSoapHandler.java new file mode 100644 index 0000000..41c4255 --- /dev/null +++ b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp18pSoapHandler.java @@ -0,0 +1,120 @@ +package at.gv.util.client.pvp.rprofile; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Set; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPEnvelope; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFactory; +import javax.xml.soap.SOAPHeader; +import javax.xml.soap.SOAPMessage; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import at.gv.util.DOMUtils; +import at.gv.util.MiscUtil; +import at.gv.util.xsd.szr.pvp.ObjectFactory; +import at.gv.util.xsd.szr.pvp.PvpTokenType; + +public class Pvp18pSoapHandler implements SOAPHandler { + + private static final String AUTH_NS = "http://schemas.xmlsoap.org/ws/2002/04/secext"; + private static final String AUTH_PREFIX="wss"; + + private PvpTokenType pvpTokenType = null; + + private Logger log = LoggerFactory.getLogger(Pvp18pSoapHandler.class); + + + 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; + } + try { + SOAPMessage message = smc.getMessage(); + SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); + SOAPFactory soapFactory = SOAPFactory.newInstance(); + + // Creating WS-Security header element + SOAPElement wsSecHeaderElm = soapFactory.createElement( + "Security", + AUTH_PREFIX, + AUTH_NS); + + // serialize pvp token + JAXBContext ctx = JAXBContext.newInstance(PvpTokenType.class); + ObjectFactory of = new ObjectFactory(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ctx.createMarshaller().marshal(of.createPvpToken(pvpTokenType), bos); + Element pvpTokenElement = DOMUtils.parseXmlNonValidating(new ByteArrayInputStream(bos.toByteArray())); + SOAPElement pvpToken = soapFactory.createElement(pvpTokenElement); + + // adding elements + wsSecHeaderElm.addChildElement(pvpToken); + SOAPHeader header = envelope.getHeader(); + if (header == null) + header = envelope.addHeader(); + + header.addChildElement(wsSecHeaderElm); + + return true; + } catch(SOAPException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (JAXBException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (ParserConfigurationException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (SAXException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (IOException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } + + + } + + public Set getHeaders() { + return null; + } + +} diff --git a/src/main/java/at/gv/util/client/pvp/rprofile/Pvp19pSoapHandler.java b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp19pSoapHandler.java new file mode 100644 index 0000000..443c3b5 --- /dev/null +++ b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp19pSoapHandler.java @@ -0,0 +1,124 @@ +package at.gv.util.client.pvp.rprofile; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Set; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPEnvelope; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFactory; +import javax.xml.soap.SOAPHeader; +import javax.xml.soap.SOAPMessage; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +import at.gv.util.DOMUtils; +import at.gv.util.MiscUtil; +import at.gv.util.xsd.szr.pvp19.ObjectFactory; +import at.gv.util.xsd.szr.pvp19.PvpTokenType; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +public class Pvp19pSoapHandler implements SOAPHandler { + + private static final String AUTH_NS = "http://schemas.xmlsoap.org/ws/2002/04/secext"; + private static final String AUTH_PREFIX="wss"; + + private PvpTokenType pvpTokenType = null; + + private final Logger log = LoggerFactory.getLogger(Pvp19pSoapHandler.class); + + + @Override + public void close(MessageContext arg0) { + } + + + @Override + public boolean handleFault(SOAPMessageContext arg0) { + return true; + } + + public void configure(PvpTokenType pvpToken) { + MiscUtil.assertNotNull(pvpToken, "pvpToken"); + this.pvpTokenType = pvpToken; + } + + + @Override + public boolean handleMessage(SOAPMessageContext smc) { + log.trace("Initializing SZR SOAP message handler."); + + final 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; + } + try { + final SOAPMessage message = smc.getMessage(); + final SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); + final SOAPFactory soapFactory = SOAPFactory.newInstance(); + + // Creating WS-Security header element + final SOAPElement wsSecHeaderElm = soapFactory.createElement( + "Security", + AUTH_PREFIX, + AUTH_NS); + + // serialize pvp token + final JAXBContext ctx = JAXBContext.newInstance(PvpTokenType.class); + final ObjectFactory of = new ObjectFactory(); + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ctx.createMarshaller().marshal(of.createPvpToken(pvpTokenType), bos); + final Element pvpTokenElement = DOMUtils.parseXmlNonValidating(new ByteArrayInputStream(bos.toByteArray())); + final SOAPElement pvpToken = soapFactory.createElement(pvpTokenElement); + + // adding elements + wsSecHeaderElm.addChildElement(pvpToken); + SOAPHeader header = envelope.getHeader(); + if (header == null) + header = envelope.addHeader(); + + header.addChildElement(wsSecHeaderElm); + + return true; + } catch(final SOAPException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (final JAXBException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (final ParserConfigurationException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (final SAXException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } catch (final IOException e) { + log.warn("Cannot add WS-Security header.", e); + return false; + } + + + } + + @Override + public Set getHeaders() { + return null; + } + +} diff --git a/src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java new file mode 100644 index 0000000..68ccb3d --- /dev/null +++ b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java @@ -0,0 +1,188 @@ +package at.gv.util.client.pvp.rprofile; + +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.ex.EgovUtilException; +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 Pvp2xHttpHeaderHandler implements SOAPHandler { + + private PvpTokenType pvpTokenType = null; + + private Logger log = LoggerFactory.getLogger(Pvp2xHttpHeaderHandler.class); + + public static final String PVP_HEADER_COSTCENTERID_DEFAULT = ""; + public static final String PVP_HEADER_VALUE_DELIMITER = ","; + public static final String PVP_HEADER_ROLE_VALUE_DELIMITER = ";"; + + private IRoleGenerationStrategy roleStrategy = null; + + public Pvp2xHttpHeaderHandler() { + + } + + public Pvp2xHttpHeaderHandler(IRoleGenerationStrategy roleGenerationStrategy) { + log.info("PVP2XHTTPHeaderHandler uses RoleGenerationStrategy: " + roleGenerationStrategy.getClass().getName()); + this.roleStrategy = roleGenerationStrategy; + + } + + 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 headers = (Map) smc.get(Message.PROTOCOL_HEADERS); + //PVP 2.x header + //setHeader(headers, "X-PVP-VERSION", pvpTokenType.getVersion()); + setHeader(headers, "X-PVP-EGOVTOKEN-VERSION", pvpTokenType.getVersion()); + setHeader(headers, "X-PVP-USERID", pvpTokenType.getAuthenticate().getUserPrincipal().getUserId()); + setHeader(headers, "X-PVP-GID", pvpTokenType.getAuthenticate().getUserPrincipal().getGvGid()); + setHeader(headers, "X-PVP-PARTICIPANT-ID", pvpTokenType.getAuthenticate().getParticipantId()); + setHeader(headers, "X-PVP-OU-GV-OU-ID", pvpTokenType.getAuthenticate().getUserPrincipal().getGvOuId()); + setHeader(headers, "X-PVP-OU", pvpTokenType.getAuthenticate().getUserPrincipal().getOu()); + setHeader(headers, "X-PVP-FUNCTION", pvpTokenType.getAuthenticate().getUserPrincipal().getGvFunction()); + setHeader(headers, "X-PVP-SECCLASS", String.valueOf(pvpTokenType.getAuthenticate().getUserPrincipal().getGvSecClass().intValue())); + setHeader(headers, "X-PVP-PRINCIPAL-NAME", pvpTokenType.getAuthenticate().getUserPrincipal().getCn()); + setHeader(headers, "X-PVP-BINDING", "http"); + setHeader(headers, "X-PVP-OU-OKZ", "AT:OVS"); + + + //PVP 1.x header + //setHeader(headers, "X-VERSION", pvpTokenType.getVersion()); + setHeader(headers, "X-VERSION", "1.8"); + 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 roles = pvpTokenType.getAuthorize().getRole(); + if (roles != null && !roles.isEmpty()) { + for (Role role : roles) { + String roleElement = role.getValue(); + List 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; + } + } + + if (roleStrategy != null) { + log.trace("Generate dynamic role ... "); + try { + String dynRoleString = roleStrategy.generateRoleString(roleString); + setHeader(headers, "X-PVP-ROLES", dynRoleString); + setHeader(headers, "X-AUTHORIZE-ROLES", dynRoleString); + + } catch (EgovUtilException e) { + throw new RuntimeException("Can NOT generate dynamic VDDS role by using: " + roleStrategy.getClass().getName(), e); + + } + + } + + + + + + //set optional headers + String costCenterId = StringUtils.EMPTY; + String invoiceRecptId = StringUtils.EMPTY; + + 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.isEmpty()) + costCenterId = value; + else + costCenterId = PVP_HEADER_VALUE_DELIMITER + value; + + } + } + } + + setHeader(headers, "X-PVP-COST-CENTER-ID", costCenterId); + setHeader(headers, "X-PVP-INVOICE-RECPT-ID", invoiceRecptId); + + setHeader(headers, "X-ACCOUNTING-CostCenterId", costCenterId); + setHeader(headers, "X-ACCOUNTING-InvoiceRecptId", invoiceRecptId); + + return true; + + + } + + public Set getHeaders() { + return null; + } + private void setHeader(Map headers, String name, String value) { + if (MiscUtil.isEmpty(value)) + headers.put(name, Collections.singletonList(StringUtils.EMPTY)); + else + headers.put(name, Collections.singletonList(value)); + + } + +} diff --git a/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java b/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java deleted file mode 100644 index d411f21..0000000 --- a/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java +++ /dev/null @@ -1,15 +0,0 @@ -package at.gv.util.client.szr; - -import at.gv.util.ex.EgovUtilException; - -public interface IRoleGenerationStrategy { - - /** - * Generates a request specific role string - * @param roleString Role from configuration - * - * @return Dynamic generated role - * @throws EgovUtilException - */ - public String generateRoleString(String roleString) throws EgovUtilException; -} diff --git a/src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java b/src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java deleted file mode 100644 index f4fc11b..0000000 --- a/src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java +++ /dev/null @@ -1,188 +0,0 @@ -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.ex.EgovUtilException; -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 PVP2XHTTPHeaderHandler implements SOAPHandler { - - private PvpTokenType pvpTokenType = null; - - private Logger log = LoggerFactory.getLogger(PVP2XHTTPHeaderHandler.class); - - public static final String PVP_HEADER_COSTCENTERID_DEFAULT = ""; - public static final String PVP_HEADER_VALUE_DELIMITER = ","; - public static final String PVP_HEADER_ROLE_VALUE_DELIMITER = ";"; - - private IRoleGenerationStrategy roleStrategy = null; - - public PVP2XHTTPHeaderHandler() { - - } - - public PVP2XHTTPHeaderHandler(IRoleGenerationStrategy roleGenerationStrategy) { - log.info("PVP2XHTTPHeaderHandler uses RoleGenerationStrategy: " + roleGenerationStrategy.getClass().getName()); - this.roleStrategy = roleGenerationStrategy; - - } - - 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 headers = (Map) smc.get(Message.PROTOCOL_HEADERS); - //PVP 2.x header - //setHeader(headers, "X-PVP-VERSION", pvpTokenType.getVersion()); - setHeader(headers, "X-PVP-EGOVTOKEN-VERSION", pvpTokenType.getVersion()); - setHeader(headers, "X-PVP-USERID", pvpTokenType.getAuthenticate().getUserPrincipal().getUserId()); - setHeader(headers, "X-PVP-GID", pvpTokenType.getAuthenticate().getUserPrincipal().getGvGid()); - setHeader(headers, "X-PVP-PARTICIPANT-ID", pvpTokenType.getAuthenticate().getParticipantId()); - setHeader(headers, "X-PVP-OU-GV-OU-ID", pvpTokenType.getAuthenticate().getUserPrincipal().getGvOuId()); - setHeader(headers, "X-PVP-OU", pvpTokenType.getAuthenticate().getUserPrincipal().getOu()); - setHeader(headers, "X-PVP-FUNCTION", pvpTokenType.getAuthenticate().getUserPrincipal().getGvFunction()); - setHeader(headers, "X-PVP-SECCLASS", String.valueOf(pvpTokenType.getAuthenticate().getUserPrincipal().getGvSecClass().intValue())); - setHeader(headers, "X-PVP-PRINCIPAL-NAME", pvpTokenType.getAuthenticate().getUserPrincipal().getCn()); - setHeader(headers, "X-PVP-BINDING", "http"); - setHeader(headers, "X-PVP-OU-OKZ", "AT:OVS"); - - - //PVP 1.x header - //setHeader(headers, "X-VERSION", pvpTokenType.getVersion()); - setHeader(headers, "X-VERSION", "1.8"); - 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 roles = pvpTokenType.getAuthorize().getRole(); - if (roles != null && !roles.isEmpty()) { - for (Role role : roles) { - String roleElement = role.getValue(); - List 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; - } - } - - if (roleStrategy != null) { - log.trace("Generate dynamic role ... "); - try { - String dynRoleString = roleStrategy.generateRoleString(roleString); - setHeader(headers, "X-PVP-ROLES", dynRoleString); - setHeader(headers, "X-AUTHORIZE-ROLES", dynRoleString); - - } catch (EgovUtilException e) { - throw new RuntimeException("Can NOT generate dynamic VDDS role by using: " + roleStrategy.getClass().getName(), e); - - } - - } - - - - - - //set optional headers - String costCenterId = StringUtils.EMPTY; - String invoiceRecptId = StringUtils.EMPTY; - - 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.isEmpty()) - costCenterId = value; - else - costCenterId = PVP_HEADER_VALUE_DELIMITER + value; - - } - } - } - - setHeader(headers, "X-PVP-COST-CENTER-ID", costCenterId); - setHeader(headers, "X-PVP-INVOICE-RECPT-ID", invoiceRecptId); - - setHeader(headers, "X-ACCOUNTING-CostCenterId", costCenterId); - setHeader(headers, "X-ACCOUNTING-InvoiceRecptId", invoiceRecptId); - - return true; - - - } - - public Set getHeaders() { - return null; - } - private void setHeader(Map headers, String name, String value) { - if (MiscUtil.isEmpty(value)) - headers.put(name, Collections.singletonList(StringUtils.EMPTY)); - else - headers.put(name, Collections.singletonList(value)); - - } - -} diff --git a/src/main/java/at/gv/util/client/szr/SZRClient.java b/src/main/java/at/gv/util/client/szr/SZRClient.java index 67813bd..e6fb31f 100644 --- a/src/main/java/at/gv/util/client/szr/SZRClient.java +++ b/src/main/java/at/gv/util/client/szr/SZRClient.java @@ -24,6 +24,7 @@ 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.SZR; @@ -180,7 +181,7 @@ public class SZRClient { log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getPVPToken(); - SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); + Pvp18pSoapHandler szrSOAPHandler = new Pvp18pSoapHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); diff --git a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java b/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java deleted file mode 100644 index 0441bd5..0000000 --- a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java +++ /dev/null @@ -1,120 +0,0 @@ -package at.gv.util.client.szr; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Set; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.namespace.QName; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.soap.SOAPElement; -import javax.xml.soap.SOAPEnvelope; -import javax.xml.soap.SOAPException; -import javax.xml.soap.SOAPFactory; -import javax.xml.soap.SOAPHeader; -import javax.xml.soap.SOAPMessage; -import javax.xml.ws.handler.MessageContext; -import javax.xml.ws.handler.soap.SOAPHandler; -import javax.xml.ws.handler.soap.SOAPMessageContext; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -import at.gv.util.DOMUtils; -import at.gv.util.MiscUtil; -import at.gv.util.xsd.szr.pvp.ObjectFactory; -import at.gv.util.xsd.szr.pvp.PvpTokenType; - -public class SZRSOAPHandler implements SOAPHandler { - - private static final String AUTH_NS = "http://schemas.xmlsoap.org/ws/2002/04/secext"; - private static final String AUTH_PREFIX="wss"; - - private PvpTokenType pvpTokenType = null; - - private Logger log = LoggerFactory.getLogger(SZRSOAPHandler.class); - - - 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; - } - try { - SOAPMessage message = smc.getMessage(); - SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); - SOAPFactory soapFactory = SOAPFactory.newInstance(); - - // Creating WS-Security header element - SOAPElement wsSecHeaderElm = soapFactory.createElement( - "Security", - AUTH_PREFIX, - AUTH_NS); - - // serialize pvp token - JAXBContext ctx = JAXBContext.newInstance(PvpTokenType.class); - ObjectFactory of = new ObjectFactory(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ctx.createMarshaller().marshal(of.createPvpToken(pvpTokenType), bos); - Element pvpTokenElement = DOMUtils.parseXmlNonValidating(new ByteArrayInputStream(bos.toByteArray())); - SOAPElement pvpToken = soapFactory.createElement(pvpTokenElement); - - // adding elements - wsSecHeaderElm.addChildElement(pvpToken); - SOAPHeader header = envelope.getHeader(); - if (header == null) - header = envelope.addHeader(); - - header.addChildElement(wsSecHeaderElm); - - return true; - } catch(SOAPException e) { - log.warn("Cannot add WS-Security header.", e); - return false; - } catch (JAXBException e) { - log.warn("Cannot add WS-Security header.", e); - return false; - } catch (ParserConfigurationException e) { - log.warn("Cannot add WS-Security header.", e); - return false; - } catch (SAXException e) { - log.warn("Cannot add WS-Security header.", e); - return false; - } catch (IOException e) { - log.warn("Cannot add WS-Security header.", e); - return false; - } - - - } - - public Set getHeaders() { - return null; - } - -} diff --git a/src/main/java/at/gv/util/client/ur_V2/URClient.java b/src/main/java/at/gv/util/client/ur_V2/URClient.java index 134f7f5..24688ae 100644 --- a/src/main/java/at/gv/util/client/ur_V2/URClient.java +++ b/src/main/java/at/gv/util/client/ur_V2/URClient.java @@ -39,7 +39,7 @@ import at.gv.util.xsd.ur_V2.xmlsw.SearchResponseType; 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.pvp.rprofile.Pvp18pSoapHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.ur_V2.URSuche; @@ -452,7 +452,7 @@ public class URClient { log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getURPVPToken(); - SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); + Pvp18pSoapHandler szrSOAPHandler = new Pvp18pSoapHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); diff --git a/src/main/java/at/gv/util/client/ur_V5/URClient.java b/src/main/java/at/gv/util/client/ur_V5/URClient.java index 6be521e..00fb750 100644 --- a/src/main/java/at/gv/util/client/ur_V5/URClient.java +++ b/src/main/java/at/gv/util/client/ur_V5/URClient.java @@ -39,7 +39,7 @@ import at.gv.util.xsd.ur_V5.xmlsw.SearchResponseType; 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.pvp.rprofile.Pvp18pSoapHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.ur_V5.URSuche; @@ -543,7 +543,7 @@ public class URClient { log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getURPVPToken(); - SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler(); + Pvp18pSoapHandler szrSOAPHandler = new Pvp18pSoapHandler(); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); -- cgit v1.2.3