diff options
Diffstat (limited to 'src/main/java/at/gv/util/client')
11 files changed, 146 insertions, 21 deletions
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/szr/IRoleGenerationStrategy.java b/src/main/java/at/gv/util/client/pvp/rprofile/IRoleGenerationStrategy.java index d411f21..1e37214 100644 --- a/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java +++ b/src/main/java/at/gv/util/client/pvp/rprofile/IRoleGenerationStrategy.java @@ -1,4 +1,4 @@ -package at.gv.util.client.szr; +package at.gv.util.client.pvp.rprofile; import at.gv.util.ex.EgovUtilException; diff --git a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp18pSoapHandler.java index 0441bd5..41c4255 100644 --- a/src/main/java/at/gv/util/client/szr/SZRSOAPHandler.java +++ b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp18pSoapHandler.java @@ -1,4 +1,4 @@ -package at.gv.util.client.szr; +package at.gv.util.client.pvp.rprofile; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -29,14 +29,14 @@ 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<SOAPMessageContext> { +public class Pvp18pSoapHandler implements SOAPHandler<SOAPMessageContext> { 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); + private Logger log = LoggerFactory.getLogger(Pvp18pSoapHandler.class); public void close(MessageContext arg0) { 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<SOAPMessageContext> { + + 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<QName> getHeaders() { + return null; + } + +} diff --git a/src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java index f4fc11b..68ccb3d 100644 --- a/src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java +++ b/src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java @@ -1,4 +1,4 @@ -package at.gv.util.client.szr; +package at.gv.util.client.pvp.rprofile; import java.util.Collections; import java.util.List; @@ -22,11 +22,11 @@ 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<SOAPMessageContext> { +public class Pvp2xHttpHeaderHandler implements SOAPHandler<SOAPMessageContext> { private PvpTokenType pvpTokenType = null; - private Logger log = LoggerFactory.getLogger(PVP2XHTTPHeaderHandler.class); + private Logger log = LoggerFactory.getLogger(Pvp2xHttpHeaderHandler.class); public static final String PVP_HEADER_COSTCENTERID_DEFAULT = "<default>"; public static final String PVP_HEADER_VALUE_DELIMITER = ","; @@ -34,11 +34,11 @@ public class PVP2XHTTPHeaderHandler implements SOAPHandler<SOAPMessageContext> { private IRoleGenerationStrategy roleStrategy = null; - public PVP2XHTTPHeaderHandler() { + public Pvp2xHttpHeaderHandler() { } - public PVP2XHTTPHeaderHandler(IRoleGenerationStrategy roleGenerationStrategy) { + public Pvp2xHttpHeaderHandler(IRoleGenerationStrategy roleGenerationStrategy) { log.info("PVP2XHTTPHeaderHandler uses RoleGenerationStrategy: " + roleGenerationStrategy.getClass().getName()); this.roleStrategy = roleGenerationStrategy; 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/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); |