From 8ab6c1a1d82f46d27e5019198c2a1b7926ac6e72 Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Mon, 22 Feb 2021 13:31:30 +0100 Subject: Add method to parse citizen country code from eIDAS personal identifier --- .../auth/eidas/v2/utils/EidasResponseUtils.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java index 1d47df20..010681a9 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java @@ -47,6 +47,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.eIDAS_ATTR_PERSONALIDENTIFIER; + public class EidasResponseUtils { private static final Logger log = LoggerFactory.getLogger(EidasResponseUtils.class); public static final String PERSONALIDENIFIER_VALIDATION_PATTERN = "^[A-Z,a-z]{2}/[A-Z,a-z]{2}/.*"; @@ -72,13 +74,12 @@ public class EidasResponseUtils { * Unique Identifier * * @param uniqueID eIDAS attribute value of a unique identifier - * @return {@link Trible} that contains:
+ * @return {@link Triple} that contains:
* First : citizen country
* Second: destination country
* Third : unique identifier
* or null if the attribute value has a wrong format */ - public static Triple parseEidasPersonalIdentifier(String uniqueID) { if (!validateEidasPersonalIdentifier(uniqueID)) { log.error("eIDAS attribute value for {} looks wrong formated. Value: {}", @@ -87,7 +88,6 @@ public class EidasResponseUtils { } return Triple.newInstance(uniqueID.substring(0, 2), uniqueID.substring(3, 5), uniqueID.substring(6)); - } /** @@ -335,6 +335,25 @@ public class EidasResponseUtils { return eIdentifier.getThird(); } + /** + * Post-Process the eIDAS pseudonym to citizen country code. + * + * @param personalIdObj eIDAS PersonalIdentifierAttribute + * @return Citizen Country Code + * @throws EidasAttributeException if NO attribute is available + */ + public static String processCountryCode(Object personalIdObj) throws EidasAttributeException { + if (!(personalIdObj instanceof String)) { + throw new EidasAttributeException(Constants.eIDAS_ATTR_PERSONALIDENTIFIER); + } + final Triple eIdentifier = + EidasResponseUtils.parseEidasPersonalIdentifier((String) personalIdObj); + if (eIdentifier == null || eIdentifier.getFirst() == null) { + throw new EidasAttributeException("Error processing eIdentifier"); + } + return eIdentifier.getFirst(); + } + /** * Post-Process the eIDAS TaxReference attribute. * -- cgit v1.2.3