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.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.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; /** * */ public class MandateRetrievalRequest implements IAction { private AuthenticationSession moaSession; private MOASTORKRequest moaStorkRequest; public String processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, AuthenticationSession moasession) throws MOAIDException { Logger.error("Entering mandateretrievalrequest"); this.moaSession = moasession; if ((req instanceof MOASTORKRequest)) { this.moaStorkRequest = (MOASTORKRequest)req; } else { return null; // TODO } if (moaStorkRequest.isAttrRequest() && moaStorkRequest.getStorkAttrQueryRequest() != null) { 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()); //moaStorkResponse.setCountry(moaStorkRequest.getSpCountry()); IPersonalAttributeList sourceAttributeList = moaStorkRequest.getStorkAttrQueryRequest().getPersonalAttributeList(); IPersonalAttributeList attributeList = new PersonalAttributeList(); for (PersonalAttribute currentAttribute : sourceAttributeList) { Logger.debug("Evaluationg currentattribute " + currentAttribute.getName()); if (currentAttribute.getName().equals("mandateContent")) { PersonalAttribute mandateContent = 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); Logger.debug("Setting currentattribute " + currentAttribute.getName()); } } 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; // } public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { return true; // } public String getDefaultActionName() { return STORKProtocol.MANDATERETRIEVALREQUEST; } }