diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/base/ArbitraryAttributeMap.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/base/ArbitraryAttributeMap.java index e2cb43805..219abe85b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/base/ArbitraryAttributeMap.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/base/ArbitraryAttributeMap.java @@ -23,6 +23,7 @@ import java.util.AbstractCollection; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; /** * Map of arbitrary attribute name/value pairs which can alternatively be @@ -82,10 +83,22 @@ public class ArbitraryAttributeMap extends HashMap { if (!(o instanceof ArbitraryAttributeModel)) return false; - // The attribute should be removed only if the value matches + // Remove only if key is actually present ArbitraryAttributeModel model = (ArbitraryAttributeModel) o; - return ArbitraryAttributeMap.this.remove(model.getName(), - model.getValue()); + if (!ArbitraryAttributeMap.this.containsKey(model.getName())) + return false; + + // The attribute should be removed only if the value matches + String currentValue = ArbitraryAttributeMap.this.get(model.getName()); + if (currentValue == null) { + if (model.getValue() != null) + return false; + } + else if (!currentValue.equals(model.getValue())) + return false; + + ArbitraryAttributeMap.this.remove(model.getName()); + return true; } @@ -129,7 +142,7 @@ public class ArbitraryAttributeMap extends HashMap { public Iterator iterator() { // Get iterator over all string name/value entries - final Iterator> iterator = entrySet().iterator(); + final Iterator> iterator = entrySet().iterator(); // Dynamically translate each string name/value entry into a // corresponding attribute model object as iteration continues @@ -142,11 +155,16 @@ public class ArbitraryAttributeMap extends HashMap { @Override public ArbitraryAttributeModel next() { - Entry entry = iterator.next(); + Map.Entry entry = iterator.next(); return new ArbitraryAttributeModel(entry.getKey(), entry.getValue()); } + @Override + public void remove() { + iterator.remove(); + } + }; }