GUACAMOLE-524: Accept only supported attributes via setAttributes(). Do not replace existing attributes.

This commit is contained in:
Michael Jumper
2018-10-01 12:10:37 -07:00
parent 220d9b2994
commit aae17f3a9f
3 changed files with 13 additions and 17 deletions

View File

@@ -19,7 +19,6 @@
package org.apache.guacamole.auth.jdbc.user; package org.apache.guacamole.auth.jdbc.user;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@@ -47,11 +46,6 @@ public abstract class RemoteAuthenticatedUser implements AuthenticatedUser {
*/ */
private final String remoteHost; private final String remoteHost;
/**
* Arbitrary attributes associated with this RemoteAuthenticatedUser object.
*/
private Map<String, String> attributes = new HashMap<String, String>();
/** /**
* The identifiers of any groups of which this user is a member, including * The identifiers of any groups of which this user is a member, including
* groups inherited through membership in other groups. * groups inherited through membership in other groups.
@@ -60,12 +54,12 @@ public abstract class RemoteAuthenticatedUser implements AuthenticatedUser {
@Override @Override
public Map<String, String> getAttributes() { public Map<String, String> getAttributes() {
return attributes; return Collections.<String, String>emptyMap();
} }
@Override @Override
public void setAttributes(Map<String, String> attributes) { public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes; // No attributes supported
} }
/** /**

View File

@@ -232,10 +232,7 @@ public class AuthenticationProviderService {
try { try {
// Return AuthenticatedUser if bind succeeds // Return AuthenticatedUser if bind succeeds
AuthenticatedUser authenticatedUser = authenticatedUserProvider.get(); AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
authenticatedUser.init(credentials); authenticatedUser.init(credentials, getLDAPAttributes(ldapConnection, credentials.getUsername()));
// Set attributes
authenticatedUser.setAttributes(getLDAPAttributes(ldapConnection, credentials.getUsername()));
return authenticatedUser; return authenticatedUser;

View File

@@ -20,7 +20,6 @@
package org.apache.guacamole.auth.ldap.user; package org.apache.guacamole.auth.ldap.user;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.guacamole.net.auth.AbstractAuthenticatedUser; import org.apache.guacamole.net.auth.AbstractAuthenticatedUser;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AuthenticationProvider;
@@ -47,16 +46,22 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser {
/** /**
* Arbitrary attributes associated with this AuthenticatedUser object. * Arbitrary attributes associated with this AuthenticatedUser object.
*/ */
private Map<String, String> attributes = new HashMap<String, String>(); private Map<String, String> attributes;
/** /**
* Initializes this AuthenticatedUser using the given credentials. * Initializes this AuthenticatedUser using the given credentials and
* arbitrary attributes.
* *
* @param credentials * @param credentials
* The credentials provided when this user was authenticated. * The credentials provided when this user was authenticated.
*
* @param attributes
* The map of arbitrary attribute name/value pairs to associate with
* this AuthenticatedUser.
*/ */
public void init(Credentials credentials) { public void init(Credentials credentials, Map<String, String> attributes) {
this.credentials = credentials; this.credentials = credentials;
this.attributes = attributes;
setIdentifier(credentials.getUsername()); setIdentifier(credentials.getUsername());
} }
@@ -67,7 +72,7 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser {
@Override @Override
public void setAttributes(Map<String, String> attributes) { public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes; // All attributes are read-only
} }
@Override @Override