diff options
Diffstat (limited to 'id/server/idserverlib/src/main/java')
4 files changed, 73 insertions, 11 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 e74cf4e8b..93204f2ab 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,10 +7,14 @@ import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; import at.gv.egovernment.moa.id.auth.exception.MOAIDException; import at.gv.egovernment.moa.id.moduls.IAction; import at.gv.egovernment.moa.id.moduls.IRequest; +import at.gv.egovernment.moa.id.storage.AssertionStorage; +import at.gv.egovernment.moa.logging.Logger; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.opensaml.common.impl.SecureRandomIdentifierGenerator; + import eu.stork.peps.auth.commons.IPersonalAttributeList; import eu.stork.peps.auth.commons.PersonalAttribute; @@ -30,6 +34,7 @@ public class AttributeCollector implements IAction { public AttributeCollector() { // TODO generate from config attributeProviders = new ArrayList<AttributeProvider>(); + attributeProviders.add(new DemoRedirectAttributeProvider()); attributeProviders.add(new DemoNoRedirectAttributeProvider()); } @@ -56,8 +61,9 @@ public class AttributeCollector implements IAction { * * @param container the {@link DataContainer} representing the status of the overall query. * @return the string + * @throws MOAIDException */ - public String processRequest(DataContainer container) { + public String processRequest(DataContainer container) throws MOAIDException { // check if there are attributes we need to fetch IPersonalAttributeList requestAttributeList = container.getRequest().getPersonalAttributeList(); IPersonalAttributeList responseAttributeList = container.getResponse().getPersonalAttributeList(); @@ -71,18 +77,38 @@ public class AttributeCollector implements IAction { for(String currentAttribute : missingAttributes) { // - check if we can find a suitable AttributeProvider Plugin for(AttributeProvider currentProvider : attributeProviders) { - // - hand over control to the suitable plugin - PersonalAttribute aquiredAttribute = currentProvider.acquire(currentAttribute); + try { + // - hand over control to the suitable plugin + PersonalAttribute aquiredAttribute = currentProvider.acquire(currentAttribute); + + // - add the aquired attribute to the container + container.getResponse().getPersonalAttributeList().add(aquiredAttribute); + } catch(UnsupportedAttributeException e) { + // ok, try the next attributeprovider + } - // - add the aquired attribute to the container - container.getResponse().getPersonalAttributeList().add(aquiredAttribute); } } - } catch(UnsupportedAttributeException e) { - // TODO - // memorize the container again - return "12345"; // TODO what to do here? - } + } catch (AttributeRequestOngoingException e) { + // the attribute request is ongoing and requires an external service. + try { + // memorize the container again + // - generate new key + String newArtifactId = new SecureRandomIdentifierGenerator() + .generateIdentifier(); + + // - put container in temporary store. + AssertionStorage.getInstance().put(newArtifactId, container); + + // TODO - add container-key to httpresponse + } catch (Exception e1) { + // TODO should we return the response as is to the PEPS? + Logger.error("Error putting incomplete Stork response into temporary storage", e); + throw new MOAIDException("stork.11", null); + } + + return "12345"; // TODO what to do here? + } // build response // done return "12345"; // AssertionId 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 2e4f2d8c5..fd35b0c71 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 @@ -20,7 +20,7 @@ public interface AttributeProvider { * @return the personal attribute * @throws UnsupportedDataTypeException when the provider cannot acquire the specified attribute */ - public PersonalAttribute acquire(String attributeName) throws UnsupportedAttributeException; + public PersonalAttribute acquire(String attributeName) throws UnsupportedAttributeException, AttributeRequestOngoingException; /** * Parses the response we got from the external attribute provider. diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeRequestOngoingException.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeRequestOngoingException.java new file mode 100644 index 000000000..be5a53f34 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeRequestOngoingException.java @@ -0,0 +1,5 @@ +package at.gv.egovernment.moa.id.protocols.stork2; + +public class AttributeRequestOngoingException extends Exception { + +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/DemoRedirectAttributeProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/DemoRedirectAttributeProvider.java new file mode 100644 index 000000000..f44fbed07 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/DemoRedirectAttributeProvider.java @@ -0,0 +1,31 @@ +package at.gv.egovernment.moa.id.protocols.stork2; + +import java.util.ArrayList; + +import javax.servlet.http.HttpServletRequest; + +import eu.stork.peps.auth.commons.PersonalAttribute; + +/** + * Just a simple demoprovider who can fetch any attribute you ask him. + */ +public class DemoRedirectAttributeProvider implements AttributeProvider { + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.protocols.stork2.AttributeProvider#acquire(java.lang.String) + */ + @Override + public PersonalAttribute acquire(String attributeName) + throws UnsupportedAttributeException, AttributeRequestOngoingException { + throw new AttributeRequestOngoingException(); + } + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.protocols.stork2.AttributeProvider#parse(javax.servlet.http.HttpServletRequest) + */ + @Override + public PersonalAttribute parse(HttpServletRequest httpReq) { + return new PersonalAttribute("sepp", true, new ArrayList<String>(), ""); + } + +} |