diff options
author | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-02-22 13:31:30 +0100 |
---|---|---|
committer | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-02-22 13:31:30 +0100 |
commit | 8ab6c1a1d82f46d27e5019198c2a1b7926ac6e72 (patch) | |
tree | 02d8c309b04ca11524f254515111bef7ed4d9739 /eidas_modules/authmodule-eIDAS-v2/src/main/java | |
parent | 06b30e1aad923cf5ed034911c5949a294310fe24 (diff) | |
download | National_eIDAS_Gateway-8ab6c1a1d82f46d27e5019198c2a1b7926ac6e72.tar.gz National_eIDAS_Gateway-8ab6c1a1d82f46d27e5019198c2a1b7926ac6e72.tar.bz2 National_eIDAS_Gateway-8ab6c1a1d82f46d27e5019198c2a1b7926ac6e72.zip |
Add method to parse citizen country code from eIDAS personal identifier
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java')
-rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java | 25 |
1 files changed, 22 insertions, 3 deletions
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: <br> + * @return {@link Triple} that contains: <br> * First : citizen country <br> * Second: destination country <br> * Third : unique identifier <br> * or null if the attribute value has a wrong format */ - public static Triple<String, String, String> 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)); - } /** @@ -336,6 +336,25 @@ public class EidasResponseUtils { } /** + * 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<String, String, String> 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. * * @param taxReferenceObj eIDAS TaxReference attribute information |