From 506a34dbd503fa7afd8c4fea52bbe08e3066f6a9 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Fri, 13 Jun 2014 17:19:41 +0200 Subject: including various company types --- .../protocols/stork2/MandateRetrievalRequest.java | 167 +++++++++++++++------ .../moa/id/protocols/stork2/S2Constants.java | 4 + 2 files changed, 128 insertions(+), 43 deletions(-) (limited to 'id/server/idserverlib/src/main/java') 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 1d081fb1c..ab189c59d 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 @@ -13,10 +13,7 @@ import eu.stork.peps.auth.commons.IPersonalAttributeList; import eu.stork.peps.auth.commons.PersonalAttribute; import eu.stork.peps.auth.commons.PersonalAttributeList; import eu.stork.peps.auth.commons.STORKAttrQueryResponse; -import eu.stork.peps.complex.attributes.CanonicalAddressType; -import eu.stork.peps.complex.attributes.MandateContentType; -import eu.stork.peps.complex.attributes.MandateType; -import eu.stork.peps.complex.attributes.RepresentationPersonType; +import eu.stork.peps.complex.attributes.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -31,6 +28,7 @@ import java.io.StringWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.regex.Pattern; /** @@ -95,21 +93,7 @@ public class MandateRetrievalRequest implements IAction { if (currentAttribute.getName().equals("mandateContent")) { MandateContentType mandateContent = getMandateContent(mandateContainer, currentAttribute); attributeList.add(marshallComplexAttribute(currentAttribute, mandateContent)); - - // final Marshaller marshaller = JAXBContext.newInstance(MandateContentType.class).createMarshaller(); - // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - - // StringWriter stringWriter = new StringWriter(); - - // marshaller.marshal(new JAXBElement(new QName("urn:eu:stork:names:tc:STORK:1.0:assertion", "mandateContent"), MandateContentType.class, null, mandateContent), stringWriter); - - // ArrayList value = new ArrayList(); - // value.add(stringWriter.toString()); - - // PersonalAttribute mandateContentAttribute = new PersonalAttribute("mandateContent", false, value, "Available"); - - // attributeList.add(mandateContentAttribute); - } else if (currentAttribute.getName().equals("representative")) { // TODO CHECK + } else if (currentAttribute.getName().equals("representative")) { // TODO CHECK IN DETAIL RepresentationPersonType representative = getRepresentative(mandateContainer, currentAttribute); attributeList.add(marshallComplexAttribute(currentAttribute, representative)); @@ -126,32 +110,46 @@ public class MandateRetrievalRequest implements IAction { } else if (currentAttribute.getName().equals("legalName")) { String legalName = getLegalName(mandateContainer, currentAttribute); - PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(legalName), "Available"); - attributeList.add(personalAttribute); + if (legalName.length() > 0) { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(legalName), AttributeStatusType.AVAILABLE.value())); + } else { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(legalName), AttributeStatusType.NOT_AVAILABLE.value())); + } } else if (currentAttribute.getName().equals("eLPIdentifier")) { String eLPIdentifier = geteLPIdentifier(mandateContainer, currentAttribute); - PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(eLPIdentifier), "Available"); - attributeList.add(personalAttribute); + if (eLPIdentifier.length() > 0) { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(eLPIdentifier), AttributeStatusType.AVAILABLE.value())); + } else { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(eLPIdentifier), AttributeStatusType.NOT_AVAILABLE.value())); + } } else if (currentAttribute.getName().equals("type")) { String type = getCompanyType(mandateContainer, currentAttribute); - PersonalAttribute personalAttribute; if (type.length() > 0) { - attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), "Available")); + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), AttributeStatusType.AVAILABLE.value())); } else { - attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), "NotAvailable")); + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), AttributeStatusType.NOT_AVAILABLE.value())); } } else if (currentAttribute.getName().equals("translatableType")) { - String translatableType = ""; - PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(translatableType), "Available"); - attributeList.add(personalAttribute); + String translatableType = getCompanyTranslatableType(mandateContainer, currentAttribute); + if (translatableType.length() > 0) { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(translatableType), AttributeStatusType.AVAILABLE.value())); + } else { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(translatableType), AttributeStatusType.NOT_AVAILABLE.value())); + } } } + +// if (attrResponse.getPersonalAttributeList().size() == 0) { +// Logger.error("AttributeList empty - could not retrieve attributes"); +// throw new MOAIDException("stork.16", new Object[]{}); // TODO MESSAGE +// } + attrResponse.setPersonalAttributeList(attributeList); moaStorkResponse.setSTORKAttrResponse(attrResponse); - Logger.debug("Attributes " + moaStorkResponse.getStorkAttrQueryResponse().getPersonalAttributeList().size()); + Logger.debug("Attributes retrieved: " + moaStorkResponse.getStorkAttrQueryResponse().getPersonalAttributeList().size()); // Prepare extended attributes Logger.debug("Preparing data container"); @@ -183,7 +181,7 @@ public class MandateRetrievalRequest implements IAction { private String geteLPIdentifier(MandateContainer mandateContainer, PersonalAttribute currentAttribute) throws MOAIDException { RepresentationPersonType represented = getRepresented(mandateContainer, currentAttribute); if (mandateContainer instanceof CorporateBodyMandateContainer) { - return represented.getELPIdentifier(); + return "AT/".concat(represented.getELPIdentifier()); } else { Logger.error("Cannot provide eLPIdentifier for natural person."); throw new MOAIDException("stork.16", new Object[]{}); // TODO @@ -192,8 +190,6 @@ public class MandateRetrievalRequest implements IAction { } private PersonalAttribute marshallComplexAttribute(PersonalAttribute currentAttribute, Object obj) { // TODO refactor - - StringWriter stringWriter = new StringWriter(); try { if (obj instanceof MandateContentType) { @@ -212,12 +208,12 @@ public class MandateRetrievalRequest implements IAction { } catch (Exception ex) { Logger.error("Could not marshall atrribute: " + currentAttribute.getName() + ", " + ex.getMessage()); - return new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), new ArrayList(), "NotAvailable"); + return new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), new ArrayList(), AttributeStatusType.NOT_AVAILABLE.value()); } ArrayList value = new ArrayList(); value.add(stringWriter.toString()); - PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), value, "Available"); + PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), value, AttributeStatusType.AVAILABLE.value()); return personalAttribute; } @@ -254,24 +250,109 @@ public class MandateRetrievalRequest implements IAction { } + private String getLegalIdentificationType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + RepresentationPersonType represented = getRepresented(mandateContainer, sourceAttribute); + if (mandateContainer instanceof CorporateBodyMandateContainer) { + return ((CorporateBodyMandateContainer) mandateContainer).getCorpMandatorIdentificationType(); + } else { + Logger.error("Cannot provide type for natural person."); + throw new MOAIDException("stork.16", new Object[]{}); // TODO + } + } + private String getCompanyType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + // retrieve the registered subject name String legalName = getLegalName(mandateContainer, sourceAttribute); + String legalIdentificationType = getLegalIdentificationType(mandateContainer, sourceAttribute); + + // compile patterns for different organisation types + // sources: USP, WKO, LexAndTax + // gmbh patterns ArrayList gmbhPatterns = new ArrayList(); - gmbhPatterns.add(Pattern.compile(".+ gmbh$", Pattern.CASE_INSENSITIVE)); - gmbhPatterns.add(Pattern.compile(".+ Handelsges\\.m\\.b\\.H\\.$", Pattern.CASE_INSENSITIVE)); - gmbhPatterns.add(Pattern.compile(".+ Gesellschaft m\\.b\\.H\\.$", Pattern.CASE_INSENSITIVE)); - gmbhPatterns.add(Pattern.compile(".+ gesmbh$", Pattern.CASE_INSENSITIVE)); - - for (Pattern pattern : gmbhPatterns) { - if (pattern.matcher(legalName).matches()) { - return "GmbH"; + gmbhPatterns.add(Pattern.compile(".+ GmbH(( in Liquidation)|( in Liqu.)){0,1}$")); + gmbhPatterns.add(Pattern.compile(".+ GesmbH$")); + gmbhPatterns.add(Pattern.compile(".+ Gesellschaft mit beschränkter Haftung$")); + gmbhPatterns.add(Pattern.compile(".+ Ges\\.m\\.b\\.H\\.$")); + gmbhPatterns.add(Pattern.compile(".+ G\\.m\\.b\\.H\\.$")); + gmbhPatterns.add(Pattern.compile(".+ Handelsges\\.m\\.b\\.H\\.$")); + gmbhPatterns.add(Pattern.compile(".+ Gesellschaft m\\.b\\.H\\.$")); + + // ag patterns + ArrayList agPatterns = new ArrayList(); + agPatterns.add(Pattern.compile(".+ AG$")); + agPatterns.add(Pattern.compile(".+ Aktiengesellschaft$")); + + // og patterns + ArrayList ogPatterns = new ArrayList(); + ogPatterns.add(Pattern.compile(".+ OG$")); + ogPatterns.add(Pattern.compile(".+ OHG$")); + ogPatterns.add(Pattern.compile(".+ offene Gesellschaft$")); + + // kg patterns + ArrayList kgPatterns = new ArrayList(); + kgPatterns.add(Pattern.compile(".+ KG$")); + kgPatterns.add(Pattern.compile(".+ Kommanditgesellschaft$")); + + // eu patterns + ArrayList euPatterns = new ArrayList(); + euPatterns.add(Pattern.compile(".+ eingetragene Unternehmerin$")); + euPatterns.add(Pattern.compile(".+ eingetragener Unternehmer$")); + euPatterns.add(Pattern.compile(".+ e\\.U\\.$")); + + + // company patterns + HashMap> companyPatterns = new HashMap>(); + companyPatterns.put("GmbH", gmbhPatterns); + companyPatterns.put("AG", agPatterns); + companyPatterns.put("OG", ogPatterns); + companyPatterns.put("KG", kgPatterns); + companyPatterns.put("e.U.", euPatterns); + + // iterate over different types of companies and check if the name ending matches + if (S2Constants.IDENTIFICATION_TYPE_COMPANY.equals(legalIdentificationType)) { + for (String companyType : companyPatterns.keySet()) { + for (Pattern pattern : companyPatterns.get(companyType)) { + if (pattern.matcher(legalName).matches()) { + return companyType; + } + } } } + // check if the subject is association + if (S2Constants.IDENTIFICATION_TYPE_ASSOCIATION.equals(legalIdentificationType)) { + return "Verein"; + } + + // check if the subject falls under category of others + if (S2Constants.IDENTIFICATION_TYPE_OTHERS.equals(legalIdentificationType)) { + return "ERsB"; + } + return ""; } + private String getCompanyTranslatableType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + // retrieve first the company type + String companyType = getCompanyType(mandateContainer, sourceAttribute); + + // translate company type based on the section 5.6 in STORK 2 D4.11 + if (companyType.length() == 0) { + return ""; + } else if (companyType.equals("GmbH")) { + return "G"; + } else if (companyType.equals("AG")) { + return "A"; + } else if (companyType.equals("OG")) { + return "O"; + } else if (companyType.equals("KG")) { + return "K"; + } else { + return ""; + } + } + private RepresentationPersonType getRepresentative(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { RepresentationPersonType representative = new RepresentationPersonType(); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/S2Constants.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/S2Constants.java index e332fbc6a..a2deaa572 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/S2Constants.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/S2Constants.java @@ -35,6 +35,10 @@ public interface S2Constants { public static final String MANDATE_MANDATOR_PHYPERS_FAMILYNAME_QUERY = "/mandate:Mandate/mandate:Mandator/persondata:PhysicalPerson/persondata:Name/persondata:FamilyName/text()"; public static final String MANDATE_MANDATOR_PHYPERS_DATEOFBIRTH_QUERY = "/mandate:Mandate/mandate:Mandator/persondata:PhysicalPerson/persondata:DateOfBirth/text()"; + public static final String IDENTIFICATION_TYPE_COMPANY = "urn:publicid:gv.at:baseid+XFN"; + public static final String IDENTIFICATION_TYPE_ASSOCIATION = "urn:publicid:gv.at:baseid+XZVR"; + public static final String IDENTIFICATION_TYPE_OTHERS = "urn:publicid:gv.at:baseid+XERSB"; + } -- cgit v1.2.3 From 34213284eeb7019f8d15af44d32f1850a0dae290 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Fri, 13 Jun 2014 18:57:31 +0200 Subject: refactoring --- .../protocols/stork2/MandateRetrievalRequest.java | 48 +++++----- .../moa/id/protocols/stork2/STORKProtocol.java | 102 +++++++++++---------- 2 files changed, 81 insertions(+), 69 deletions(-) (limited to 'id/server/idserverlib/src/main/java') 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 ab189c59d..72dc81b35 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 @@ -182,11 +182,11 @@ public class MandateRetrievalRequest implements IAction { RepresentationPersonType represented = getRepresented(mandateContainer, currentAttribute); if (mandateContainer instanceof CorporateBodyMandateContainer) { return "AT/".concat(represented.getELPIdentifier()); - } else { + } else if (currentAttribute.isRequired()) { Logger.error("Cannot provide eLPIdentifier for natural person."); - throw new MOAIDException("stork.16", new Object[]{}); // TODO + throw new MOAIDException("stork.19", new Object[]{currentAttribute.getName()}); } - + return ""; } private PersonalAttribute marshallComplexAttribute(PersonalAttribute currentAttribute, Object obj) { // TODO refactor @@ -214,16 +214,18 @@ public class MandateRetrievalRequest implements IAction { value.add(stringWriter.toString()); PersonalAttribute personalAttribute = new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), value, AttributeStatusType.AVAILABLE.value()); - return personalAttribute; } - private String mapPowersType(MandateContainer mandateContainer) { // TODO - return ""; - } - - private String mapCompanyType(MandateContainer mandateContainer) { // TODO + private String mapPowersType(MandateContainer mandateContainer) { + if (mandateContainer.getAnnotation().equals("ELGABilateral")) { + return "6"; // Health Powers + } else if (mandateContainer.getAnnotation().equals("ERsB")) { + return "0"; // General Powers + } else if (mandateContainer.getAnnotation().equals("GeneralvollmachtBilateral")) { + return "0"; // General Powers + } return ""; } @@ -232,6 +234,7 @@ public class MandateRetrievalRequest implements IAction { RepresentationPersonType representative = getRepresentative(mandateContainer, sourceAttribute); RepresentationPersonType represented = getRepresented(mandateContainer, sourceAttribute); MandateContentType mandateContent = getMandateContent(mandateContainer, sourceAttribute); + mandateType.setRepresenting(representative); mandateType.setRepresented(represented); mandateType.setMandateContent(mandateContent); @@ -243,21 +246,22 @@ public class MandateRetrievalRequest implements IAction { RepresentationPersonType represented = getRepresented(mandateContainer, sourceAttribute); if (mandateContainer instanceof CorporateBodyMandateContainer) { return represented.getName(); - } else { + } else if (sourceAttribute.isRequired()) { Logger.error("Cannot provide legalName for natural person."); - throw new MOAIDException("stork.16", new Object[]{}); // TODO + throw new MOAIDException("stork.19", new Object[]{sourceAttribute.getName()}); } + return ""; } private String getLegalIdentificationType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { - RepresentationPersonType represented = getRepresented(mandateContainer, sourceAttribute); if (mandateContainer instanceof CorporateBodyMandateContainer) { return ((CorporateBodyMandateContainer) mandateContainer).getCorpMandatorIdentificationType(); - } else { + } else if (sourceAttribute.isRequired()) { Logger.error("Cannot provide type for natural person."); - throw new MOAIDException("stork.16", new Object[]{}); // TODO + throw new MOAIDException("stork.19", new Object[]{sourceAttribute.getName()}); // TODO } + return ""; } private String getCompanyType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { @@ -366,16 +370,15 @@ public class MandateRetrievalRequest implements IAction { return representative; } - private RepresentationPersonType getRepresented(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) { + private RepresentationPersonType getRepresented(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { RepresentationPersonType represented = new RepresentationPersonType(); if (mandateContainer instanceof CorporateBodyMandateContainer) { - CorporateBodyMandateContainer corporateBodyMandateContainer = (CorporateBodyMandateContainer) mandateContainer; - represented.setELPIdentifier(corporateBodyMandateContainer.getCorpMandatorIdentificationValue()); - represented.setName(corporateBodyMandateContainer.getCorpMandatorFullName()); + represented.setELPIdentifier(geteLPIdentifier(mandateContainer, sourceAttribute)); + represented.setName(getLegalName(mandateContainer, sourceAttribute)); represented.setAddress(""); represented.setCanonicalAddress(new CanonicalAddressType()); - represented.setType(mapCompanyType(mandateContainer)); // TODO + represented.setType(getCompanyType(mandateContainer, sourceAttribute)); } else if (mandateContainer instanceof PhyPersonMandateContainer) { PhyPersonMandateContainer phyPersonMandateContainer = (PhyPersonMandateContainer) mandateContainer; represented.setEIdentifier(""); // TODO CALCULATE @@ -394,13 +397,12 @@ public class MandateRetrievalRequest implements IAction { MandateContentType mandateContent = new MandateContentType(); try { XMLGregorianCalendar validFrom = DatatypeFactory.newInstance().newXMLGregorianCalendar(mandateContainer.getMandateValidFrom()); - XMLGregorianCalendar validTo = DatatypeFactory.newInstance().newXMLGregorianCalendar(mandateContainer.getMandateValidTo()); mandateContent.setValidFrom(validFrom); mandateContent.setValidTo(validTo); } catch (DatatypeConfigurationException dte) { - Logger.error("Error converting data from mandate"); - throw new MOAIDException("stork.16", new Object[]{}); // TODO + Logger.error("Error converting date from mandate: " + mandateContainer.getMandateValidFrom() + ", " + mandateContainer.getMandateValidTo()); + throw new MOAIDException("stork.20", new Object[]{}); } mandateContent.setTransactionLimit(BigInteger.valueOf(0)); // TODO @@ -413,7 +415,7 @@ public class MandateRetrievalRequest implements IAction { } public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { - return true; // + return true; } public String getDefaultActionName() { 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 ed9c45126..29148daeb 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 @@ -9,6 +9,7 @@ import at.gv.egovernment.moa.logging.Logger; import eu.stork.peps.auth.commons.*; import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; @@ -26,7 +27,7 @@ public class STORKProtocol implements IModulInfo, MOAIDAuthConstants { public static final String AUTHENTICATIONREQUEST = "AuthenticationRequest"; public static final String ATTRIBUTE_COLLECTOR = "AttributeCollector"; public static final String MANDATERETRIEVALREQUEST = "MandateRetrievalRequest"; - public static final String CONSENT_EVALUATOR = "ConsentEvaluator"; + public static final String CONSENT_EVALUATOR = "ConsentEvaluator"; private static HashMap actions = new HashMap(); @@ -68,7 +69,7 @@ public class STORKProtocol implements IModulInfo, MOAIDAuthConstants { if (AttributeCollector.class.getSimpleName().equals(action) || ConsentEvaluator.class.getSimpleName().equals(action)) - return STORK2Request; + return STORK2Request; if (request.getParameter("SAMLResponse") != null) { // TODO check attribute collector @@ -102,57 +103,66 @@ public class STORKProtocol implements IModulInfo, MOAIDAuthConstants { return STORK2Response; - } else if (request.getParameter("SAMLRequest") != null) { - - //extract STORK Response from HTTP Request - byte[] decSamlToken; - try { - decSamlToken = PEPSUtil.decodeSAMLToken(request.getParameter("SAMLRequest")); - } catch (NullPointerException e) { - if (request.getRemoteHost().contains("129.27.142")) { - Logger.warn("Availability check by " + request.getRemoteHost() + " on URI: " + request.getRequestURI()); - } else { - Logger.error("Unable to retrieve STORK Request for host: " + request.getRemoteHost() + " and URI: " + request.getRequestURI(), e); + } else if (request.getParameter("SAMLRequest") != null) { + + //extract STORK Response from HTTP Request + byte[] decSamlToken; + try { + decSamlToken = PEPSUtil.decodeSAMLToken(request.getParameter("SAMLRequest")); + } catch (NullPointerException e) { + if (request.getRemoteHost().contains("129.27.142")) { + Logger.warn("Availability check by " + request.getRemoteHost() + " on URI: " + request.getRequestURI()); + } else { + Logger.error("Unable to retrieve STORK Request for host: " + request.getRemoteHost() + " and URI: " + request.getRequestURI(), e); + } + throw new MOAIDException("stork.04", null); } - throw new MOAIDException("stork.04", null); - } - //Get SAMLEngine instance - STORKSAMLEngine engine = STORKSAMLEngine.getInstance("VIDP"); - - STORKAuthnRequest authnRequest = null; - STORKAttrQueryRequest attrRequest = null; - - - // check if valid authn request is contained - try { - authnRequest = engine.validateSTORKAuthnRequest(decSamlToken); - } catch (STORKSAMLEngineException ex) { - Logger.error("Unable to validate Stork AuthenticationRequest: " + ex.getMessage()); - } catch(ClassCastException e) { - // we do not have a authnRequest - // check if a valid attr request is container - try { - attrRequest = engine.validateSTORKAttrQueryRequest(decSamlToken); - } catch (STORKSAMLEngineException ex) { - Logger.error("Unable to validate Stork AuthenticationRequest: " + ex.getMessage()); - } - } + //Get SAMLEngine instance + STORKSAMLEngine engine = STORKSAMLEngine.getInstance("VIDP"); - // if there is no authn or attr request, raise error - if ((authnRequest == null) && (attrRequest == null)) { - Logger.error("There is no authentication or attribute request contained."); - throw new MOAIDException("stork.14", null); - } + STORKAuthnRequest authnRequest = null; + STORKAttrQueryRequest attrRequest = null; - STORK2Request.setSTORKAuthnRequest(authnRequest); - STORK2Request.setSTORKAttrRequest(attrRequest); - - return STORK2Request; + // check if valid authn request is contained + try { + authnRequest = engine.validateSTORKAuthnRequest(decSamlToken); + } catch (STORKSAMLEngineException ex) { + Logger.error("Unable to validate Stork AuthenticationRequest: " + ex.getMessage()); + } catch (ClassCastException e) { + // we do not have a authnRequest + // check if a valid attr request is container + try { + attrRequest = engine.validateSTORKAttrQueryRequest(decSamlToken); + } catch (STORKSAMLEngineException ex) { + Logger.error("Unable to validate Stork AuthenticationRequest: " + ex.getMessage()); + } + } + + // if there is no authn or attr request, raise error + if ((authnRequest == null) && (attrRequest == null)) { + Logger.error("There is no authentication or attribute request contained."); + throw new MOAIDException("stork.14", null); + } + // list attributes in the request + try { + for (PersonalAttribute personalAttribute : authnRequest.getPersonalAttributeList()) { + Logger.debug("Personal attribute found in request: " + personalAttribute.getName() + " isRequired: " + personalAttribute.isRequired()); + } + } catch (Exception e) { + Logger.error("Exception, attributes: " + e.getMessage()); + } + + + STORK2Request.setSTORKAuthnRequest(authnRequest); + STORK2Request.setSTORKAttrRequest(attrRequest); + + + return STORK2Request; } else { throw new MOAIDException("stork.14", null); // TODO Specify message - } + } } public IAction canHandleRequest(HttpServletRequest request, HttpServletResponse response) { -- cgit v1.2.3 From 8a1ec60f9531640ad8c4275c1c143ee29d915fe0 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Fri, 13 Jun 2014 19:02:24 +0200 Subject: company status --- .../moa/id/protocols/stork2/MandateRetrievalRequest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'id/server/idserverlib/src/main/java') 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 72dc81b35..29a4c23a4 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 @@ -129,6 +129,13 @@ public class MandateRetrievalRequest implements IAction { } else { attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), AttributeStatusType.NOT_AVAILABLE.value())); } + } else if (currentAttribute.getName().equals("status")) { + String status = getCompanyStatus(mandateContainer, currentAttribute); + if (status.length() > 0) { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(status), AttributeStatusType.AVAILABLE.value())); + } else { + attributeList.add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(status), AttributeStatusType.NOT_AVAILABLE.value())); + } } else if (currentAttribute.getName().equals("translatableType")) { String translatableType = getCompanyTranslatableType(mandateContainer, currentAttribute); if (translatableType.length() > 0) { @@ -264,6 +271,15 @@ public class MandateRetrievalRequest implements IAction { return ""; } + private String getCompanyStatus(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + String legalName = getLegalName(mandateContainer, sourceAttribute); + if (legalName.contains("in Liquidation") || legalName.contains("in Liqu.")) { + return "L"; // liqudation + } + return "R"; + } + + private String getCompanyType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { // retrieve the registered subject name String legalName = getLegalName(mandateContainer, sourceAttribute); -- cgit v1.2.3 From 3b2f0109faa906d34172daeec388dc58bf116cb3 Mon Sep 17 00:00:00 2001 From: Bojan Suzic Date: Fri, 13 Jun 2014 19:15:10 +0200 Subject: mandate refactor --- .../protocols/stork2/MandateRetrievalRequest.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'id/server/idserverlib/src/main/java') 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 29a4c23a4..4d306af22 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 @@ -279,12 +279,7 @@ public class MandateRetrievalRequest implements IAction { return "R"; } - - private String getCompanyType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { - // retrieve the registered subject name - String legalName = getLegalName(mandateContainer, sourceAttribute); - String legalIdentificationType = getLegalIdentificationType(mandateContainer, sourceAttribute); - + private String getCompanyType(String legalName, String legalIdentificationType, PersonalAttribute sourceAttrivbute) throws MOAIDException { // compile patterns for different organisation types // sources: USP, WKO, LexAndTax @@ -353,6 +348,13 @@ public class MandateRetrievalRequest implements IAction { return ""; } + private String getCompanyType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { + // retrieve the registered subject name and identification type + String legalName = getLegalName(mandateContainer, sourceAttribute); + String legalIdentificationType = getLegalIdentificationType(mandateContainer, sourceAttribute); + return getCompanyType(legalName, legalIdentificationType, sourceAttribute); + } + private String getCompanyTranslatableType(MandateContainer mandateContainer, PersonalAttribute sourceAttribute) throws MOAIDException { // retrieve first the company type String companyType = getCompanyType(mandateContainer, sourceAttribute); @@ -390,11 +392,12 @@ public class MandateRetrievalRequest implements IAction { RepresentationPersonType represented = new RepresentationPersonType(); if (mandateContainer instanceof CorporateBodyMandateContainer) { - represented.setELPIdentifier(geteLPIdentifier(mandateContainer, sourceAttribute)); - represented.setName(getLegalName(mandateContainer, sourceAttribute)); + CorporateBodyMandateContainer corporateBodyMandateContainer = (CorporateBodyMandateContainer)mandateContainer; + represented.setELPIdentifier("AT/" + corporateBodyMandateContainer.getCorpMandatorIdentificationValue()); + represented.setName(corporateBodyMandateContainer.getCorpMandatorFullName()); represented.setAddress(""); represented.setCanonicalAddress(new CanonicalAddressType()); - represented.setType(getCompanyType(mandateContainer, sourceAttribute)); + represented.setType(getCompanyType(corporateBodyMandateContainer.corpMandatorFullName, corporateBodyMandateContainer.corpMandatorIdentificationType, sourceAttribute)); } else if (mandateContainer instanceof PhyPersonMandateContainer) { PhyPersonMandateContainer phyPersonMandateContainer = (PhyPersonMandateContainer) mandateContainer; represented.setEIdentifier(""); // TODO CALCULATE -- cgit v1.2.3