diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2014-05-09 12:10:28 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2014-05-09 12:10:28 +0200 |
commit | bb06ad890498e2428c3f4268ae2f732a0f75bd77 (patch) | |
tree | d5a422144d55c96a0e87965ecc6ce036080d7133 /id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java | |
parent | c44e10f563cae97ce3c4a64f7ba3e8777e131a0d (diff) | |
parent | a6d06a04fdd2caaebb387be3d85107658c08f345 (diff) | |
download | moa-id-spss-bb06ad890498e2428c3f4268ae2f732a0f75bd77.tar.gz moa-id-spss-bb06ad890498e2428c3f4268ae2f732a0f75bd77.tar.bz2 moa-id-spss-bb06ad890498e2428c3f4268ae2f732a0f75bd77.zip |
merge VIDP updates to Snapshot branch
Conflicts:
id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java
id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java
id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java')
-rw-r--r-- | id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateRetrievalRequest.java | 329 |
1 files changed, 328 insertions, 1 deletions
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 dea74aa75..0d0391e3c 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 @@ -1,24 +1,349 @@ package at.gv.egovernment.moa.id.protocols.stork2; import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; +import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; import at.gv.egovernment.moa.id.auth.exception.MOAIDException; import at.gv.egovernment.moa.id.data.SLOInformationInterface; +import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider; +import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.id.moduls.IAction; import at.gv.egovernment.moa.id.moduls.IRequest; import at.gv.egovernment.moa.logging.Logger; +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.*; +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; /** * */ public class MandateRetrievalRequest implements IAction { + + private AuthenticationSession moaSession; + private MOASTORKRequest moaStorkRequest; + public SLOInformationInterface processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, AuthenticationSession moasession) throws MOAIDException { - Logger.info("Entering mandateretrievalrequest"); + Logger.debug("Entering AttributeRequest for MandateProvider"); + httpResp.reset(); + OAAuthParameter oaParam = AuthConfigurationProvider.getInstance().getOnlineApplicationParameter(moasession.getPublicOAURLPrefix()); + if (oaParam == null) + throw new AuthenticationException("stork.12", new Object[]{moasession.getPublicOAURLPrefix()}); + + MOASTORKResponse moaStorkResponse = new MOASTORKResponse(); + STORKAttrQueryResponse attrResponse = new STORKAttrQueryResponse(); + + this.moaSession = moasession; + + if ((req instanceof MOASTORKRequest)) { + this.moaStorkRequest = (MOASTORKRequest) req; + + } else { + return null; // TODO + } + + + if (moaStorkRequest.isAttrRequest() && moaStorkRequest.getStorkAttrQueryRequest() != null) { + MandateContainer mandateContainer = null; + + try { + mandateContainer = new CorporateBodyMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); + } catch (Exception ex) { + try { + mandateContainer = new PhyPersonMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); + } catch (Exception ex2) { + Logger.error("Could not extract data and create mandate container."); + throw new MOAIDException("stork.16", new Object[] {}); // TODO + } + } + + if (mandateContainer instanceof CorporateBodyMandateContainer) { + + } else if (mandateContainer instanceof PhyPersonMandateContainer) { + + } + + + + + + +// moaStorkResponse.setPersonalAttributeList(populateAttributes()); + + //moaStorkResponse.setCountry(moaStorkRequest.getSpCountry()); + + IPersonalAttributeList sourceAttributeList = moaStorkRequest.getStorkAttrQueryRequest().getPersonalAttributeList(); + + IPersonalAttributeList attributeList = new PersonalAttributeList(); + + for (PersonalAttribute currentAttribute : sourceAttributeList) { + Logger.debug("Evaluating currentattribute " + currentAttribute.getName()); + if (currentAttribute.getName().equals("mandateContent")) { + 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); + + // StringWriter stringWriter = new StringWriter(); + + // marshaller.marshal(new JAXBElement<MandateContentType>(new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", "mandateContent"), MandateContentType.class, null, mandateContent), stringWriter); + + // ArrayList<String> value = new ArrayList<String>(); + // value.add(stringWriter.toString()); + + // PersonalAttribute mandateContentAttribute = new PersonalAttribute("mandateContent", false, value, "Available"); + + // 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); + moaStorkResponse.setSTORKAttrResponse(attrResponse); + + Logger.debug("Attributes " + moaStorkResponse.getStorkAttrQueryResponse().getPersonalAttributeList().size()); + + // Prepare extended attributes + Logger.debug("Preparing data container"); + + // create fresh container + DataContainer container = new DataContainer(); + + // - fill in the request we extracted above + container.setRequest(moaStorkRequest); + + // - fill in the partial response created above + container.setResponse(moaStorkResponse); + + container.setRemoteAddress(httpReq.getRemoteAddr()); + + Logger.debug("Data container prepared"); + + // ask for consent if necessary + if (oaParam.isRequireConsentForStorkAttributes()) + new ConsentEvaluator().requestConsent(container, httpResp, oaParam); + else + new ConsentEvaluator().generateSTORKResponse(httpResp, container); + + + //return (new AttributeCollector()).processRequest(container, httpReq, httpResp, moasession, oaParam); + } + + 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<MandateContentType>(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<MandateType>(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<RepresentationPersonType>(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<String>(), "NotAvailable"); + } + ArrayList<String> value = new ArrayList<String>(); + 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(); + MandateContentType mandateContentType = new MandateContentType(); + } + + + private void populateRepresented(AuthenticationSession moasession) { + + MandateContainer mc = null; + + try { + mc = new CorporateBodyMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); + } catch (Exception ex) { + Logger.error("CORPORATE ERROR"); + try { + mc = new PhyPersonMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); + } catch (Exception ex2) { + Logger.error("PERSON ERROR"); + } + } + + if (mc instanceof CorporateBodyMandateContainer) { + Logger.error("Instance of Corp"); + } else if (mc instanceof PhyPersonMandateContainer) { + Logger.error("Instance of Phy"); + } + + + } + + + private Node extractChildNode(Node node, String childName) throws MOAIDException { + if (!node.hasChildNodes()) { + throw new MOAIDException("stork.11", null); // TODO description + } + for (int n = 0; n < node.getChildNodes().getLength(); n++) { + if (node.getChildNodes().item(n).getNodeName().equals(childName)) { + return node.getChildNodes().item(n); + } + } + throw new MOAIDException("stork.11", null); // TODO description + + } + + private String extractNodeTextContent(Node node, String childName) throws MOAIDException { + if (!node.hasChildNodes()) { + throw new MOAIDException("stork.11", null); // TODO description + } + for (int n = 0; n < node.getChildNodes().getLength(); n++) { + if (node.getChildNodes().item(n).getNodeName().equals(childName)) { + return node.getTextContent(); + } + } + throw new MOAIDException("stork.11", null); // TODO description + } + + private String mapPowersType(MandateContainer mandateContainer) { // TODO + return ""; + } + + private String mapCompanyType(MandateContainer mandateContainer) { // TODO + return ""; + } + + 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; + representative.setEIdentifier(""); // TODO CALCULATE + representative.setGivenName(phyPersonMandateContainer.getPhysicalRepresentativeGivenName()); + representative.setSurname(phyPersonMandateContainer.getPhysicalRepresentativeFamilyName()); + representative.setDateOfBirth(phyPersonMandateContainer.getPhysicalRepresentativeBirthDate()); + } + + Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); + return representative; + } + + private RepresentationPersonType getRepresented(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + RepresentationPersonType represented = new RepresentationPersonType(); + + if (mandateContainer instanceof CorporateBodyMandateContainer) { + CorporateBodyMandateContainer corporateBodyMandateContainer = (CorporateBodyMandateContainer)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; + represented.setEIdentifier(""); // TODO CALCULATE + represented.setGivenName(phyPersonMandateContainer.getPhyPersMandatorGivenName()); + represented.setSurname(phyPersonMandateContainer.getPhyPersMandatorFamilyName()); + represented.setDateOfBirth(phyPersonMandateContainer.getPhyPersMandatorBirthDate()); + } + + Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); + + return represented; + } + + + private MandateContentType getMandateContent(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + MandateContentType mandateContent = new MandateContentType(); + try { + XMLGregorianCalendar validFrom = DatatypeFactory.newInstance().newXMLGregorianCalendar(mandateContainer.getMandateValidFrom()); + + 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 + + } + + 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) { return true; // } @@ -26,4 +351,6 @@ public class MandateRetrievalRequest implements IAction { public String getDefaultActionName() { return STORKProtocol.MANDATERETRIEVALREQUEST; } + + } |