aboutsummaryrefslogtreecommitdiff
path: root/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/auth/modules/eidas/utils/MOAWhiteListConfigurator.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/auth/modules/eidas/utils/MOAWhiteListConfigurator.java')
-rw-r--r--id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/auth/modules/eidas/utils/MOAWhiteListConfigurator.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/auth/modules/eidas/utils/MOAWhiteListConfigurator.java b/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/auth/modules/eidas/utils/MOAWhiteListConfigurator.java
new file mode 100644
index 000000000..7d647ff15
--- /dev/null
+++ b/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/auth/modules/eidas/utils/MOAWhiteListConfigurator.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2014 Federal Chancellery Austria
+ * MOA-ID has been developed in a cooperation between BRZ, the Federal
+ * Chancellery Austria - ICT staff unit, and Graz University of Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * 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.gv.egovernment.moa.id.auth.modules.eidas.utils;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+
+import com.google.common.collect.ImmutableSet;
+
+import at.gv.egovernment.moa.id.commons.utils.KeyValueUtils;
+
+/**
+ * @author tlenz
+ *
+ */
+public class MOAWhiteListConfigurator {
+ private static final Pattern WHITE_LIST_SPLITTER = Pattern.compile("[;,]");
+
+
+ public static ImmutableSet<String> getAllowedAlgorithms( ImmutableSet<String> defaultWhiteList,
+ ImmutableSet<String> allowedValues,
+ String algorithmWhiteListValue) {
+ if (StringUtils.isBlank(algorithmWhiteListValue)) {
+ return defaultWhiteList;
+ }
+ ImmutableSet.Builder<String> allowed = ImmutableSet.builder();
+ String[] wlAlgorithms = WHITE_LIST_SPLITTER.split(algorithmWhiteListValue);
+ if (null != wlAlgorithms && wlAlgorithms.length > 0) {
+ return getAllowedAlgorithms(defaultWhiteList, allowedValues, ImmutableSet.<String>copyOf(wlAlgorithms));
+ }
+ return defaultWhiteList;
+ }
+
+
+ public static ImmutableSet<String> getAllowedAlgorithms( ImmutableSet<String> defaultWhiteList,
+ ImmutableSet<String> allowedValues,
+ ImmutableSet<String> candidateValues) {
+ if (CollectionUtils.isEmpty(candidateValues)) {
+ return defaultWhiteList;
+ }
+ ImmutableSet.Builder<String> allowed = ImmutableSet.builder();
+ boolean modified = false;
+ for (String candidateValue : candidateValues) {
+
+ /**FIX:
+ * fix problem with lowerCase and MGF1 signature algorithms
+ *
+ */
+ candidateValue = StringUtils.trimToNull(
+ KeyValueUtils.removeAllNewlineFromString(candidateValue));
+ if (StringUtils.isNotBlank(candidateValue)) {
+ String candidateAlgorithm = StringUtils.lowerCase(candidateValue, Locale.ENGLISH);
+ if (allowedValues.contains(candidateAlgorithm)) {
+ allowed.add(candidateValue);
+ if (!modified && !candidateAlgorithm.equals(candidateValue)) {
+ modified = true;
+ }
+ } else {
+ modified = true;
+ }
+ }
+ }
+ if (!modified) {
+ return candidateValues;
+ }
+ ImmutableSet<String> set = allowed.build();
+ if (set.isEmpty()) {
+ return defaultWhiteList;
+ }
+ return set;
+ }
+
+}