diff options
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src')
| -rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/EidasResponseUtils.java | 91 | 
1 files changed, 50 insertions, 41 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 fa26c2c5..d71201ce 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 @@ -58,7 +58,7 @@ public class EidasResponseUtils {    /**     * Validate a eIDAS PersonalIdentifier attribute value This validation is done     * according to eIDAS SAML Attribute Profile - Section 2.2.3 Unique Identifier -   *  +   *     * @param uniqueID eIDAS attribute value of a unique identifier     * @return true if the uniqueID matches to eIDAS to Unique Identifier     *         specification, otherwise false @@ -74,9 +74,9 @@ public class EidasResponseUtils {     * Parse an eIDAS PersonalIdentifier attribute value into it components. This     * processing is done according to eIDAS SAML Attribute Profile - Section 2.2.3     * 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> @@ -84,7 +84,7 @@ public class EidasResponseUtils {     */    public static Triple<String, String, String> parseEidasPersonalIdentifier(String uniqueID) {      if (!validateEidasPersonalIdentifier(uniqueID)) { -      log.error("eIDAS attribute value for {} looks wrong formated. Value: {}",  +      log.error("eIDAS attribute value for {} looks wrong formated. Value: {}",            Constants.eIDAS_ATTR_PERSONALIDENTIFIER, uniqueID);        return null; @@ -94,27 +94,41 @@ public class EidasResponseUtils {    }    /** -   * Get eIDAS attribute-values from eIDAS Node attributes.  -   *  +   * 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,        ImmutableSet<? extends AttributeValue<?>> attributeValues) {      final List<String> stringListAttribute = new ArrayList<>(); -    if (attributeValues != null) { -      final AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition -          .getAttributeValueMarshaller(); -      for (final AttributeValue<?> attributeValue : attributeValues.asList()) { -        String valueString = null; -        try { -          valueString = attributeValueMarshaller.marshal((AttributeValue) attributeValue); + +    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(),  +              attributeValue.isNonLatinScriptAlternateVersion(),                AttributeValueTransliterator.needsTransliteration(valueString));            // if (attributeValue.isNonLatinScriptAlternateVersion()) { @@ -126,30 +140,25 @@ public class EidasResponseUtils {              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()); -       -    } else { -      log.info("Can not extract infos from 'null' attribute value"); -       +      }      } +    log.trace("Extract values: {} for attr: {}", +        StringUtils.join(stringListAttribute, ","), attributeDefinition.getFriendlyName()); +      return stringListAttribute;    }    /** -   * Convert eIDAS DateTime attribute to Java Object.  -   *  +   * Convert eIDAS DateTime attribute to Java Object. +   *     * @param attributeDefinition eIDAS attribute definition. -   * @param attributeValues eIDAS attribute value +   * @param attributeValues     eIDAS attribute value     * @return     */    @Nullable @@ -166,9 +175,9 @@ 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 @@ -183,7 +192,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) { @@ -208,7 +217,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) { @@ -229,7 +238,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) { @@ -253,7 +262,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)) { @@ -267,7 +276,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)) { @@ -281,7 +290,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)) { @@ -295,7 +304,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)) { @@ -309,7 +318,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)) { @@ -328,7 +337,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)) { | 
