diff options
Diffstat (limited to 'eaaf_core/src/main/java')
4 files changed, 81 insertions, 37 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java new file mode 100644 index 00000000..10e6464b --- /dev/null +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/utils/IJsonMapper.java @@ -0,0 +1,32 @@ +package at.gv.egiz.eaaf.core.api.utils; + +import java.io.IOException; + +import at.gv.egiz.eaaf.core.exceptions.EAAFJsonMapperException; + +public interface IJsonMapper { + + + /** + * Serialize an object to a JSON string. + * @param value the object to serialize + * @return a JSON string + * @throws JsonProcessingException thrown when an error occurs during serialization + */ + String serialize(Object value) throws EAAFJsonMapperException; + + /** + * Deserialize a JSON string. + * + * @param value the JSON string to deserialize + * @param clazz optional parameter that determines the type of the returned object. If not set, an {@link Object} is returned. + * @return the deserialized JSON string as an object of type {@code clazz} or {@link Object} + * @throws JsonParseException if the JSON string contains invalid content. + * @throws JsonMappingException if the input JSON structure does not match structure expected for result type + * @throws IOException if an I/O problem occurs (e.g. unexpected end-of-input) + */ + <T> Object deserialize(String value, Class<T> clazz) throws EAAFJsonMapperException; + + //<T> Object deserialize(String value, TypeReference<T> clazz) throws EAAFJsonMapperException; + +}
\ No newline at end of file diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java index 47b1ecf9..558a9a33 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java @@ -97,7 +97,9 @@ public abstract class AbstractAuthenticationDataBuilder implements IAuthenticati Assert.notNull(authData, "AuthData is null"); } - + + } catch ( EAAFAuthenticationException e) { + throw e; } catch (XPathException | DOMException | EAAFException e) { log.warn("Can not build authentication data from auth. process information"); @@ -461,10 +463,8 @@ public abstract class AbstractAuthenticationDataBuilder implements IAuthenticati authData.setBPKType(result.getSecond()); } else { - log.warn("Can not build authData, because moaSession include no valid bPK, encrypted bPK or baseID"); - throw new EAAFBuilderException("builder.08", new Object[]{"No valid " + PVPAttributeDefinitions.BPK_FRIENDLY_NAME - + " or " + PVPAttributeDefinitions.EID_SOURCE_PIN_FRIENDLY_NAME - + " or " + PVPAttributeDefinitions.ENC_BPK_LIST_FRIENDLY_NAME}, + log.warn("Can not build authData, because moaSession include no valid bPK, encrypted bPK or sourceID"); + throw new EAAFBuilderException("builder.13", new Object[]{pendingReq.getServiceProviderConfiguration().getAreaSpecificTargetIdentifier()}, "No valid " + PVPAttributeDefinitions.BPK_FRIENDLY_NAME + " or " + PVPAttributeDefinitions.EID_SOURCE_PIN_FRIENDLY_NAME + " or " + PVPAttributeDefinitions.ENC_BPK_LIST_FRIENDLY_NAME); @@ -550,7 +550,7 @@ public abstract class AbstractAuthenticationDataBuilder implements IAuthenticati * @return true, if bPK-Type matchs to Service-Provider configuration, otherwise false */ @Deprecated - private boolean matchsReceivedbPKToOnlineApplication(ISPConfiguration oaParam, String bPKType) { + protected boolean matchsReceivedbPKToOnlineApplication(ISPConfiguration oaParam, String bPKType) { return oaParam.getAreaSpecificTargetIdentifier().equals(bPKType); } diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java index 7005c930..714ffc9d 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java @@ -26,9 +26,12 @@ *******************************************************************************/ package at.gv.egiz.eaaf.core.impl.idp.builder.attributes; +import javax.annotation.Nonnull; + import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.Assert; import at.gv.egiz.eaaf.core.api.data.EAAFConstants; import at.gv.egiz.eaaf.core.api.idp.IAttributeGenerator; @@ -44,18 +47,21 @@ public class BPKAttributeBuilder implements IPVPAttributeBuilder { private static final Logger log = LoggerFactory.getLogger(BPKAttributeBuilder.class); public static final String DELIMITER_BPKTYPE_BPK = ":"; + @Override public String getName() { return BPK_NAME; } + @Override public <ATT> ATT build(ISPConfiguration oaParam, IAuthData authData, IAttributeGenerator<ATT> g) throws AttributeBuilderException { - String result = getBpkForSP(authData); + final String result = getBpkForSP(authData); log.trace("Authenticate user with bPK/wbPK: " + result); return g.buildStringAttribute(BPK_FRIENDLY_NAME, BPK_NAME, result); } + @Override public <ATT> ATT buildEmpty(IAttributeGenerator<ATT> g) { return g.buildEmptyAttribute(BPK_FRIENDLY_NAME, BPK_NAME); } @@ -68,8 +74,8 @@ public class BPKAttributeBuilder implements IPVPAttributeBuilder { * @throws UnavailableAttributeException */ protected String getBpkForSP(IAuthData authData) throws UnavailableAttributeException { - String bpk = attrMaxSize(authData.getBPK()); - String type = removeBpkTypePrefix(authData.getBPKType()); + final String bpk = attrMaxSize(authData.getBPK()); + final String type = removeBpkTypePrefix(authData.getBPKType()); if (StringUtils.isEmpty(bpk)) throw new UnavailableAttributeException(BPK_NAME); @@ -98,7 +104,9 @@ public class BPKAttributeBuilder implements IPVPAttributeBuilder { * @param type * @return */ - protected String removeBpkTypePrefix(String type) { + @Nonnull + protected String removeBpkTypePrefix(@Nonnull String type) { + Assert.isTrue(type != null, "bPKType is 'NULL'"); if (type.startsWith(EAAFConstants.URN_PREFIX_WBPK)) return type.substring((EAAFConstants.URN_PREFIX_WBPK).length()); diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java index f0a082c3..efc47337 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java @@ -36,6 +36,9 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,11 +84,11 @@ public class KeyValueUtils { * @return Child key {String} if it exists or null */ public static String getFirstChildAfterPrefix(String key, String prefix) { - String idAfterPrefix = removePrefixFromKey(key, prefix); + final String idAfterPrefix = removePrefixFromKey(key, prefix); if (idAfterPrefix != null) { - int index = idAfterPrefix.indexOf(KEY_DELIMITER); + final int index = idAfterPrefix.indexOf(KEY_DELIMITER); if (index > 0) { - String adding = idAfterPrefix.substring(0, index); + final String adding = idAfterPrefix.substring(0, index); if (!(adding.isEmpty())) { return adding; @@ -108,7 +111,7 @@ public class KeyValueUtils { */ public static String getPrefixFromKey(String key, String suffix) { if (key != null && key.endsWith(suffix)) { - String idPreforeSuffix = key.substring(0, key.length()-suffix.length()); + final String idPreforeSuffix = key.substring(0, key.length()-suffix.length()); if (idPreforeSuffix.endsWith(KEY_DELIMITER)) return idPreforeSuffix.substring(0, idPreforeSuffix.length()-1); else @@ -131,7 +134,7 @@ public class KeyValueUtils { if (key!=null && key.startsWith(prefix)) { String afterPrefix = key.substring(prefix.length()); - int index = afterPrefix.indexOf(KEY_DELIMITER); + final int index = afterPrefix.indexOf(KEY_DELIMITER); if (index == 0) { afterPrefix = afterPrefix.substring(1); @@ -151,11 +154,11 @@ public class KeyValueUtils { * @return {Map<String, String>} of key/value pairs without prefix in key, but never null */ public static Map<String, String> removePrefixFromKeys(Map<String, String> keys, String prefix) { - Map<String, String> result = new HashMap<String, String>(); - Iterator<Entry<String, String>> interator = keys.entrySet().iterator(); + final Map<String, String> result = new HashMap<String, String>(); + final Iterator<Entry<String, String>> interator = keys.entrySet().iterator(); while(interator.hasNext()) { - Entry<String, String> el = interator.next(); - String newKey = removePrefixFromKey(el.getKey(), prefix); + final Entry<String, String> el = interator.next(); + final String newKey = removePrefixFromKey(el.getKey(), prefix); if (StringUtils.isNotEmpty(newKey)) { result.put(newKey, el.getValue()); } @@ -186,10 +189,10 @@ public class KeyValueUtils { * @return {Map<String, String>} of key/value pairs in which all keys are absolute but never null */ public static Map<String, String> makeKeysAbsolut(Map<String, String> input, String prefix, String absolutIdentifier) { - Map<String, String> result = new HashMap<String, String>(); - Iterator<Entry<String, String>> interator = input.entrySet().iterator(); + final Map<String, String> result = new HashMap<String, String>(); + final Iterator<Entry<String, String>> interator = input.entrySet().iterator(); while(interator.hasNext()) { - Entry<String, String> el = interator.next(); + final Entry<String, String> el = interator.next(); if (!el.getKey().startsWith(absolutIdentifier)) { //key is not absolute -> add prefix result.put(prefix @@ -213,7 +216,7 @@ public class KeyValueUtils { */ public static String getParentKey(String key) { if (StringUtils.isNotEmpty(key)) { - int index = key.lastIndexOf(KEY_DELIMITER); + final int index = key.lastIndexOf(KEY_DELIMITER); if (index > 0) { return key.substring(0, index); @@ -232,13 +235,13 @@ public class KeyValueUtils { */ public static int findNextFreeListCounter(String[] input, String listPrefix) { - List<Integer> counters = new ArrayList<Integer>(); + final List<Integer> counters = new ArrayList<Integer>(); if (input == null || input.length == 0) return 0; else { - for (String key : input) { - String listIndex = getFirstChildAfterPrefix(key, listPrefix); + for (final String key : input) { + final String listIndex = getFirstChildAfterPrefix(key, listPrefix); counters.add(Integer.parseInt(listIndex)); } @@ -259,7 +262,7 @@ public class KeyValueUtils { if (keySet.isEmpty()) return 0; - String[] array = new String[keySet.size()]; + final String[] array = new String[keySet.size()]; keySet.toArray(array); return findNextFreeListCounter(array, listPrefix); } @@ -278,8 +281,8 @@ public class KeyValueUtils { public static String normalizeCSVValueString(String value) { String normalizedCodes = null; if (StringUtils.isNotEmpty(value)) { - String[] codes = value.split(CSV_DELIMITER); - for (String el: codes) { + final String[] codes = value.split(CSV_DELIMITER); + for (final String el: codes) { if (normalizedCodes == null) normalizedCodes = StringUtils.chomp(el.trim()); else @@ -301,7 +304,7 @@ public class KeyValueUtils { */ public static boolean isCSVValueString(String value) { if (StringUtils.isNotEmpty(value)) { - String[] codes = value.split(CSV_DELIMITER); + final String[] codes = value.split(CSV_DELIMITER); if (codes.length >= 2) { if (StringUtils.isNotEmpty(codes[1].trim())) return true; @@ -322,11 +325,12 @@ public class KeyValueUtils { * @param csv CSV encoded input data * @return List of CSV normalized values, but never null */ - public static List<String> getListOfCSVValues(String csv) { - List<String> list = new ArrayList<String>(); + @Nonnull + public static List<String> getListOfCSVValues(@Nullable String csv) { + final List<String> list = new ArrayList<String>(); if (StringUtils.isNotEmpty(csv)) { - String[] values = csv.split(CSV_DELIMITER); - for (String el: values) + final String[] values = csv.split(CSV_DELIMITER); + for (final String el: values) list.add(el.trim()); } @@ -343,10 +347,10 @@ public class KeyValueUtils { * @return Map of Key / Value pairs, but never null */ public static Map<String, String> convertListToMap(List<String> elements) { - Map<String, String> map = new HashMap<String, String>(); - for (String el : elements) { + final Map<String, String> map = new HashMap<String, String>(); + for (final String el : elements) { if (el.contains(KEYVVALUEDELIMITER)) { - String[] split = el.split(KEYVVALUEDELIMITER); + final String[] split = el.split(KEYVVALUEDELIMITER); map.put(split[0], split[1]); } else |