diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java index 654b403c3..f84712c7f 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java @@ -330,7 +330,7 @@ public class AuthenticationProviderService { throws GuacamoleException { // Get attributes from configuration information - List attrList = config.getAttributes(); + Collection attrList = config.getAttributes(); // If there are no attributes there is no reason to search LDAP if (attrList.isEmpty()) diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/ConnectedLDAPConfiguration.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/ConnectedLDAPConfiguration.java index 493cafcb7..c41114c02 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/ConnectedLDAPConfiguration.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/ConnectedLDAPConfiguration.java @@ -19,6 +19,7 @@ package org.apache.guacamole.auth.ldap; +import java.util.Collection; import java.util.List; import org.apache.directory.api.ldap.model.filter.ExprNode; import org.apache.directory.api.ldap.model.message.AliasDerefMode; @@ -124,7 +125,7 @@ public class ConnectedLDAPConfiguration implements LDAPConfiguration, AutoClosea } @Override - public List getUsernameAttributes() throws GuacamoleException { + public Collection getUsernameAttributes() throws GuacamoleException { return config.getUsernameAttributes(); } @@ -139,7 +140,7 @@ public class ConnectedLDAPConfiguration implements LDAPConfiguration, AutoClosea } @Override - public List getGroupNameAttributes() throws GuacamoleException { + public Collection getGroupNameAttributes() throws GuacamoleException { return config.getGroupNameAttributes(); } @@ -209,7 +210,7 @@ public class ConnectedLDAPConfiguration implements LDAPConfiguration, AutoClosea } @Override - public List getAttributes() throws GuacamoleException { + public Collection getAttributes() throws GuacamoleException { return config.getAttributes(); } diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/EnvironmentLDAPConfiguration.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/EnvironmentLDAPConfiguration.java index 9fb44a1fa..5ffeb203b 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/EnvironmentLDAPConfiguration.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/EnvironmentLDAPConfiguration.java @@ -19,7 +19,7 @@ package org.apache.guacamole.auth.ldap.conf; -import java.util.List; +import java.util.Collection; import org.apache.directory.api.ldap.model.filter.ExprNode; import org.apache.directory.api.ldap.model.message.AliasDerefMode; import org.apache.directory.api.ldap.model.name.Dn; @@ -75,8 +75,8 @@ public class EnvironmentLDAPConfiguration implements LDAPConfiguration { } @Override - public List getUsernameAttributes() throws GuacamoleException { - return environment.getProperty( + public Collection getUsernameAttributes() throws GuacamoleException { + return environment.getPropertyCollection( LDAPGuacamoleProperties.LDAP_USERNAME_ATTRIBUTE, DEFAULT.getUsernameAttributes() ); @@ -98,8 +98,8 @@ public class EnvironmentLDAPConfiguration implements LDAPConfiguration { } @Override - public List getGroupNameAttributes() throws GuacamoleException { - return environment.getProperty( + public Collection getGroupNameAttributes() throws GuacamoleException { + return environment.getPropertyCollection( LDAPGuacamoleProperties.LDAP_GROUP_NAME_ATTRIBUTE, DEFAULT.getGroupNameAttributes() ); @@ -210,8 +210,8 @@ public class EnvironmentLDAPConfiguration implements LDAPConfiguration { } @Override - public List getAttributes() throws GuacamoleException { - return environment.getProperty( + public Collection getAttributes() throws GuacamoleException { + return environment.getPropertyCollection( LDAPGuacamoleProperties.LDAP_USER_ATTRIBUTES, DEFAULT.getAttributes() ); diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/JacksonLDAPConfiguration.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/JacksonLDAPConfiguration.java index 01d58a3e4..bddccd871 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/JacksonLDAPConfiguration.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/JacksonLDAPConfiguration.java @@ -22,6 +22,7 @@ package org.apache.guacamole.auth.ldap.conf; import com.fasterxml.jackson.annotation.JsonFormat; import static com.fasterxml.jackson.annotation.JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collection; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -331,7 +332,7 @@ public class JacksonLDAPConfiguration implements LDAPConfiguration { } @Override - public List getUsernameAttributes() throws GuacamoleException { + public Collection getUsernameAttributes() throws GuacamoleException { return withDefault(usernameAttributes, defaultConfig::getUsernameAttributes); } @@ -348,7 +349,7 @@ public class JacksonLDAPConfiguration implements LDAPConfiguration { } @Override - public List getGroupNameAttributes() throws GuacamoleException { + public Collection getGroupNameAttributes() throws GuacamoleException { return withDefault(groupNameAttributes, defaultConfig::getGroupNameAttributes); } @@ -424,7 +425,7 @@ public class JacksonLDAPConfiguration implements LDAPConfiguration { } @Override - public List getAttributes() throws GuacamoleException { + public Collection getAttributes() throws GuacamoleException { return withDefault(userAttributes, defaultConfig::getAttributes); } diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPConfiguration.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPConfiguration.java index 975631d02..e57049b26 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPConfiguration.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPConfiguration.java @@ -19,6 +19,7 @@ package org.apache.guacamole.auth.ldap.conf; +import java.util.Collection; import java.util.List; import org.apache.directory.api.ldap.model.filter.ExprNode; import org.apache.directory.api.ldap.model.message.AliasDerefMode; @@ -84,7 +85,7 @@ public interface LDAPConfiguration { * @throws GuacamoleException * If the username attributes cannot be retrieved. */ - List getUsernameAttributes() throws GuacamoleException; + Collection getUsernameAttributes() throws GuacamoleException; /** * Returns the base DN under which all Guacamole users will be stored @@ -125,7 +126,7 @@ public interface LDAPConfiguration { * @throws GuacamoleException * If the group name attributes cannot be retrieved. */ - List getGroupNameAttributes() throws GuacamoleException; + Collection getGroupNameAttributes() throws GuacamoleException; /** * Returns the base DN under which all Guacamole role based access control @@ -305,7 +306,7 @@ public interface LDAPConfiguration { * If the names of the LDAP user attributes to be exposed as parameter * tokens cannot be retrieved. */ - List getAttributes() throws GuacamoleException; + Collection getAttributes() throws GuacamoleException; /** * Returns the name of the LDAP attribute used to enumerate members in a diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPGuacamoleProperties.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPGuacamoleProperties.java index cd0b724c0..7349356b9 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPGuacamoleProperties.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/LDAPGuacamoleProperties.java @@ -84,8 +84,8 @@ public class LDAPGuacamoleProperties { * one attribute, and the concatenation of that attribute and the value of * LDAP_USER_BASE_DN must equal the user's full DN. */ - public static final StringListProperty LDAP_USERNAME_ATTRIBUTE = - new StringListProperty() { + public static final StringGuacamoleProperty LDAP_USERNAME_ATTRIBUTE = + new StringGuacamoleProperty() { @Override public String getName() { return "ldap-username-attribute"; } @@ -97,8 +97,8 @@ public class LDAPGuacamoleProperties { * attributes must be present within each Guacamole user group's record in * the LDAP directory for that group to be visible. */ - public static final StringListProperty LDAP_GROUP_NAME_ATTRIBUTE = - new StringListProperty() { + public static final StringGuacamoleProperty LDAP_GROUP_NAME_ATTRIBUTE = + new StringGuacamoleProperty() { @Override public String getName() { return "ldap-group-name-attribute"; } @@ -277,8 +277,8 @@ public class LDAPGuacamoleProperties { * Custom attribute or attributes to query from Guacamole user's record in * the LDAP directory. */ - public static final StringListProperty LDAP_USER_ATTRIBUTES = - new StringListProperty() { + public static final StringGuacamoleProperty LDAP_USER_ATTRIBUTES = + new StringGuacamoleProperty() { @Override public String getName() { return "ldap-user-attributes"; } diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/StringListProperty.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/StringListProperty.java deleted file mode 100644 index f7057e9f6..000000000 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/StringListProperty.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.guacamole.auth.ldap.conf; - -import java.util.Arrays; -import java.util.List; -import java.util.regex.Pattern; -import org.apache.guacamole.GuacamoleException; -import org.apache.guacamole.properties.GuacamoleProperty; - -/** - * A GuacamoleProperty whose value is a List of Strings. The string value - * parsed to produce this list is a comma-delimited list. Duplicate values are - * ignored, as is any whitespace following delimiters. To maintain - * compatibility with the behavior of Java properties in general, only - * whitespace at the beginning of each value is ignored; trailing whitespace - * becomes part of the value. - */ -public abstract class StringListProperty implements GuacamoleProperty> { - - /** - * A pattern which matches against the delimiters between values. This is - * currently simply a comma and any following whitespace. Parts of the - * input string which match this pattern will not be included in the parsed - * result. - */ - private static final Pattern DELIMITER_PATTERN = Pattern.compile(",\\s*"); - - @Override - public List parseValue(String values) throws GuacamoleException { - - // If no property provided, return null. - if (values == null) - return null; - - // Split string into a list of individual values - List stringValues = Arrays.asList(DELIMITER_PATTERN.split(values)); - if (stringValues.isEmpty()) - return null; - - return stringValues; - - } - -} diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/UserService.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/UserService.java index fa9fe1522..38fa33e7e 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/UserService.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/UserService.java @@ -183,7 +183,7 @@ public class UserService { throws GuacamoleException { // Pull username attributes from properties - List usernameAttributes = config.getUsernameAttributes(); + List usernameAttributes = new ArrayList<>(config.getUsernameAttributes()); // We need exactly one base DN to derive the user DN if (usernameAttributes.size() != 1) {