diff options
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java | 44 | ||||
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/X509Utils.java | 15 |
2 files changed, 31 insertions, 28 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java index 0c5eeb40..b0a91e74 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java @@ -28,13 +28,12 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Utils to operate on Key/Value based configurations. @@ -43,8 +42,7 @@ import org.slf4j.LoggerFactory; * */ public class KeyValueUtils { - private static final Logger log = LoggerFactory.getLogger(KeyValueUtils.class); - + public static final String KEY_DELIMITER = "."; public static final String CSV_DELIMITER = ","; public static final String KEYVVALUEDELIMITER = "="; @@ -154,18 +152,14 @@ public class KeyValueUtils { * null */ public static Map<String, String> removePrefixFromKeys(final Map<String, String> keys, - final String prefix) { - final Map<String, String> result = new HashMap<>(); - final Iterator<Entry<String, String>> interator = keys.entrySet().iterator(); - while (interator.hasNext()) { - final Entry<String, String> el = interator.next(); - final String newKey = removePrefixFromKey(el.getKey(), prefix); - if (StringUtils.isNotEmpty(newKey)) { - result.put(newKey, el.getValue()); - } - } - - return result; + final String prefix) { + return keys.entrySet().stream() + .filter(el -> StringUtils.isNotEmpty(removePrefixFromKey(el.getKey(), prefix))) + .collect(Collectors.toMap( + el -> removePrefixFromKey(el.getKey(), prefix), + el -> el.getValue())); + + } /** @@ -351,19 +345,13 @@ public class KeyValueUtils { * @return Map of Key / Value pairs, but never null */ public static Map<String, String> convertListToMap(final List<String> elements) { - final Map<String, String> map = new HashMap<>(); - for (final String el : elements) { - if (el.contains(KEYVVALUEDELIMITER)) { - final String[] split = el.split(KEYVVALUEDELIMITER); - map.put(split[0], split[1]); - - } else { - log.debug("Key/Value Mapper: '" + el + "' contains NO '='. Ignore it."); - } - - } + return elements.stream() + .filter(el -> el.contains(KEYVVALUEDELIMITER)) + .map(el -> el.split(KEYVVALUEDELIMITER)) + .collect(Collectors.toMap( + el -> el[0], + el -> el[1])); - return map; } /** diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/X509Utils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/X509Utils.java index 72c183bf..e2fc4d1b 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/X509Utils.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/X509Utils.java @@ -5,12 +5,26 @@ import java.util.List; import javax.security.auth.x500.X500Principal; +import org.springframework.util.CollectionUtils; + public class X509Utils { /** * Sorts the Certificate Chain by IssuerDN and SubjectDN. The [0]-Element should * be the Hostname, the last Element should be the Root Certificate. * + * @param certChain The first element must be the correct one. + * @return sorted Certificate Chain + */ + public static List<X509Certificate> sortCertificates(X509Certificate[] certChain) { + return sortCertificates(CollectionUtils.arrayToList(certChain)); + + } + + /** + * Sorts the Certificate Chain by IssuerDN and SubjectDN. The [0]-Element should + * be the Hostname, the last Element should be the Root Certificate. + * * @param certs The first element must be the correct one. * @return sorted Certificate Chain */ @@ -48,4 +62,5 @@ public class X509Utils { return certs; } + } |