From 612a8b4b97c0cbeed19f84d0b398dc99949e8142 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Oct 2014 15:39:41 -0700 Subject: [PATCH] GUAC-434: Allow SimpleUserContext/SimpleAuthenticationProvider to provide actual usernames. --- .../simple/SimpleAuthenticationProvider.java | 2 +- .../net/auth/simple/SimpleUserContext.java | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleAuthenticationProvider.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleAuthenticationProvider.java index 32037604f..ab9d98556 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleAuthenticationProvider.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleAuthenticationProvider.java @@ -73,7 +73,7 @@ public abstract class SimpleAuthenticationProvider return null; // Return user context restricted to authorized configs - return new SimpleUserContext(configs); + return new SimpleUserContext(credentials.getUsername(), configs); } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index 92663e7a9..2bb376747 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.auth.simple; import java.util.Collections; import java.util.Map; +import java.util.UUID; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; @@ -60,12 +61,26 @@ public class SimpleUserContext implements UserContext { /** * Creates a new SimpleUserContext which provides access to only those - * configurations within the given Map. + * configurations within the given Map. The username is assigned + * arbitrarily. * * @param configs A Map of all configurations for which the user associated * with this UserContext has read access. */ public SimpleUserContext(Map configs) { + this(UUID.randomUUID().toString(), configs); + } + + /** + * Creates a new SimpleUserContext for the user with the given username + * which provides access to only those configurations within the given Map. + * + * @param username The username of the user associated with this + * UserContext. + * @param configs A Map of all configurations for which the user associated + * with this UserContext has read access. + */ + public SimpleUserContext(String username, Map configs) { // Add root group that contains only configurations this.connectionGroup = new SimpleConnectionGroup("ROOT", "ROOT", @@ -73,7 +88,7 @@ public class SimpleUserContext implements UserContext { new SimpleConnectionGroupDirectory(Collections.EMPTY_LIST)); // Build new user from credentials, giving the user an arbitrary name - this.self = new SimpleUser("user", + this.self = new SimpleUser(username, configs, Collections.singleton(connectionGroup)); // Create user directory for new user