mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUAC-1101: Load connection parameters upon request.
This commit is contained in:
@@ -45,7 +45,6 @@ import net.sourceforge.guacamole.net.auth.mysql.service.SaltService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.SecureRandomSaltService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.SystemPermissionService;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.UserService;
|
||||
import org.glyptodon.guacamole.properties.GuacamoleProperties;
|
||||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
||||
import org.glyptodon.guacamole.environment.Environment;
|
||||
import org.glyptodon.guacamole.environment.LocalEnvironment;
|
||||
@@ -151,6 +150,7 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
|
||||
bind(Environment.class).toInstance(environment);
|
||||
bind(ConnectionDirectory.class);
|
||||
bind(MySQLConnection.class);
|
||||
bind(MySQLGuacamoleConfiguration.class);
|
||||
bind(MySQLUser.class);
|
||||
bind(MySQLUserContext.class);
|
||||
bind(MySQLRootConnectionGroup.class);
|
||||
|
@@ -23,6 +23,7 @@
|
||||
package net.sourceforge.guacamole.net.auth.mysql;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel;
|
||||
@@ -57,6 +58,17 @@ public class MySQLConnection implements Connection, DirectoryObject<ConnectionMo
|
||||
*/
|
||||
@Inject
|
||||
private ConnectionService connectionService;
|
||||
|
||||
/**
|
||||
* Provider for lazy-loaded, permission-controlled configurations.
|
||||
*/
|
||||
@Inject
|
||||
private Provider<MySQLGuacamoleConfiguration> configProvider;
|
||||
|
||||
/**
|
||||
* The manually-set GuacamoleConfiguration, if any.
|
||||
*/
|
||||
private GuacamoleConfiguration config = null;
|
||||
|
||||
/**
|
||||
* Creates a new, empty MySQLConnection.
|
||||
@@ -86,8 +98,9 @@ public class MySQLConnection implements Connection, DirectoryObject<ConnectionMo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(ConnectionModel userModel) {
|
||||
this.connectionModel = userModel;
|
||||
public void setModel(ConnectionModel connectionModel) {
|
||||
this.connectionModel = connectionModel;
|
||||
this.config = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,20 +150,24 @@ public class MySQLConnection implements Connection, DirectoryObject<ConnectionMo
|
||||
@Override
|
||||
public GuacamoleConfiguration getConfiguration() {
|
||||
|
||||
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
||||
config.setProtocol(connectionModel.getProtocol());
|
||||
// If configuration has been manually set, return that
|
||||
if (config != null)
|
||||
return config;
|
||||
|
||||
/* FIXME: Set parameters, if available */
|
||||
// Otherwise, return permission-controlled configuration
|
||||
MySQLGuacamoleConfiguration restrictedConfig = configProvider.get();
|
||||
restrictedConfig.init(currentUser, connectionModel);
|
||||
return restrictedConfig;
|
||||
|
||||
return config;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfiguration(GuacamoleConfiguration config) {
|
||||
|
||||
/* FIXME: Set parameters, if available */
|
||||
// Store manually-set configuration internally
|
||||
this.config = config;
|
||||
|
||||
// Update model
|
||||
connectionModel.setProtocol(config.getProtocol());
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.sourceforge.guacamole.net.auth.mysql;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Map;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionService;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
|
||||
|
||||
/**
|
||||
* Implementation of GuacamoleConfiguration which loads parameter values only
|
||||
* if necessary, and only if allowed.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class MySQLGuacamoleConfiguration extends GuacamoleConfiguration {
|
||||
|
||||
/**
|
||||
* The user this configuration belongs to. Access is based on his/her
|
||||
* permission settings.
|
||||
*/
|
||||
private AuthenticatedUser currentUser;
|
||||
|
||||
/**
|
||||
* The internal model object containing the values which represent the
|
||||
* connection associated with this configuration.
|
||||
*/
|
||||
private ConnectionModel connectionModel;
|
||||
|
||||
/**
|
||||
* Service for managing connection parameters.
|
||||
*/
|
||||
@Inject
|
||||
private ConnectionService connectionService;
|
||||
|
||||
/**
|
||||
* The manually-set parameter map, if any.
|
||||
*/
|
||||
private Map<String, String> parameters = null;
|
||||
|
||||
/**
|
||||
* Creates a new, empty MySQLGuacamoleConfiguration.
|
||||
*/
|
||||
public MySQLGuacamoleConfiguration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this configuration, associating it with the current
|
||||
* authenticated user and populating it with data from the given model
|
||||
* object.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user that created or retrieved this configuration.
|
||||
*
|
||||
* @param connectionModel
|
||||
* The model object backing this configuration.
|
||||
*/
|
||||
public void init(AuthenticatedUser currentUser, ConnectionModel connectionModel) {
|
||||
this.currentUser = currentUser;
|
||||
this.connectionModel = connectionModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionID() {
|
||||
return connectionModel.getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionID(String connectionID) {
|
||||
throw new UnsupportedOperationException("The ID of this GuacamoleConfiguration is immutable.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocol() {
|
||||
return connectionModel.getProtocol();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProtocol(String protocol) {
|
||||
super.setProtocol(protocol);
|
||||
connectionModel.setProtocol(protocol);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setParameters(Map<String, String> parameters) {
|
||||
this.parameters = parameters;
|
||||
super.setParameters(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParameters() {
|
||||
|
||||
// Retrieve visible parameters, if not overridden by setParameters()
|
||||
if (parameters == null) {
|
||||
|
||||
// Retrieve all visible parameters
|
||||
Map<String, String> visibleParameters =
|
||||
connectionService.retrieveParameters(currentUser, connectionModel.getIdentifier());
|
||||
|
||||
// Use retrieved parameters to back future operations
|
||||
super.setParameters(visibleParameters);
|
||||
|
||||
}
|
||||
|
||||
return super.getParameters();
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -25,6 +25,8 @@ package net.sourceforge.guacamole.net.auth.mysql.service;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.AuthenticatedUser;
|
||||
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnection;
|
||||
@@ -180,6 +182,39 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all parameters visible to the given user and associated with
|
||||
* the connection having the given identifier. If the given user has no
|
||||
* access to such parameters, or no such connection exists, the returned
|
||||
* map will be empty.
|
||||
*
|
||||
* @param user
|
||||
* The user retrieving connection parameters.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the connection whose parameters are being
|
||||
* retrieved.
|
||||
*
|
||||
* @return
|
||||
* A new map of all parameter name/value pairs that the given user has
|
||||
* access to.
|
||||
*/
|
||||
public Map<String, String> retrieveParameters(AuthenticatedUser user,
|
||||
String identifier) {
|
||||
|
||||
// FIXME: Check permissions
|
||||
|
||||
Map<String, String> parameterMap = new HashMap<String, String>();
|
||||
|
||||
// Convert associated parameters to map
|
||||
Collection<ParameterModel> parameters = parameterMapper.select(identifier);
|
||||
for (ParameterModel parameter : parameters)
|
||||
parameterMap.put(parameter.getName(), parameter.getValue());
|
||||
|
||||
return parameterMap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the given connection as the given user, using the given
|
||||
* client information. If the user does not have permission to read the
|
||||
|
Reference in New Issue
Block a user