From 3eece09e3a24b383a7dcdb1737e4eb97990c67df Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Mon, 5 May 2014 18:11:54 +0200 Subject: puting attributes in main section --- .../protocols/stork2/MandateRetrievalRequest.java | 179 ++++++++++++++++++--- 1 file changed, 154 insertions(+), 25 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 d216f716c..6e8262eef 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 @@ -19,8 +19,8 @@ import org.w3c.dom.Node; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -32,7 +32,14 @@ public class MandateRetrievalRequest implements IAction { private MOASTORKRequest moaStorkRequest; public String processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, AuthenticationSession moasession) throws MOAIDException { - Logger.error("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; @@ -45,18 +52,29 @@ public class MandateRetrievalRequest implements IAction { if (moaStorkRequest.isAttrRequest() && moaStorkRequest.getStorkAttrQueryRequest() != null) { - populateRepresented(moasession); + 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) { + + } + - 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(); // moaStorkResponse.setPersonalAttributeList(populateAttributes()); @@ -69,15 +87,38 @@ public class MandateRetrievalRequest implements IAction { for (PersonalAttribute currentAttribute : sourceAttributeList) { Logger.debug("Evaluationg currentattribute " + currentAttribute.getName()); if (currentAttribute.getName().equals("mandateContent")) { - PersonalAttribute mandateContent = new PersonalAttribute(); + 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)); + } + + + if (currentAttribute.getName().equals("representative")) { + PersonalAttribute personalAttribute = new PersonalAttribute(); List x = new ArrayList(); x.add("12345234k32jekqwjeqwe"); - mandateContent.setName(currentAttribute.getName()); - mandateContent.setFriendlyName(currentAttribute.getFriendlyName()); - mandateContent.setIsRequired(currentAttribute.isRequired()); - mandateContent.setValue(x); - mandateContent.setStatus("Available"); - attributeList.add(mandateContent); + HashMap complexValue = new HashMap(); + + if (mandateContainer instanceof CorporateBodyMandateContainer) { + + } else if (mandateContainer instanceof PhyPersonMandateContainer) { + } + + complexValue.put("eIdentifier","12345"); + complexValue.put("givenName", "Name"); + complexValue.put("surname", "surname"); + complexValue.put("dateOfBirth", "1.1.1."); + + 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()); } @@ -127,19 +168,26 @@ public class MandateRetrievalRequest implements IAction { private void populateRepresented(AuthenticationSession moasession) { + MandateContainer mc = null; + try { - CorporateBodyMandateContainer corporateBodyMandateContainer = new CorporateBodyMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); + mc = new CorporateBodyMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); } catch (Exception ex) { - Logger.error("CORPORATE ERROR"); + Logger.error("CORPORATE ERROR"); + try { + mc = new PhyPersonMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); + } catch (Exception ex2) { + Logger.error("PERSON ERROR"); + } } - - try { - PhyPersonMandateContainer phyPersonMandateContainer = new PhyPersonMandateContainer(new String(moaSession.getMISMandate().getMandate(), "UTF-8")); - } catch (Exception ex) { - Logger.error("PERSON ERROR"); + if (mc instanceof CorporateBodyMandateContainer) { + Logger.error("Instance of Corp"); + } else if (mc instanceof PhyPersonMandateContainer) { + Logger.error("Instance of Phy"); } + } @@ -168,8 +216,89 @@ public class MandateRetrievalRequest implements IAction { throw new MOAIDException("stork.11", null); // TODO description } - private void populateMandateType(AuthenticationSession moasession) { + private String mapPowersType(MandateContainer mandateContainer) { // TODO + return ""; + } + + private String mapCompanyType(MandateContainer mandateContainer) { // TODO + return ""; + } + + private PersonalAttribute getRepresentative(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + PersonalAttribute personalAttribute = new PersonalAttribute(); + HashMap complexValue = new HashMap(); + + 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()); + } + + 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; + } + + private PersonalAttribute getRepresented(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + PersonalAttribute personalAttribute = new PersonalAttribute(); + HashMap complexValue = new HashMap(); + + 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)); + } 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()); + } + + 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; + } + + + private PersonalAttribute getMandateContent(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + PersonalAttribute personalAttribute = new PersonalAttribute(); + HashMap complexValue = new HashMap(); + + 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)); + + 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; } public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { -- cgit v1.2.3