diff options
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java')
-rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java | 118 |
1 files changed, 70 insertions, 48 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 aafcd8b9..ef8822aa 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 @@ -19,7 +19,7 @@ * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. -*/ + */ package at.asitplus.eidas.specific.modules.auth.eidas.v2.utils; @@ -28,6 +28,7 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasAttribute import at.gv.e_government.reference.namespace.persondata._20020228.PostalAddressType; import at.gv.egiz.eaaf.core.impl.data.Triple; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import eu.eidas.auth.commons.attribute.AttributeDefinition; import eu.eidas.auth.commons.attribute.AttributeValue; import eu.eidas.auth.commons.attribute.AttributeValueMarshaller; @@ -57,7 +58,7 @@ public class EidasResponseUtils { * * @param uniqueID eIDAS attribute value of a unique identifier * @return true if the uniqueID matches to eIDAS to Unique Identifier - * specification, otherwise false + * specification, otherwise false */ public static boolean validateEidasPersonalIdentifier(String uniqueID) { final Pattern pattern = Pattern.compile(PERSONALIDENIFIER_VALIDATION_PATTERN); @@ -73,10 +74,10 @@ public class EidasResponseUtils { * * @param uniqueID eIDAS attribute value of a unique identifier * @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 + * 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)) { @@ -93,58 +94,79 @@ public class EidasResponseUtils { * Get eIDAS attribute-values from eIDAS Node attributes. * * @param attributeDefinition eIDAS attribute definition - * @param attributeValues Attributes from eIDAS response - * @return Set of attribute values. If more then one value than the first value contains the 'Latin' value. + * @param attributeValues Attributes from eIDAS response + * @return Set of attribute values. If more then one value than the first value + * contains the 'Latin' value. */ // TODO: check possible problem with nonLatinCharacters public static List<String> translateStringListAttribute(AttributeDefinition<?> attributeDefinition, - ImmutableList<? extends AttributeValue<?>> attributeValues) { + @Nullable ImmutableSet<? extends AttributeValue<?>> attributeValues) { final List<String> stringListAttribute = new ArrayList<>(); - final AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition - .getAttributeValueMarshaller(); - for (final AttributeValue<?> attributeValue : attributeValues) { - String valueString = null; - try { - valueString = attributeValueMarshaller.marshal((AttributeValue) attributeValue); - - log.trace("Find attr: {} with value: {} nonLatinFlag: {} needTransliteration: {}", - attributeDefinition.getFriendlyName(), attributeValue.toString(), - attributeValue.isNonLatinScriptAlternateVersion(), - AttributeValueTransliterator.needsTransliteration(valueString)); - - // if (attributeValue.isNonLatinScriptAlternateVersion()) { - if (!AttributeValueTransliterator.needsTransliteration(valueString)) { - stringListAttribute.add(0, valueString); - - } else { - log.trace("Find 'needsTransliteration' flag. Setting this value at last list element ... "); - stringListAttribute.add(valueString); + if (attributeValues == null) { + log.info("Can not extract infos from 'null' attribute value"); - } + } else { + final AttributeValueMarshaller<?> attributeValueMarshaller = + attributeDefinition.getAttributeValueMarshaller(); + for (final AttributeValue<?> attributeValue : attributeValues) { + String valueString = null; + try { + valueString = attributeValueMarshaller.marshal((AttributeValue) attributeValue); + + log.trace("Find attr: {} with value: {} nonLatinFlag: {} needTransliteration: {}", + attributeDefinition.getFriendlyName(), attributeValue.toString(), + attributeValue.isNonLatinScriptAlternateVersion(), + AttributeValueTransliterator.needsTransliteration(valueString)); + + // if (attributeValue.isNonLatinScriptAlternateVersion()) { + if (!AttributeValueTransliterator.needsTransliteration(valueString)) { + stringListAttribute.add(0, valueString); + + } else { + log.trace("Find 'needsTransliteration' flag. Setting this value at last list element ... "); + stringListAttribute.add(valueString); + + log.trace("Find attr: {} with value: {} nonLatinFlag: {} needTransliteration: {}", + attributeDefinition.getFriendlyName(), attributeValue.toString(), + attributeValue.isNonLatinScriptAlternateVersion(), + AttributeValueTransliterator.needsTransliteration(valueString)); + + // if (attributeValue.isNonLatinScriptAlternateVersion()) { + if (!AttributeValueTransliterator.needsTransliteration(valueString)) { + stringListAttribute.add(0, valueString); + + } else { + log.trace("Find 'needsTransliteration' flag. Setting this value at last list element ... "); + stringListAttribute.add(valueString); + + } + } + } catch (final AttributeValueMarshallingException e) { + throw new IllegalStateException(e); - } catch (final AttributeValueMarshallingException e) { - throw new IllegalStateException(e); + } } - } + log.trace("Extract values: {} for attr: {}", + StringUtils.join(stringListAttribute, ","), attributeDefinition.getFriendlyName()); - log.trace("Extract values: {} for attr: {}", - StringUtils.join(stringListAttribute, ","), attributeDefinition.getFriendlyName()); + } return stringListAttribute; } + /** * Convert eIDAS DateTime attribute to Java Object. * * @param attributeDefinition eIDAS attribute definition. - * @param attributeValues eIDAS attribute value + * @param attributeValues eIDAS attribute value * @return */ @Nullable public static DateTime translateDateAttribute(AttributeDefinition<?> attributeDefinition, - ImmutableList<? extends AttributeValue<?>> attributeValues) { + ImmutableList<? extends AttributeValue<?>> attributeValues) { if (attributeValues.size() != 0) { final AttributeValue<?> firstAttributeValue = attributeValues.get(0); return (DateTime) firstAttributeValue.getValue(); @@ -158,12 +180,12 @@ public class EidasResponseUtils { * Concert eIDAS Address attribute to Java object. * * @param attributeDefinition eIDAS attribute definition - * @param attributeValues eIDAS attribute value + * @param attributeValues eIDAS attribute value * @return */ @Nullable public static PostalAddress translateAddressAttribute(AttributeDefinition<?> attributeDefinition, - ImmutableList<? extends AttributeValue<?>> attributeValues) { + ImmutableList<? extends AttributeValue<?>> attributeValues) { final AttributeValue<?> firstAttributeValue = attributeValues.get(0); return (PostalAddress) firstAttributeValue.getValue(); } @@ -173,7 +195,7 @@ public class EidasResponseUtils { * * @param currentAddressObj eIDAS current address information * @return current address or null if no attribute is available - * @throws EidasAttributeException if eIDAS attribute is of a wrong type + * @throws EidasAttributeException if eIDAS attribute is of a wrong type */ public static PostalAddressType processAddress(Object currentAddressObj) throws EidasAttributeException { if (currentAddressObj != null) { @@ -198,7 +220,7 @@ public class EidasResponseUtils { * * @param birthNameObj eIDAS birthname information * @return birthName or null if no attribute is available - * @throws EidasAttributeException if eIDAS attribute is of a wrong type + * @throws EidasAttributeException if eIDAS attribute is of a wrong type */ public static String processBirthName(Object birthNameObj) throws EidasAttributeException { if (birthNameObj != null) { @@ -219,7 +241,7 @@ public class EidasResponseUtils { * * @param placeOfBirthObj eIDAS Place-of-Birth information * @return place of Birth or null if no attribute is available - * @throws EidasAttributeException if eIDAS attribute is of a wrong type + * @throws EidasAttributeException if eIDAS attribute is of a wrong type */ public static String processPlaceOfBirth(Object placeOfBirthObj) throws EidasAttributeException { if (placeOfBirthObj != null) { @@ -243,7 +265,7 @@ public class EidasResponseUtils { * * @param dateOfBirthObj eIDAS date-of-birth attribute information * @return formated user's date-of-birth - * @throws EidasAttributeException if NO attribute is available + * @throws EidasAttributeException if NO attribute is available */ public static DateTime processDateOfBirth(Object dateOfBirthObj) throws EidasAttributeException { if (!(dateOfBirthObj instanceof DateTime)) { @@ -257,7 +279,7 @@ public class EidasResponseUtils { * * @param dateOfBirthObj eIDAS date-of-birth attribute information * @return formated user's date-of-birth as string - * @throws EidasAttributeException if NO attribute is available + * @throws EidasAttributeException if NO attribute is available */ public static String processDateOfBirthToString(Object dateOfBirthObj) throws EidasAttributeException { if (!(dateOfBirthObj instanceof DateTime)) { @@ -271,7 +293,7 @@ public class EidasResponseUtils { * * @param givenNameObj eIDAS givenName attribute information * @return formated user's givenname - * @throws EidasAttributeException if NO attribute is available + * @throws EidasAttributeException if NO attribute is available */ public static String processGivenName(Object givenNameObj) throws EidasAttributeException { if (!(givenNameObj instanceof String)) { @@ -285,7 +307,7 @@ public class EidasResponseUtils { * * @param familyNameObj eIDAS familyName attribute information * @return formated user's familyname - * @throws EidasAttributeException if NO attribute is available + * @throws EidasAttributeException if NO attribute is available */ public static String processFamilyName(Object familyNameObj) throws EidasAttributeException { if (!(familyNameObj instanceof String)) { @@ -299,7 +321,7 @@ public class EidasResponseUtils { * * @param personalIdObj eIDAS PersonalIdentifierAttribute * @return Unique personal identifier without country-code information - * @throws EidasAttributeException if NO attribute is available + * @throws EidasAttributeException if NO attribute is available */ public static String processPseudonym(Object personalIdObj) throws EidasAttributeException { if (!(personalIdObj instanceof String)) { @@ -318,7 +340,7 @@ public class EidasResponseUtils { * * @param taxReferenceObj eIDAS TaxReference attribute information * @return formated user's TaxReference - * @throws EidasAttributeException if NO attribute is available + * @throws EidasAttributeException if NO attribute is available */ public static String processTaxReference(Object taxReferenceObj) throws EidasAttributeException { if (!(taxReferenceObj instanceof String)) { @@ -326,4 +348,4 @@ public class EidasResponseUtils { } return (String) taxReferenceObj; } -} +}
\ No newline at end of file |