From 5a0218da5224fe8d0add07ec332a62c535a5beb2 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Wed, 14 May 2014 14:24:05 +0200 Subject: correct representative problem --- .../moa/id/protocols/stork2/MandateRetrievalRequest.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 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 662baa3c9..1e2811f74 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 @@ -281,16 +281,10 @@ public class MandateRetrievalRequest implements IAction { 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()); - } + representative.setEIdentifier(""); // TODO CALCULATE + representative.setGivenName(mandateContainer.getPhysicalRepresentativeGivenName()); + representative.setSurname(mandateContainer.getPhysicalRepresentativeFamilyName()); + representative.setDateOfBirth(mandateContainer.getPhysicalRepresentativeBirthDate()); Logger.debug("Complex attribute extracted: " + sourceAttribute.getName()); return representative; -- cgit v1.2.3 From 46c0d02baddd94c96bcfea5d27291ec25d838794 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Wed, 14 May 2014 17:03:38 +0200 Subject: retrieving several attributes at once --- .../id/protocols/stork2/AttributeCollector.java | 16 +++++++++---- .../moa/id/protocols/stork2/AttributeProvider.java | 15 +++++++++++- .../stork2/EHvdAttributeProviderPlugin.java | 21 ++++++++++------ .../stork2/MandateAttributeRequestProvider.java | 28 ++++++++++++++++++++++ 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java index fe5a96c18..e39f3606e 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java @@ -7,6 +7,9 @@ import java.util.List; 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.commons.db.dao.config.AttributeProviderPlugin; +import at.gv.egovernment.moa.id.commons.db.dao.config.OAStorkAttribute; +import at.gv.egovernment.moa.id.commons.db.dao.config.StorkAttribute; import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider; import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; @@ -168,14 +171,17 @@ public class AttributeCollector implements IAction { currentAttribute.setStatus("notAvailable"); aquiredAttributes.add((PersonalAttribute) currentAttribute.clone()); addOrUpdateAll(container.getResponse().getPersonalAttributeList(), aquiredAttributes); - // - check if we can find a suitable AttributeProvider Plugin for (AttributeProvider currentProvider : AttributeProviderFactory.getConfiguredPlugins(oaParam.getStorkAPs())) { + try { // - hand over control to the suitable plugin Logger.info(currentProvider.getClass().getSimpleName() + " called to handle attribute '" + currentAttribute.getName() + "'"); - aquiredAttributes = currentProvider.acquire(currentAttribute, container.getRequest().getSpCountry(), moasession); - Logger.info(currentProvider.getClass().getSimpleName() + " can handle attribute '" + currentAttribute.getName() + "'"); + + //aquiredAttributes = currentProvider.acquire(currentAttribute, container.getRequest().getSpCountry(), moasession); + aquiredAttributes = currentProvider.acquire(missingAttributes, container.getRequest().getSpCountry(), moasession); + + Logger.info(currentProvider.getClass().getSimpleName() + " can handle attribute '" + currentAttribute.getName() + "'"); break; } catch (UnsupportedAttributeException e) { // ok, try the next attributeprovider @@ -244,7 +250,7 @@ public class AttributeCollector implements IAction { private void addOrUpdateAll(IPersonalAttributeList target, IPersonalAttributeList source) throws MOAIDException { Logger.debug("Updating " + source.size() + " attributes..."); for (PersonalAttribute current : source) { - Logger.trace("treating " + current.getName()); + Logger.debug("treating " + current.getName()); // check if we need to update the current pa if (target.containsKey(current.getName())) { @@ -261,7 +267,7 @@ public class AttributeCollector implements IAction { } else target.add(current); - Logger.trace("...successfully treated " + current.getName()); + Logger.debug("...successfully treated " + current.getName()); } } diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java index 2914d8f7d..8203c0c63 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java @@ -10,6 +10,8 @@ import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import eu.stork.peps.auth.commons.IPersonalAttributeList; import eu.stork.peps.auth.commons.PersonalAttribute; +import java.util.List; + /** * An {@link AttributeProvider} can fetch a set of stork attributes. It might complete the query within one method call, * but might also need to redirect to another webservice to accomplish its task. @@ -31,7 +33,9 @@ public interface AttributeProvider { */ public IPersonalAttributeList acquire(PersonalAttribute attributes, String spCountyCode, AuthenticationSession moasession) throws UnsupportedAttributeException, ExternalAttributeRequestRequiredException, MOAIDException; - /** + public IPersonalAttributeList acquire(List attributes, String spCountyCode, AuthenticationSession moasession) throws UnsupportedAttributeException, ExternalAttributeRequestRequiredException, MOAIDException; + + /** * Perform redirect. * * @param url the return URL ending with ?artifactId=... @@ -52,5 +56,14 @@ public interface AttributeProvider { */ public IPersonalAttributeList parse(HttpServletRequest httpReq) throws UnsupportedAttributeException, MOAIDException; + /** + * Returns the list of supported attributes + * + * @return a list of attributes + * @throws MOAIDException if something went wrong + */ + //public IPersonalAttributeList getSupportedAttributes() throws MOAIDException; + + } diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java index 370182e71..332d407be 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java @@ -1,10 +1,7 @@ package at.gv.egovernment.moa.id.protocols.stork2; import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; +import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -202,9 +199,19 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider { } } - /* (non-Javadoc) - * @see at.gv.egovernment.moa.id.protocols.stork2.AttributeProvider#performRedirect(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, at.gv.egovernment.moa.id.config.auth.OAAuthParameter) - */ + @Override + public IPersonalAttributeList acquire(List attributes, String spCountyCode, AuthenticationSession moasession) throws UnsupportedAttributeException, ExternalAttributeRequestRequiredException, MOAIDException { + if (attributes.size() == 1) { + return acquire(attributes.get(0), spCountyCode, moasession); + } else { + throw new MOAIDException("stork.13", new Object[] { }); // TODO message only one attribute supported by this provider + + } + } + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.protocols.stork2.AttributeProvider#performRedirect(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, at.gv.egovernment.moa.id.config.auth.OAAuthParameter) + */ public void performRedirect(String url, HttpServletRequest req, HttpServletResponse resp, OAAuthParameter oaParam) throws MOAIDException { diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java index cae5e698b..ccbe2abbd 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java @@ -2,6 +2,7 @@ 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.MOAIDException; +import at.gv.egovernment.moa.id.commons.db.dao.config.AttributeProviderPlugin; import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.id.util.HTTPUtils; import at.gv.egovernment.moa.id.util.VelocityProvider; @@ -17,6 +18,7 @@ import org.apache.velocity.app.VelocityEngine; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.StringWriter; +import java.util.List; /** * Provides mandate attribute from MIS @@ -65,6 +67,28 @@ public class MandateAttributeRequestProvider implements AttributeProvider { throw new ExternalAttributeRequestRequiredException(this); } + @Override + public IPersonalAttributeList acquire(List attributes, String spCountryCode, AuthenticationSession moasession) throws UnsupportedAttributeException, ExternalAttributeRequestRequiredException, MOAIDException { + Logger.info("Acquiring " + attributes.size() + " attributes, by: " + getAttrProviderName()); + this.spCountryCode = spCountryCode; + requestedAttributes = new PersonalAttributeList(attributes.size()); + + for (PersonalAttribute personalAttribute : attributes) { + // break if we cannot handle the requested attribute + if (!this.attributes.contains(personalAttribute.getName())) { + Logger.info("Attribute " + personalAttribute.getName() + " not supported by the provider: " + getAttrProviderName()); + throw new UnsupportedAttributeException(); + } + requestedAttributes.add(personalAttribute); + } + + Logger.info("Thrown external request by: " + getAttrProviderName()); + throw new ExternalAttributeRequestRequiredException(this); + } + + + + public void performRedirect(String url, HttpServletRequest req, HttpServletResponse resp, OAAuthParameter oaParam) throws MOAIDException { String spSector = "Business"; @@ -87,6 +111,9 @@ public class MandateAttributeRequestProvider implements AttributeProvider { attributeRequest.setCitizenCountryCode("AT"); + + + Logger.info("STORK AttrRequest successfully assembled."); STORKSAMLEngine samlEngine = STORKSAMLEngine.getInstance("VIDP"); @@ -124,5 +151,6 @@ public class MandateAttributeRequestProvider implements AttributeProvider { return null; // } + } -- cgit v1.2.3 From e35dad4b75514aee5d1b019aa1cc44828a0b707b Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Wed, 14 May 2014 17:18:29 +0200 Subject: requisting only attributes that can be handled by attribute provider --- .../moa/id/protocols/stork2/AttributeCollector.java | 16 +++++++++++++++- .../moa/id/protocols/stork2/AttributeProvider.java | 2 +- .../id/protocols/stork2/EHvdAttributeProviderPlugin.java | 9 +++++++++ .../stork2/MandateAttributeRequestProvider.java | 10 ++++++++++ .../moa/id/protocols/stork2/MandateRetrievalRequest.java | 3 --- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java index e39f3606e..2f6dfe555 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java @@ -172,14 +172,28 @@ public class AttributeCollector implements IAction { aquiredAttributes.add((PersonalAttribute) currentAttribute.clone()); addOrUpdateAll(container.getResponse().getPersonalAttributeList(), aquiredAttributes); // - check if we can find a suitable AttributeProvider Plugin + for (AttributeProvider currentProvider : AttributeProviderFactory.getConfiguredPlugins(oaParam.getStorkAPs())) { + // build a section of attribute provider's predefined attributes and missing attributes + // only missing attributes that can be handled by attribute provider will be sent to it + List currentProviderConfiguredAttributes = new ArrayList(); + for (String attributeName : currentProvider.getSupportedAttributeNames()) { + for (PersonalAttribute missingAttribute : missingAttributes) { + if (missingAttribute.getName().equals(attributeName)) { + currentProviderConfiguredAttributes.add(missingAttribute); + break; + } + } + } + try { // - hand over control to the suitable plugin Logger.info(currentProvider.getClass().getSimpleName() + " called to handle attribute '" + currentAttribute.getName() + "'"); //aquiredAttributes = currentProvider.acquire(currentAttribute, container.getRequest().getSpCountry(), moasession); - aquiredAttributes = currentProvider.acquire(missingAttributes, container.getRequest().getSpCountry(), moasession); + //aquiredAttributes = currentProvider.acquire(missingAttributes, container.getRequest().getSpCountry(), moasession); + aquiredAttributes = currentProvider.acquire(currentProviderConfiguredAttributes, container.getRequest().getSpCountry(), moasession); Logger.info(currentProvider.getClass().getSimpleName() + " can handle attribute '" + currentAttribute.getName() + "'"); break; diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java index 8203c0c63..d7a4bfcc2 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java @@ -62,7 +62,7 @@ public interface AttributeProvider { * @return a list of attributes * @throws MOAIDException if something went wrong */ - //public IPersonalAttributeList getSupportedAttributes() throws MOAIDException; + public List getSupportedAttributeNames() throws MOAIDException; diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java index 332d407be..c132d5640 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/EHvdAttributeProviderPlugin.java @@ -226,4 +226,13 @@ public class EHvdAttributeProviderPlugin implements AttributeProvider { // there is no redirect required, so we throw an exception when someone asks us to parse a response throw new UnsupportedAttributeException(); } + + @Override + public List getSupportedAttributeNames() throws MOAIDException { + ArrayList supportedAttributeNames = new ArrayList(); + for (String attributeName : this.attributes.split(",")) { + supportedAttributeNames.add(attributeName); + } + return supportedAttributeNames; + } } diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java index ccbe2abbd..d4f7066d0 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MandateAttributeRequestProvider.java @@ -18,6 +18,7 @@ import org.apache.velocity.app.VelocityEngine; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.StringWriter; +import java.util.ArrayList; import java.util.List; /** @@ -151,6 +152,15 @@ public class MandateAttributeRequestProvider implements AttributeProvider { return null; // } + @Override + public List getSupportedAttributeNames() throws MOAIDException { + ArrayList supportedAttributeNames = new ArrayList(); + for (String attributeName : this.attributes.split(",")) { + supportedAttributeNames.add(attributeName); + } + return supportedAttributeNames; + } + } 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 1e2811f74..ade2a0301 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 @@ -159,9 +159,6 @@ public class MandateRetrievalRequest implements IAction { new ConsentEvaluator().requestConsent(container, httpResp, oaParam); else new ConsentEvaluator().generateSTORKResponse(httpResp, container); - - - //return (new AttributeCollector()).processRequest(container, httpReq, httpResp, moasession, oaParam); } -- cgit v1.2.3 From 5b1d68f71a77b80bd39a9c231090a9c63a892811 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Wed, 14 May 2014 17:19:18 +0200 Subject: remove unused --- .../protocols/stork2/MandateRetrievalRequest.java | 56 ---------------------- 1 file changed, 56 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 ade2a0301..9c7f45146 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 @@ -197,62 +197,6 @@ public class MandateRetrievalRequest implements IAction { } - 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 ""; -- cgit v1.2.3