Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
GUAC-1101: Load connection parameters upon request.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-jumper committed Mar 1, 2015
1 parent 14ebda6 commit e584447
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 9 deletions.
Expand Up @@ -45,7 +45,6 @@
import net.sourceforge.guacamole.net.auth.mysql.service.SecureRandomSaltService; 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.SystemPermissionService;
import net.sourceforge.guacamole.net.auth.mysql.service.UserService; import net.sourceforge.guacamole.net.auth.mysql.service.UserService;
import org.glyptodon.guacamole.properties.GuacamoleProperties;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.environment.LocalEnvironment; import org.glyptodon.guacamole.environment.LocalEnvironment;
Expand Down Expand Up @@ -151,6 +150,7 @@ protected void initialize() {
bind(Environment.class).toInstance(environment); bind(Environment.class).toInstance(environment);
bind(ConnectionDirectory.class); bind(ConnectionDirectory.class);
bind(MySQLConnection.class); bind(MySQLConnection.class);
bind(MySQLGuacamoleConfiguration.class);
bind(MySQLUser.class); bind(MySQLUser.class);
bind(MySQLUserContext.class); bind(MySQLUserContext.class);
bind(MySQLRootConnectionGroup.class); bind(MySQLRootConnectionGroup.class);
Expand Down
Expand Up @@ -23,6 +23,7 @@
package net.sourceforge.guacamole.net.auth.mysql; package net.sourceforge.guacamole.net.auth.mysql;


import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel; import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel;
Expand Down Expand Up @@ -57,6 +58,17 @@ public class MySQLConnection implements Connection, DirectoryObject<ConnectionMo
*/ */
@Inject @Inject
private ConnectionService connectionService; 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. * Creates a new, empty MySQLConnection.
Expand Down Expand Up @@ -86,8 +98,9 @@ public ConnectionModel getModel() {
} }


@Override @Override
public void setModel(ConnectionModel userModel) { public void setModel(ConnectionModel connectionModel) {
this.connectionModel = userModel; this.connectionModel = connectionModel;
this.config = null;
} }


@Override @Override
Expand Down Expand Up @@ -137,20 +150,24 @@ public void setParentIdentifier(String parentIdentifier) {
@Override @Override
public GuacamoleConfiguration getConfiguration() { public GuacamoleConfiguration getConfiguration() {


GuacamoleConfiguration config = new GuacamoleConfiguration(); // If configuration has been manually set, return that
config.setProtocol(connectionModel.getProtocol()); 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 @Override
public void setConfiguration(GuacamoleConfiguration config) { public void setConfiguration(GuacamoleConfiguration config) {


/* FIXME: Set parameters, if available */ // Store manually-set configuration internally
this.config = config;


// Update model
connectionModel.setProtocol(config.getProtocol()); connectionModel.setProtocol(config.getProtocol());


} }
Expand Down
@@ -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();

}

}
Expand Up @@ -25,6 +25,8 @@
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import net.sourceforge.guacamole.net.auth.mysql.AuthenticatedUser; import net.sourceforge.guacamole.net.auth.mysql.AuthenticatedUser;
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnection; import net.sourceforge.guacamole.net.auth.mysql.MySQLConnection;
Expand Down Expand Up @@ -180,6 +182,39 @@ public Set<String> getRootIdentifiers(AuthenticatedUser user) throws GuacamoleEx


} }


/**
* 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 * Connects to the given connection as the given user, using the given
* client information. If the user does not have permission to read the * client information. If the user does not have permission to read the
Expand Down

0 comments on commit e584447

Please sign in to comment.