diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-01-23 13:47:25 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-01-23 13:47:25 +0100 |
commit | f7c97e3423fa51f9f3d32f0285f2468d95d5987d (patch) | |
tree | bd30f3c5ceabf149f42da518ec5b803e3c27b1ca /src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java | |
parent | 2708d02b25f55883b387a334b4fd85dfb9ea831a (diff) | |
download | egovutils-f7c97e3423fa51f9f3d32f0285f2468d95d5987d.tar.gz egovutils-f7c97e3423fa51f9f3d32f0285f2468d95d5987d.tar.bz2 egovutils-f7c97e3423fa51f9f3d32f0285f2468d95d5987d.zip |
add first version of SZR client v4.0
Diffstat (limited to 'src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java')
-rw-r--r-- | src/main/java/at/gv/util/client/pvp/rprofile/Pvp2xHttpHeaderHandler.java | 188 |
1 files changed, 188 insertions, 0 deletions
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<SOAPMessageContext> { + + private PvpTokenType pvpTokenType = null; + + private Logger log = LoggerFactory.getLogger(Pvp2xHttpHeaderHandler.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 = ";"; + + 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<String, List> headers = (Map<String, List>) 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<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; + } + } + + 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<QName> getHeaders() { + return null; + } + private void setHeader(Map<String, List> headers, String name, String value) { + if (MiscUtil.isEmpty(value)) + headers.put(name, Collections.singletonList(StringUtils.EMPTY)); + else + headers.put(name, Collections.singletonList(value)); + + } + +} |