From a6d06a04fdd2caaebb387be3d85107658c08f345 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Tue, 6 May 2014 19:34:59 +0200 Subject: change --- .../protocols/stork2/MandateRetrievalRequest.java | 206 +++++++++++++-------- 1 file changed, 124 insertions(+), 82 deletions(-) (limited to 'id/server/idserverlib/src/main') diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java index 6e8262eef..662baa3c9 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java @@ -12,13 +12,21 @@ import eu.stork.peps.auth.commons.IPersonalAttributeList; import eu.stork.peps.auth.commons.PersonalAttribute; import eu.stork.peps.auth.commons.PersonalAttributeList; import eu.stork.peps.auth.commons.STORKAttrQueryResponse; -import eu.stork.peps.complex.attributes.MandateContentType; -import eu.stork.peps.complex.attributes.MandateType; -import eu.stork.peps.complex.attributes.RepresentationPersonType; +import eu.stork.peps.complex.attributes.*; +import org.apache.xerces.impl.dv.DatatypeException; import org.w3c.dom.Node; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Marshaller; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.QName; +import java.io.StringWriter; +import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -85,43 +93,44 @@ public class MandateRetrievalRequest implements IAction { IPersonalAttributeList attributeList = new PersonalAttributeList(); for (PersonalAttribute currentAttribute : sourceAttributeList) { - Logger.debug("Evaluationg currentattribute " + currentAttribute.getName()); + Logger.debug("Evaluating currentattribute " + currentAttribute.getName()); if (currentAttribute.getName().equals("mandateContent")) { - attributeList.add(getMandateContent(mandateContainer, currentAttribute)); - } - if (currentAttribute.getName().equals("representative")) { - attributeList.add(getRepresentative(mandateContainer, currentAttribute)); - } - if (currentAttribute.getName().equals("represented")) { - attributeList.add(getRepresented(mandateContainer, currentAttribute)); - } + MandateContentType mandateContent = getMandateContent(mandateContainer, currentAttribute); + attributeList.add(marshallComplexAttribute(currentAttribute, mandateContent)); + // final Marshaller marshaller = JAXBContext.newInstance(MandateContentType.class).createMarshaller(); + // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - if (currentAttribute.getName().equals("representative")) { - PersonalAttribute personalAttribute = new PersonalAttribute(); - List x = new ArrayList(); - x.add("12345234k32jekqwjeqwe"); - HashMap complexValue = new HashMap(); + // StringWriter stringWriter = new StringWriter(); - if (mandateContainer instanceof CorporateBodyMandateContainer) { + // marshaller.marshal(new JAXBElement(new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", "mandateContent"), MandateContentType.class, null, mandateContent), stringWriter); - } else if (mandateContainer instanceof PhyPersonMandateContainer) { - } + // ArrayList value = new ArrayList(); + // value.add(stringWriter.toString()); - complexValue.put("eIdentifier","12345"); - complexValue.put("givenName", "Name"); - complexValue.put("surname", "surname"); - complexValue.put("dateOfBirth", "1.1.1."); + // PersonalAttribute mandateContentAttribute = new PersonalAttribute("mandateContent", false, value, "Available"); - personalAttribute.setName(currentAttribute.getName()); - personalAttribute.setFriendlyName(currentAttribute.getFriendlyName()); - personalAttribute.setIsRequired(currentAttribute.isRequired()); - personalAttribute.setComplexValue(complexValue); - personalAttribute.setStatus("Available"); - attributeList.add(personalAttribute); - Logger.debug("Setting currentattribute " + currentAttribute.getName()); + // attributeList.add(mandateContentAttribute); + } else + if (currentAttribute.getName().equals("representative")) { // TODO CHECK + RepresentationPersonType representative = getRepresentative(mandateContainer, currentAttribute); + attributeList.add(marshallComplexAttribute(currentAttribute, representative)); + + //attributeList.add(getRepresentative(mandateContainer, currentAttribute)); + } else + if (currentAttribute.getName().equals("represented")) { + //attributeList.add(getRepresented(mandateContainer, currentAttribute)); + RepresentationPersonType represented = getRepresented(mandateContainer, currentAttribute); + attributeList.add(marshallComplexAttribute(currentAttribute, represented)); + + } else + if (currentAttribute.getName().equals("mandateType")) { + //attributeList.add(getMandateType(mandateContainer, currentAttribute)); + MandateType mandateType = getMandateType(mandateContainer, currentAttribute); + attributeList.add(marshallComplexAttribute(currentAttribute, mandateType)); } + } attrResponse.setPersonalAttributeList(attributeList); @@ -159,6 +168,38 @@ public class MandateRetrievalRequest implements IAction { return null; // } + private PersonalAttribute marshallComplexAttribute(PersonalAttribute currentAttribute, Object obj) { // TODO refactor + + + StringWriter stringWriter = new StringWriter(); + try { + if (obj instanceof MandateContentType) { + final Marshaller marshaller = JAXBContext.newInstance(MandateContentType.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(new JAXBElement(new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), MandateContentType.class, null, (MandateContentType)obj), stringWriter); + } else if (obj instanceof MandateType) { + final Marshaller marshaller = JAXBContext.newInstance(MandateType.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(new JAXBElement(new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), MandateType.class, null, (MandateType)obj), stringWriter); + } else if (obj instanceof RepresentationPersonType) { + final Marshaller marshaller = JAXBContext.newInstance(RepresentationPersonType.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(new JAXBElement(new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", currentAttribute.getName()), RepresentationPersonType.class, null, (RepresentationPersonType)obj), stringWriter); + } + + } catch (Exception ex) { + Logger.error("Could not marshall atrribute: " + currentAttribute.getName() + ", " + ex.getMessage()); + return new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), new ArrayList(), "NotAvailable"); + } + ArrayList value = new ArrayList(); + value.add(stringWriter.toString()); + + PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), value, "Available"); + + return personalAttribute; + } + + private void populateMandatingData(AuthenticationSession moasession) { MandateType mandateType = new MandateType(); RepresentationPersonType representationPersonType = new RepresentationPersonType(); @@ -224,81 +265,82 @@ public class MandateRetrievalRequest implements IAction { return ""; } - private PersonalAttribute getRepresentative(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { - PersonalAttribute personalAttribute = new PersonalAttribute(); - HashMap complexValue = new HashMap(); + private MandateType getMandateType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + MandateType mandateType = new MandateType(); + RepresentationPersonType representative = getRepresentative(mandateContainer, sourceAttribute); + RepresentationPersonType represented = getRepresented(mandateContainer, sourceAttribute); + MandateContentType mandateContent = getMandateContent(mandateContainer, sourceAttribute); + mandateType.setRepresenting(representative); + mandateType.setRepresented(represented); + mandateType.setMandateContent(mandateContent); + Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); + return mandateType; + } + + + private RepresentationPersonType getRepresentative(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + RepresentationPersonType representative = new RepresentationPersonType(); if (mandateContainer instanceof CorporateBodyMandateContainer) { Logger.error("Company as representative not supported"); // TODO } else if (mandateContainer instanceof PhyPersonMandateContainer) { PhyPersonMandateContainer phyPersonMandateContainer = (PhyPersonMandateContainer)mandateContainer; - complexValue.put("eIdentifier", ""); // TODO CALCULATE - complexValue.put("givenName", phyPersonMandateContainer.getPhysicalRepresentativeGivenName()); - complexValue.put("surname", phyPersonMandateContainer.getPhysicalRepresentativeFamilyName()); - complexValue.put("dateOfBirth", phyPersonMandateContainer.getPhysicalRepresentativeBirthDate()); + representative.setEIdentifier(""); // TODO CALCULATE + representative.setGivenName(phyPersonMandateContainer.getPhysicalRepresentativeGivenName()); + representative.setSurname(phyPersonMandateContainer.getPhysicalRepresentativeFamilyName()); + representative.setDateOfBirth(phyPersonMandateContainer.getPhysicalRepresentativeBirthDate()); } - personalAttribute.setName(sourceAttribute.getName()); - personalAttribute.setFriendlyName(sourceAttribute.getFriendlyName()); - personalAttribute.setIsRequired(sourceAttribute.isRequired()); - personalAttribute.setComplexValue(complexValue); - personalAttribute.setStatus("Available"); - Logger.debug("Complex attribute extracted: " + personalAttribute.getName()); - - return personalAttribute; + Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); + return representative; } - private PersonalAttribute getRepresented(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { - PersonalAttribute personalAttribute = new PersonalAttribute(); - HashMap complexValue = new HashMap(); + private RepresentationPersonType getRepresented(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + RepresentationPersonType represented = new RepresentationPersonType(); if (mandateContainer instanceof CorporateBodyMandateContainer) { CorporateBodyMandateContainer corporateBodyMandateContainer = (CorporateBodyMandateContainer)mandateContainer; - complexValue.put("eLPIdentifier", corporateBodyMandateContainer.getCorpMandatorIdentificationValue()); - complexValue.put("name", corporateBodyMandateContainer.getCorpMandatorFullName()); - complexValue.put("address", ""); - complexValue.put("canonicalAddress", ""); - complexValue.put("type", mapCompanyType(mandateContainer)); + represented.setELPIdentifier(corporateBodyMandateContainer.getCorpMandatorIdentificationValue()); + represented.setName(corporateBodyMandateContainer.getCorpMandatorFullName()); + represented.setAddress(""); + represented.setCanonicalAddress(new CanonicalAddressType()); + represented.setType(mapCompanyType(mandateContainer)); // TODO } else if (mandateContainer instanceof PhyPersonMandateContainer) { PhyPersonMandateContainer phyPersonMandateContainer = (PhyPersonMandateContainer)mandateContainer; - complexValue.put("eIdentifier", ""); // TODO CALCULATE - complexValue.put("givenName", phyPersonMandateContainer.getPhyPersMandatorGivenName()); - complexValue.put("surname", phyPersonMandateContainer.getPhyPersMandatorFamilyName()); - complexValue.put("dateOfBirth", phyPersonMandateContainer.getPhyPersMandatorBirthDate()); + represented.setEIdentifier(""); // TODO CALCULATE + represented.setGivenName(phyPersonMandateContainer.getPhyPersMandatorGivenName()); + represented.setSurname(phyPersonMandateContainer.getPhyPersMandatorFamilyName()); + represented.setDateOfBirth(phyPersonMandateContainer.getPhyPersMandatorBirthDate()); } - personalAttribute.setName(sourceAttribute.getName()); - personalAttribute.setFriendlyName(sourceAttribute.getFriendlyName()); - personalAttribute.setIsRequired(sourceAttribute.isRequired()); - personalAttribute.setComplexValue(complexValue); - personalAttribute.setStatus("Available"); - Logger.debug("Complex attribute extracted: " + personalAttribute.getName()); + Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); - return personalAttribute; + return represented; } - private PersonalAttribute getMandateContent(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { - PersonalAttribute personalAttribute = new PersonalAttribute(); - HashMap complexValue = new HashMap(); + private MandateContentType getMandateContent(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + MandateContentType mandateContent = new MandateContentType(); + try { + XMLGregorianCalendar validFrom = DatatypeFactory.newInstance().newXMLGregorianCalendar(mandateContainer.getMandateValidFrom()); - complexValue.put("validFrom", mandateContainer.getMandateValidFrom()); - complexValue.put("validTo", mandateContainer.getMandateValidTo()); - complexValue.put("transactionLimit", "0"); // TODO - complexValue.put("transactionLimitCurrency", ""); // TODO - complexValue.put("isJoint", ""); - complexValue.put("isChained", "false"); - complexValue.put("typePower", mapPowersType(mandateContainer)); + XMLGregorianCalendar validTo = DatatypeFactory.newInstance().newXMLGregorianCalendar(mandateContainer.getMandateValidTo()); + mandateContent.setValidFrom(validFrom); + mandateContent.setValidTo(validTo); + } catch (DatatypeConfigurationException dte) { + Logger.error("Error converting data from mandate"); + throw new MOAIDException("stork.16", new Object[] {}); // TODO - personalAttribute.setName(sourceAttribute.getName()); - personalAttribute.setFriendlyName(sourceAttribute.getFriendlyName()); - personalAttribute.setIsRequired(sourceAttribute.isRequired()); - personalAttribute.setComplexValue(complexValue); - personalAttribute.setStatus("Available"); - Logger.debug("Complex attribute extracted: " + personalAttribute.getName()); + } - return personalAttribute; + mandateContent.setTransactionLimit(BigInteger.valueOf(0)); // TODO + mandateContent.setTransactionLimitCurrency("");// TODO + mandateContent.setIsJoint(""); + mandateContent.setIschained(false); + mandateContent.setTypePower(mapPowersType(mandateContainer)); + Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); + return mandateContent; } public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { -- cgit v1.2.3