From 2c3c1d6bb748a0655a83fdf4cd26135042d898b9 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 19 Jul 2019 10:35:29 +0200 Subject: USP client integration switch to v2.0.7 --- .../at/gv/util/client/mis/usp_v2/USPClient.java | 171 +++++++++++++------ .../util/client/mis/usp_v2/USPClientException.java | 14 +- .../mis/usp_v2/VDDSRoleGenerationStrategy.java | 83 +++++++++ .../util/client/szr/IRoleGenerationStrategy.java | 15 ++ .../gv/util/client/szr/PVP2XHTTPHeaderHandler.java | 188 +++++++++++++++++++++ src/main/java/at/gv/util/client/szr/SZRClient.java | 4 +- .../gv/util/client/szr/SZRHTTPHeaderHandler.java | 138 --------------- 7 files changed, 410 insertions(+), 203 deletions(-) create mode 100644 src/main/java/at/gv/util/client/mis/usp_v2/VDDSRoleGenerationStrategy.java create mode 100644 src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java create mode 100644 src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java delete mode 100644 src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java (limited to 'src/main/java/at/gv/util/client') 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 4d23a1e..7bbdef9 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 @@ -1,7 +1,9 @@ package at.gv.util.client.mis.usp_v2; import java.net.URL; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; @@ -23,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.SZRHTTPHeaderHandler; +import at.gv.util.client.szr.PVP2XHTTPHeaderHandler; import at.gv.util.config.EgovUtilConfiguration; import at.gv.util.ex.EgovUtilException; import at.gv.util.wsdl.mis.usp_v2.ISyncService; @@ -32,18 +34,31 @@ import at.gv.util.wsdl.mis.usp_v2.SynchronisationServiceServiceagent; 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.mis.usp_v2.eai.syncmsgs.MandateList; +import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.MandateListType; +import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.ObjectFactory; +import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.SearchCriteriaTestType; +import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.SearchCriteriaType; +import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.TimeRangeType; +import at.gv.util.xsd.mis.usp_v2.mandates.Mandate; +import at.gv.util.xsd.mis.usp_v2.persondata.IdentificationType; +import at.gv.util.xsd.mis.usp_v2.persondata.IdentificationType.Value; import at.gv.util.xsd.szr.pvp.PvpTokenType; public class USPClient { - @Resource - WebServiceContext wsContext; + public static final String USP_DATE_PATTERN = "yyyy-MM-dd"; + + + @Resource WebServiceContext wsContext; private EgovUtilConfiguration config = null; private Logger log = LoggerFactory.getLogger(USPClient.class); private boolean logEnabled = true; private ISyncService uspSuche = null; + private SimpleDateFormat formater; + public USPClient(EgovUtilConfiguration config, boolean logEnabled) throws EgovUtilException { MiscUtil.assertNotNull(config, "config"); this.config = config; @@ -51,65 +66,100 @@ public class USPClient { initialize(); } -// public GetMandatesResponse getMandates(String bpkType, String bpkValue, List mandateFilters) { -// -// // assemble request -// GetMandatesRequest request = new GetMandatesRequest(); -// String requestId = createUSPRequestId(); -// log.debug("USP request id: " + requestId); -// request.setRequestId(requestId); -// Date date = new Date(); -// try { -// request.setTimestamp(MiscUtil.getXMLGregorianCalendar(date)); -// } catch (DatatypeConfigurationException e) { -// log.warn("Error initializing USP client.", e); -// return null; -// } -// log.debug("USP time stamp: " + date.toString()); -// request.setApplicationId(config.getUSPApplicationId()); -// log.debug("USP application id: " + config.getUSPApplicationId()); -// -// // set identification -// IdentificationType idt = new IdentificationType(); -// idt.setType(bpkType); -// idt.setValue(bpkValue); -// request.setIdentification(idt); -// -// // set filters -// if (mandateFilters != null && mandateFilters.size() > 0) { -// MandateFilters mf = new MandateFilters(); -// mf.getMandateFilter().addAll(mandateFilters); -// request.setMandateFilters(mf); -// } -// -// return this.uspSuche.getMandatesOperation(request); -// -// -// } - - public void getMandates(String bpkType, String bpkValue, List mandateFilters) { - ListMandatesRequest parameters = new ListMandatesRequest(); - - MandateAttributesSearchFilterType searchFilterType = new MandateAttributesSearchFilterType(); - - Object searchFilter = null; - searchFilterType.setFilter(searchFilter ); - - + public List getMandates(String bpkType, String bpkValue, List mandateFilters) throws Exception { - //request USP try { - log.trace("Request pre-processing finished. Requesting USP ... "); - - ListMandatesResponseType results = this.uspSuche.listMandates(parameters ); + if (mandateFilters.size() > 1) + log.debug("More than one mandate-profile required. Request each profile seperatly"); + + List results = new ArrayList(); + for (String mandateFilter : mandateFilters) { + log.trace("Building USP VDDS request ... "); + ListMandatesRequest req = generateRequest(bpkType, bpkValue, mandateFilter); - log.trace("Receive response from USP. Starting response post-processing ... "); + log.trace("Request pre-processing finished. Requesting USP ... "); + ListMandatesResponseType resp = this.uspSuche.listMandates(req ); + + log.trace("Receive response from USP for filter:" + mandateFilter + " . Start post processing ... "); + postProcessUSPMandateResult(resp, results); + + } + return results; + } catch (ListMandatesFault e) { - // TODO Auto-generated catch block - e.printStackTrace(); + log.warn("Receive an error from USP. Msg: " + e.getMessage(), e); + throw e; + + } catch (Exception e) { + log.error("Catch an generic error during USP communication.", e); + throw e; + } + + } + + private void postProcessUSPMandateResult(ListMandatesResponseType resp, List results) throws USPClientException { + if (resp.getSearchResult() != null) { + if (resp.getSearchResult().getDeclaredType().isAssignableFrom(MandateList.class)) { + log.trace("Find 'MandateList' element in USP response"); + MandateList mandateList = (MandateList) resp.getSearchResult().getValue(); + + if (mandateList.getMandates() != null && mandateList.getMandates().getMandate() != null) { + log.debug("Find #" + mandateList.getMandates().getMandate().size() + " mandates in USP response"); + results.addAll(mandateList.getMandates().getMandate()); + + } else + log.info("Find 'null' element in USP response. Ignore full response"); + } else + log.warn("'SearchResult' element in USP response contains an unknown type: " + resp.getSearchResult().getName().toString()); + + } else { + log.debug("'SearchResult' element in USP response is 'null' Inspecting response on errors ..."); + if (resp.getResult() != null) { + String errorCode = resp.getResult().getErrorCode(); + String errorMsg = resp.getResult().getErrorMessage(); + if (MiscUtil.isNotEmpty(errorCode) || MiscUtil.isNotEmpty(errorMsg)) { + log.info("Receice an error from USP! Code: " + errorCode + " Msg: " + errorMsg); + throw new USPClientException(errorMsg, errorCode); + } + + } + } + + } + + private ListMandatesRequest generateRequest(String bpkType, String bpkValue, String mandateFilter) { + ObjectFactory objFactory = new ObjectFactory(); + + ListMandatesRequest parameters = new ListMandatesRequest(); + MandateAttributesSearchFilterType searchFilterType = new MandateAttributesSearchFilterType(); + SearchCriteriaTestType searchCriteriaTest = new SearchCriteriaTestType(); + SearchCriteriaType searchCriteria = new SearchCriteriaType(); + IdentificationType representative = new IdentificationType(); + Value IdValue = new Value(); + + //set bPK + IdValue.setValue(bpkValue); + representative.setValue(IdValue ); + representative.setType(bpkType); + searchCriteria.getActivationRangeOrMandateTypeOrMandatorID().add(objFactory.createSearchCriteriaTypeRepresentativeID(representative)); + + //set allowed time range + TimeRangeType fromTo = new TimeRangeType(); + fromTo.setFrom(formater.format(new Date())); + fromTo.setTo("9999-12-31"); + searchCriteria.getActivationRangeOrMandateTypeOrMandatorID().add(objFactory.createSearchCriteriaTypeValidFromTo(fromTo)); + + //set mandate filters + searchCriteria.getActivationRangeOrMandateTypeOrMandatorID().add(objFactory.createSearchCriteriaTypeMandateType(mandateFilter)); + + searchCriteriaTest.setSearchCriteria(searchCriteria); + searchFilterType.setFilter(searchCriteriaTest); + parameters.getSearchFilter().add(objFactory.createMandateAttributesSearchFilter(searchFilterType)); + + return parameters; } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -141,7 +191,13 @@ public class USPClient { // PV authentication log.trace("Adding WS-Security Header handler."); PvpTokenType pvpToken = config.getUSPPVPToken(); - SZRHTTPHeaderHandler szrSOAPHandler = new SZRHTTPHeaderHandler(); + + VDDSRoleGenerationStrategy roleStrategy = new VDDSRoleGenerationStrategy( + config.getConfigurationValue("egovutil.usp.role.dynamic.participant"), + config.getConfigurationValue("egovutil.usp.role.dynamic.secret")); + + + PVP2XHTTPHeaderHandler szrSOAPHandler = new PVP2XHTTPHeaderHandler(roleStrategy); szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); @@ -183,6 +239,9 @@ public class USPClient { } http.setTlsClientParameters(tlsParams ); } + + formater = new SimpleDateFormat(USP_DATE_PATTERN); + } private String createUSPRequestId() { diff --git a/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java b/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java index 96ad965..4b2302b 100644 --- a/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java +++ b/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java @@ -4,29 +4,29 @@ public class USPClientException extends Exception { private static final long serialVersionUID = 5173056345209288701L; - private int code = -1; + private String code; - public USPClientException(int code) { + public USPClientException(String code) { super(); this.code = code; } - public USPClientException(String message, int code, Throwable cause) { + public USPClientException(String message, String code, Throwable cause) { super(message, cause); this.code = code; } - public USPClientException(String message, int code) { + public USPClientException(String message, String errorCode) { super(message); - this.code = code; + this.code = errorCode; } - public USPClientException(int code, Throwable cause) { + public USPClientException(String code, Throwable cause) { super(cause); this.code = code; } - public int getCode() { + public String getCode() { return this.code; } 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 new file mode 100644 index 0000000..c5573d3 --- /dev/null +++ b/src/main/java/at/gv/util/client/mis/usp_v2/VDDSRoleGenerationStrategy.java @@ -0,0 +1,83 @@ +package at.gv.util.client.mis.usp_v2; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.Base64; +import java.util.Date; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.util.MiscUtil; +import at.gv.util.client.szr.IRoleGenerationStrategy; +import at.gv.util.ex.EgovUtilException; + +public class VDDSRoleGenerationStrategy implements IRoleGenerationStrategy { + private static final Logger log = LoggerFactory.getLogger(VDDSRoleGenerationStrategy.class); + + public static final String ROLE_CONSTANT_PARTNERNAME = "partner-name="; + public static final String ROLE_CONSTANT_SECRET = "secret="; + public static final String ROLE_CONSTANT_CREATIONTS = "creation-ts="; + + public static final String TS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; + private static final SimpleDateFormat tsFormat = new SimpleDateFormat(TS_PATTERN); + + private String participant; + private String authData; + + public VDDSRoleGenerationStrategy(String participant, String authData) throws EgovUtilException { + if (MiscUtil.isEmpty(authData)) { + log.error("Secret to generate VDDS role is 'null or 'empty''"); + throw new EgovUtilException("Secret to generate VDDS role is 'null or 'empty'"); + + } + this.authData = authData; + + if (MiscUtil.isEmpty(participant)) { + log.error("Participant to generate VDDS role is 'null or 'empty''"); + throw new EgovUtilException("Secret to generate VDDS role is 'null or 'empty'"); + + } + this.participant = participant; + + log.trace("VDDSRoleGenerationStrategy uses participant: " + this.participant + " and secret: " + this.authData); + + } + + @Override + public String generateRoleString(String roleString) throws EgovUtilException { + + try { + String currentTS = tsFormat.format(new Date()); + log.trace("Generate VDDS role at: " + currentTS); + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] digistInput = (currentTS + authData).getBytes("UTF-8"); + log.trace("DigistInput: " + new String(digistInput, "UTF-8")); + byte[] digistOutput = md.digest(digistInput); + String secret = Base64.getEncoder().encodeToString(digistOutput); + + StringBuilder sBuilder = new StringBuilder(roleString); + sBuilder.append("("); + sBuilder.append(ROLE_CONSTANT_PARTNERNAME); + sBuilder.append(participant); + sBuilder.append(","); + sBuilder.append(ROLE_CONSTANT_SECRET); + sBuilder.append(secret); + sBuilder.append(","); + sBuilder.append(ROLE_CONSTANT_CREATIONTS); + sBuilder.append(currentTS); + sBuilder.append(")"); + + log.trace("Finale VDDS Role: " + sBuilder.toString()); + return sBuilder.toString(); + + } catch(NoSuchAlgorithmException | UnsupportedEncodingException e) { + log.error("VDDSRoleGeneration FAILED with error: " + e.getMessage(), e); + throw new EgovUtilException("VDDSRoleGeneration FAILED", e); + + } + } + +} diff --git a/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java b/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java new file mode 100644 index 0000000..d411f21 --- /dev/null +++ b/src/main/java/at/gv/util/client/szr/IRoleGenerationStrategy.java @@ -0,0 +1,15 @@ +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 new file mode 100644 index 0000000..f4fc11b --- /dev/null +++ b/src/main/java/at/gv/util/client/szr/PVP2XHTTPHeaderHandler.java @@ -0,0 +1,188 @@ +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 ad54d2f..67813bd 100644 --- a/src/main/java/at/gv/util/client/szr/SZRClient.java +++ b/src/main/java/at/gv/util/client/szr/SZRClient.java @@ -104,7 +104,7 @@ public class SZRClient { } - public String transformBPK(PersonInfoType personInfo, String inputBpk, String inputTarget, String target, String vkz) throws SZRException, EgovUtilException { + 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+"; @@ -135,7 +135,7 @@ public class SZRClient { if (response == null) { return null; } - return response.get(0).getFremdBPK(); + return response.get(0); } @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java b/src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java deleted file mode 100644 index bde6b7b..0000000 --- a/src/main/java/at/gv/util/client/szr/SZRHTTPHeaderHandler.java +++ /dev/null @@ -1,138 +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.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 { - - private PvpTokenType pvpTokenType = null; - - private Logger log = LoggerFactory.getLogger(SZRHTTPHeaderHandler.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 = ";"; - - 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); - 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 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; - } - } - 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 getHeaders() { - return null; - } - private void setHeader(Map headers, String name, String value) { - if (MiscUtil.isEmpty(value)) - headers.put(name, null); - else - headers.put(name, Collections.singletonList(value)); - - } - -} -- cgit v1.2.3