diff options
6 files changed, 205 insertions, 3 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 new file mode 100644 index 000000000..fbc959cc4 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeCollector.java @@ -0,0 +1,70 @@ +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.moduls.IAction; +import at.gv.egovernment.moa.id.moduls.IRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * the AttributeCollector Action tries to get all requested attributes from a set of {@link AttributeProvider} Plugins. + * The class is called whenever the {@link AuthenticationRequest} Action is invoked and checks for missing attributes. + * Furthermore, the class can handle direct posts. That is when the class triggers an attribute query which needs user + * interaction, redirect to another portal, etc. The redirect will hit here and the class can continue to fetch attributes. + *  + * TODO how do we treat mandatory and optional attributes? + *  + */ +public class AttributeCollector implements IAction { + + +    /* (non-Javadoc) +     * @see at.gv.egovernment.moa.id.moduls.IAction#processRequest(at.gv.egovernment.moa.id.moduls.IRequest, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, at.gv.egovernment.moa.id.auth.data.AuthenticationSession) +     */ +    public String processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, AuthenticationSession moasession) throws MOAIDException { +    	// check if we have a STORKAttributeResponse in the request +    	// - no, how did we get here? +    	// yes, we got a recent requested attribute +    	// - find the attribute provider plugin that can handle the response +    	// - fetch the container +    	DataContainer container = new DataContainer(); +    	// - insert the embedded attribute(s) into the container +    	 +    	// see if we need some more attributes +    	return processRequest(container); +    } +     +    /** +     * Checks if there are missing attributes and tries to fetch them. If there are no more attribute to fetch, +     * this very method creates and sends the protocol result to the asking S-PEPS. +     * +     * @param container the {@link DataContainer} representing the status of the overall query. +     * @return the string +     */ +    public String processRequest(DataContainer container) { +    	// check if there are attributes we need to fetch +    	// for each attribute still missing +    	// - check if we can find a suitable AttributeProvider Plugin +    	// - hand over control to the suitable plugin +    	// - add the aquired attribute to the container +    	// build response +    	// done +    	return "12345"; // AssertionId +    } + +    /* (non-Javadoc) +     * @see at.gv.egovernment.moa.id.moduls.IAction#needAuthentication(at.gv.egovernment.moa.id.moduls.IRequest, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) +     */ +    public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { +    	// this action does not need any authentication. The authentication is already done by the preceeding AuthenticationRequest-Action. +        return false; +    } + +    /* (non-Javadoc) +     * @see at.gv.egovernment.moa.id.moduls.IAction#getDefaultActionName() +     */ +    public String getDefaultActionName() { +        return STORKProtocol.ATTRIBUTE_COLLECTOR; +    } +} 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 new file mode 100644 index 000000000..2e4f2d8c5 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProvider.java @@ -0,0 +1,32 @@ +package at.gv.egovernment.moa.id.protocols.stork2; + +import javax.activation.UnsupportedDataTypeException; +import javax.servlet.http.HttpServletRequest; + +import eu.stork.peps.auth.commons.PersonalAttribute; + +/** + * 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. + */ +public interface AttributeProvider { +	 +	/** +	 * Acquire the specified attribute. Returns {@code null} when attribute retrieval is in progress, but requires for +	 * for redirecting the user to an external service. Use {@link AttributeProvider#parse(HttpServletRequest)} to parse +	 * the response. +	 * +	 * @param attributeName the attribute name +	 * @return the personal attribute +	 * @throws UnsupportedDataTypeException when the provider cannot acquire the specified attribute +	 */ +	public PersonalAttribute acquire(String attributeName) throws UnsupportedAttributeException; + +	/** +	 * Parses the response we got from the external attribute provider. +	 * +	 * @param httpReq the http req +	 * @return the personal attribute +	 */ +	public PersonalAttribute parse(HttpServletRequest httpReq); +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java index 7e80273ca..1f6ffaa9a 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java @@ -4,6 +4,7 @@ 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 org.apache.velocity.VelocityContext;  import org.apache.velocity.app.VelocityEngine; @@ -81,9 +82,21 @@ public class AuthenticationRequest implements IAction {          //httpResp.setStatus(200);          //VPEPSInboundPostHandler - - -        return "12345"; // AssertionId +         +        // create fresh container +        DataContainer container = new DataContainer(); +         +        // - fill in the request we extracted above +        container.setRequest(request); +         +        // - fill in the partial response created above +        container.setResponse(response); +         +        // - memorize the target url were we have to return the result +        container.setTarget(target); +         +        // see if we need to fetch further attributes +        return (new AttributeCollector()).processRequest(container);      }      public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/DataContainer.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/DataContainer.java new file mode 100644 index 000000000..40c827ef8 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/DataContainer.java @@ -0,0 +1,79 @@ +package at.gv.egovernment.moa.id.protocols.stork2; + +import java.io.Serializable; + +import eu.stork.peps.auth.commons.STORKAuthnRequest; +import eu.stork.peps.auth.commons.STORKAuthnResponse; + +// TODO: Auto-generated Javadoc +/** + * Holds info about an ongoing but yet incomplete stork authnrequest process. + */ +public class DataContainer implements Serializable { +	 +	/** The Constant serialVersionUID. */ +	private static final long serialVersionUID = -8765997480582363012L; + +	/** The incoming request. */ +	private STORKAuthnRequest request; +	 +	/** The yet incomplete response. */ +	private STORKAuthnResponse response; +	 +	/** The target. */ +	private String target; +	 +	/** +	 * Gets the request. +	 * +	 * @return the request +	 */ +	public STORKAuthnRequest getRequest() { +		return request; +	} + +	/** +	 * Sets the request. +	 * +	 * @param request the new request +	 */ +	public void setRequest(STORKAuthnRequest request) { +		this.request = request; +	} + +	/** +	 * Gets the response. +	 * +	 * @return the response +	 */ +	public STORKAuthnResponse getResponse() { +		return response; +	} + +	/** +	 * Sets the response. +	 * +	 * @param response the new response +	 */ +	public void setResponse(STORKAuthnResponse response) { +		this.response = response; +	} + +	/** +	 * Gets the target. +	 * +	 * @return the target +	 */ +	public String getTarget() { +		return target; +	} + +	/** +	 * Sets the target. +	 * +	 * @param target the new target +	 */ +	public void setTarget(String target) { +		this.target = target; +	} +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java index 2e42a0d75..323d9ba8e 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java @@ -36,6 +36,7 @@ public class STORKProtocol implements IModulInfo, MOAIDAuthConstants {      public static final String PATH = "id_stork2";      public static final String AUTHENTICATIONREQUEST = "AuthenticationRequest"; +	public static final String ATTRIBUTE_COLLECTOR = "AttributeCollector";      private static HashMap<String, IAction> actions = new HashMap<String, IAction>(); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/UnsupportedAttributeException.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/UnsupportedAttributeException.java new file mode 100644 index 000000000..9447c079f --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/UnsupportedAttributeException.java @@ -0,0 +1,7 @@ +package at.gv.egovernment.moa.id.protocols.stork2; + +public class UnsupportedAttributeException extends Exception { + +	private static final long serialVersionUID = -7720066381435378111L; + +} | 
