diff options
author | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-07-12 11:49:39 +0200 |
---|---|---|
committer | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-07-12 11:49:39 +0200 |
commit | 49d18b25cd247c5d5f564719d16a829f6e85d8af (patch) | |
tree | af83719eda001df3417b3466ac8237c33b8076de /eidas_modules/authmodule-eIDAS-v2 | |
parent | 09af792ce3ed3df430f8d7ae6099f284756147a0 (diff) | |
download | National_eIDAS_Gateway-49d18b25cd247c5d5f564719d16a829f6e85d8af.tar.gz National_eIDAS_Gateway-49d18b25cd247c5d5f564719d16a829f6e85d8af.tar.bz2 National_eIDAS_Gateway-49d18b25cd247c5d5f564719d16a829f6e85d8af.zip |
Extract common code for converting eIDAS attributes to simple map
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2')
3 files changed, 88 insertions, 130 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java index fe3a9560..135eeec1 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java @@ -25,7 +25,6 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks; import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.MatchedPersonResult; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPostProcessingException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasAttributeException; @@ -34,31 +33,20 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidPr import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterOperationStatus; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterStatusResults; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; import at.gv.egiz.eaaf.core.impl.idp.auth.modules.AbstractAuthServletTask; -import com.google.common.collect.ImmutableMap; -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.light.ILightResponse; -import eu.eidas.auth.commons.protocol.eidas.impl.PostalAddress; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; -import org.joda.time.DateTime; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; import java.util.Map; -import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK; import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK; /** @@ -170,45 +158,9 @@ public class AlternativeSearchTask extends AbstractAuthServletTask { throws EidasAttributeException, EidPostProcessingException { final ILightResponse eidasResponse = MatchingTaskUtils.getAuthProcessDataWrapper(pendingReq) .getGenericDataFromSession(Constants.DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE, ILightResponse.class); - Map<String, Object> simpleMap = convertEidasAttrToSimpleMap(eidasResponse.getAttributes().getAttributeMap()); + Map<String, Object> simpleMap = MatchingTaskUtils.convertEidasAttrToSimpleMap( + eidasResponse.getAttributes().getAttributeMap(), log); return eidPostProcessor.postProcess(simpleMap); } - private Map<String, Object> convertEidasAttrToSimpleMap( - ImmutableMap<AttributeDefinition<?>, ImmutableSet<? extends AttributeValue<?>>> attributeMap) { - final Map<String, Object> result = new HashMap<>(); - for (final AttributeDefinition<?> el : attributeMap.keySet()) { - final Class<?> parameterizedType = el.getParameterizedType(); - if (DateTime.class.equals(parameterizedType)) { - final DateTime attribute = EidasResponseUtils.translateDateAttribute(el, attributeMap.get(el).asList()); - if (attribute != null) { - result.put(el.getFriendlyName(), attribute); - log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), attribute); - } else { - log.info("Ignore empty 'DateTime' attribute"); - } - } else if (PostalAddress.class.equals(parameterizedType)) { - final PostalAddress addressAttribute = EidasResponseUtils - .translateAddressAttribute(el, attributeMap.get(el).asList()); - if (addressAttribute != null) { - result.put(el.getFriendlyName(), addressAttribute); - log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), addressAttribute); - } else { - log.info("Ignore empty 'PostalAddress' attribute"); - } - } else { - final List<String> natPersonIdObj = EidasResponseUtils.translateStringListAttribute(el, attributeMap.get(el)); - final String stringAttr = natPersonIdObj.get(0); - if (StringUtils.isNotEmpty(stringAttr)) { - result.put(el.getFriendlyName(), stringAttr); - log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), stringAttr); - } else { - log.info("Ignore empty 'String' attribute"); - } - } - } - log.debug("Receive #{} attributes with names: {}", result.size(), result.keySet()); - return result; - } - } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java index a55af1c4..2341b733 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java @@ -34,28 +34,18 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidPr import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterOperationStatus; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterStatusResults; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; import at.gv.egiz.eaaf.core.impl.idp.auth.modules.AbstractAuthServletTask; -import com.google.common.collect.ImmutableMap; -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.light.ILightResponse; -import eu.eidas.auth.commons.protocol.eidas.impl.PostalAddress; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; -import org.joda.time.DateTime; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; import java.util.Map; import static at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK; @@ -204,45 +194,9 @@ public class InitialSearchTask extends AbstractAuthServletTask { throws EidasAttributeException, EidPostProcessingException { final ILightResponse eidasResponse = MatchingTaskUtils.getAuthProcessDataWrapper(pendingReq) .getGenericDataFromSession(Constants.DATA_FULL_EIDAS_RESPONSE, ILightResponse.class); - Map<String, Object> simpleMap = convertEidasAttrToSimpleMap(eidasResponse.getAttributes().getAttributeMap()); + Map<String, Object> simpleMap = MatchingTaskUtils.convertEidasAttrToSimpleMap( + eidasResponse.getAttributes().getAttributeMap(), log); return eidPostProcessor.postProcess(simpleMap); } - private Map<String, Object> convertEidasAttrToSimpleMap( - ImmutableMap<AttributeDefinition<?>, ImmutableSet<? extends AttributeValue<?>>> attributeMap) { - final Map<String, Object> result = new HashMap<>(); - for (final AttributeDefinition<?> el : attributeMap.keySet()) { - final Class<?> parameterizedType = el.getParameterizedType(); - if (DateTime.class.equals(parameterizedType)) { - final DateTime attribute = EidasResponseUtils.translateDateAttribute(el, attributeMap.get(el).asList()); - if (attribute != null) { - result.put(el.getFriendlyName(), attribute); - log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), attribute); - } else { - log.info("Ignore empty 'DateTime' attribute"); - } - } else if (PostalAddress.class.equals(parameterizedType)) { - final PostalAddress addressAttribute = EidasResponseUtils - .translateAddressAttribute(el, attributeMap.get(el).asList()); - if (addressAttribute != null) { - result.put(el.getFriendlyName(), addressAttribute); - log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), addressAttribute); - } else { - log.info("Ignore empty 'PostalAddress' attribute"); - } - } else { - final List<String> natPersonIdObj = EidasResponseUtils.translateStringListAttribute(el, attributeMap.get(el)); - final String stringAttr = natPersonIdObj.get(0); - if (StringUtils.isNotEmpty(stringAttr)) { - result.put(el.getFriendlyName(), stringAttr); - log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), stringAttr); - } else { - log.info("Ignore empty 'String' attribute"); - } - } - } - log.debug("Receive #{} attributes with names: {}", result.size(), result.keySet()); - return result; - } - } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/MatchingTaskUtils.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/MatchingTaskUtils.java index c2392a79..c7631f53 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/MatchingTaskUtils.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/utils/MatchingTaskUtils.java @@ -1,49 +1,60 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.utils; -import javax.annotation.Nullable; - -import org.springframework.lang.NonNull; - import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.MatchedPersonResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidProcessingService; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterStatusResults; import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper; +import com.google.common.collect.ImmutableMap; +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.protocol.eidas.impl.PostalAddress; +import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.slf4j.Logger; +import org.springframework.lang.NonNull; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class MatchingTaskUtils { /** * Get eIDAS log-in information from session. - * + * * @param pendingReq Current pendingRequest * @return eIDAS infos or <code>null</code> if not exist */ @Nullable - public static SimpleEidasData getInitialEidasData(IRequest pendingReq) { + public static SimpleEidasData getInitialEidasData(IRequest pendingReq) { return getAuthProcessDataWrapper(pendingReq).getGenericDataFromSession( Constants.DATA_SIMPLE_EIDAS, SimpleEidasData.class); - + } /** * Set eIDAS log-in information to session. - * + * * @param pendingReq Current pendingRequest - * @param eidasData infos from eIDAS Proxy-Service + * @param eidasData infos from eIDAS Proxy-Service * @throws EaafStorageException In case of data can not be add into session */ @Nullable - public static void storeInitialEidasData(IRequest pendingReq, SimpleEidasData eidasData) + public static void storeInitialEidasData(IRequest pendingReq, SimpleEidasData eidasData) throws EaafStorageException { getAuthProcessDataWrapper(pendingReq).setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, eidasData); - + } - + /** * Get intermediate matching result from session. - * + * * @param pendingReq Current pendingRequest * @return Intermediate matching result or <code>null</code> if not exist */ @@ -51,27 +62,27 @@ public class MatchingTaskUtils { public static RegisterStatusResults getIntermediateMatchingResult(IRequest pendingReq) { return getAuthProcessDataWrapper(pendingReq).getGenericDataFromSession(Constants.DATA_INTERMEDIATE_RESULT, RegisterStatusResults.class); - + } - + /** * Store intermediate matching result into session. - * - * @param pendingReq Current pendingRequest + * + * @param pendingReq Current pendingRequest * @param registerData Intermediate matching result information * @throws EaafStorageException In case of data can not be add into session */ @Nullable - public static void storeIntermediateMatchingResult(IRequest pendingReq, RegisterStatusResults registerData) + public static void storeIntermediateMatchingResult(IRequest pendingReq, RegisterStatusResults registerData) throws EaafStorageException { getAuthProcessDataWrapper(pendingReq).setGenericDataToSession( Constants.DATA_INTERMEDIATE_RESULT, registerData); - + } /** * Get intermediate matching result from session. - * + * * @param pendingReq Current pendingRequest * @return Intermediate matching result or <code>null</code> if not exist */ @@ -79,39 +90,80 @@ public class MatchingTaskUtils { public static MatchedPersonResult getFinalMatchingResult(IRequest pendingReq) { return getAuthProcessDataWrapper(pendingReq).getGenericDataFromSession(Constants.DATA_PERSON_MATCH_RESULT, MatchedPersonResult.class); - + } - + /** * Store intermediate matching result into session. - * - * @param pendingReq Current pendingRequest + * + * @param pendingReq Current pendingRequest * @param personInfos Person information after a successful match * @throws EaafStorageException In case of data can not be add into session */ @Nullable - public static void storeFinalMatchingResult(IRequest pendingReq, MatchedPersonResult personInfos) + public static void storeFinalMatchingResult(IRequest pendingReq, MatchedPersonResult personInfos) throws EaafStorageException { getAuthProcessDataWrapper(pendingReq).setGenericDataToSession( Constants.DATA_PERSON_MATCH_RESULT, personInfos); - + } - + /** * Get holder for authentication information for the current process. - * + * * @param pendingReq Current pendingRequest * @return {@link AuthProcessDataWrapper} */ @NonNull public static AuthProcessDataWrapper getAuthProcessDataWrapper(IRequest pendingReq) { return pendingReq.getSessionData(AuthProcessDataWrapper.class); - + } - + + /** + * Convert attributes from eIDAS Authn Response into a simple map, to be used from + * {@link ICcSpecificEidProcessingService#postProcess(Map)}. + */ + public static Map<String, Object> convertEidasAttrToSimpleMap( + ImmutableMap<AttributeDefinition<?>, ImmutableSet<? extends AttributeValue<?>>> attributeMap, Logger log) { + final Map<String, Object> result = new HashMap<>(); + for (final AttributeDefinition<?> el : attributeMap.keySet()) { + final Class<?> parameterizedType = el.getParameterizedType(); + if (DateTime.class.equals(parameterizedType)) { + final DateTime attribute = EidasResponseUtils.translateDateAttribute(el, attributeMap.get(el).asList()); + if (attribute != null) { + result.put(el.getFriendlyName(), attribute); + log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), attribute); + } else { + log.info("Ignore empty 'DateTime' attribute"); + } + } else if (PostalAddress.class.equals(parameterizedType)) { + final PostalAddress addressAttribute = EidasResponseUtils + .translateAddressAttribute(el, attributeMap.get(el).asList()); + if (addressAttribute != null) { + result.put(el.getFriendlyName(), addressAttribute); + log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), addressAttribute); + } else { + log.info("Ignore empty 'PostalAddress' attribute"); + } + } else { + final List<String> natPersonIdObj = EidasResponseUtils.translateStringListAttribute(el, attributeMap.get(el)); + final String stringAttr = natPersonIdObj.get(0); + if (StringUtils.isNotEmpty(stringAttr)) { + result.put(el.getFriendlyName(), stringAttr); + log.trace("Find attr '{}' with value: {}", el.getFriendlyName(), stringAttr); + } else { + log.info("Ignore empty 'String' attribute"); + } + } + } + log.debug("Receive #{} attributes with names: {}", result.size(), result.keySet()); + return result; + } + private MatchingTaskUtils() { //hide constructor in case of class contains only static methods - + } - + } |