Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.authentication.admin/src/org/eclipse/osee/authentication/admin/AuthenticationConfigurationBuilder.java')
-rw-r--r--plugins/org.eclipse.osee.authentication.admin/src/org/eclipse/osee/authentication/admin/AuthenticationConfigurationBuilder.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.authentication.admin/src/org/eclipse/osee/authentication/admin/AuthenticationConfigurationBuilder.java b/plugins/org.eclipse.osee.authentication.admin/src/org/eclipse/osee/authentication/admin/AuthenticationConfigurationBuilder.java
new file mode 100644
index 00000000000..424a2e1696f
--- /dev/null
+++ b/plugins/org.eclipse.osee.authentication.admin/src/org/eclipse/osee/authentication/admin/AuthenticationConfigurationBuilder.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.authentication.admin;
+
+import static org.eclipse.osee.authentication.admin.AuthenticationConstants.AUTHENTICATION_SCHEME_ALLOWED;
+import static org.eclipse.osee.authentication.admin.AuthenticationConstants.DEFAULT_AUTHENTICATION_SCHEME;
+import static org.eclipse.osee.authentication.admin.internal.AuthenticationUtil.normalize;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.authentication.admin.internal.AuthenticationUtil;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AuthenticationConfigurationBuilder {
+
+ private final AuthenticationConfigurationImpl config = new AuthenticationConfigurationImpl();
+
+ private AuthenticationConfigurationBuilder() {
+ //Builder class
+ }
+
+ public static AuthenticationConfigurationBuilder newBuilder() {
+ return new AuthenticationConfigurationBuilder();
+ }
+
+ public AuthenticationConfigurationBuilder scheme(String scheme) {
+ config.addScheme(scheme);
+ return this;
+ }
+
+ public AuthenticationConfigurationBuilder properties(Map<String, Object> props) {
+ config.loadProperties(props);
+ return this;
+ }
+
+ public AuthenticationConfiguration build() {
+ return config.clone();
+ }
+
+ private static final class AuthenticationConfigurationImpl implements AuthenticationConfiguration, Cloneable {
+
+ private final Set<String> schemes = new HashSet<String>();
+
+ @Override
+ public Iterable<String> getAllowedSchemes() {
+ return AuthenticationUtil.unmodifiableSortedIterable(schemes);
+ }
+
+ public void addSchemes(Collection<String> toAdd) {
+ if (toAdd != null && !toAdd.isEmpty()) {
+ schemes.addAll(toAdd);
+ }
+ }
+
+ public void addScheme(String scheme) {
+ if (Strings.isValid(scheme)) {
+ schemes.add(scheme);
+ }
+ }
+
+ @Override
+ public synchronized AuthenticationConfigurationImpl clone() {
+ AuthenticationConfigurationImpl cloned = new AuthenticationConfigurationImpl();
+ cloned.addSchemes(this.schemes);
+ return cloned;
+ }
+
+ public void loadProperties(Map<String, Object> props) {
+ if (props != null && !props.isEmpty()) {
+ addSchemes(getSet(props, AUTHENTICATION_SCHEME_ALLOWED, DEFAULT_AUTHENTICATION_SCHEME));
+ }
+ }
+
+ public Collection<String> getSet(Map<String, Object> props, String key, String defaultValue) {
+ Set<String> toReturn = new HashSet<String>();
+ String joinedArray = get(props, key, "");
+ if (Strings.isValid(joinedArray)) {
+ String[] split = joinedArray.split(",");
+ for (String value : split) {
+ String toAdd = normalize(value);
+ if (Strings.isValid(toAdd)) {
+ toReturn.add(toAdd);
+ }
+ }
+ } else {
+ toReturn.add(defaultValue);
+ }
+ return toReturn;
+ }
+
+ private String get(Map<String, Object> props, String key, String defaultValue) {
+ String toReturn = defaultValue;
+ Object object = props.get(key);
+ if (object != null) {
+ toReturn = String.valueOf(object);
+ }
+ return toReturn;
+ }
+ }
+} \ No newline at end of file

Back to the top