Skip to content

Commit

Permalink
GUACAMOLE-524: Merge use decoration API to inject tokens from LDAP at…
Browse files Browse the repository at this point in the history
…tributes.
  • Loading branch information
necouchman committed Oct 6, 2018
2 parents 3089e71 + 13e2b06 commit dfd4332
Show file tree
Hide file tree
Showing 37 changed files with 788 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ public List<ConnectionRecord> retrieveHistory(ModeledAuthenticatedUser user,
* @param info
* Information associated with the connecting client.
*
* @param tokens
* A Map containing the token names and corresponding values to be
* applied as parameter tokens when establishing the connection.
*
* @return
* A connected GuacamoleTunnel associated with a newly-established
* connection.
Expand All @@ -507,12 +511,12 @@ public List<ConnectionRecord> retrieveHistory(ModeledAuthenticatedUser user,
* If permission to connect to this connection is denied.
*/
public GuacamoleTunnel connect(ModeledAuthenticatedUser user,
ModeledConnection connection, GuacamoleClientInformation info)
throws GuacamoleException {
ModeledConnection connection, GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {

// Connect only if READ permission is granted
if (hasObjectPermission(user, connection.getIdentifier(), ObjectPermission.Type.READ))
return tunnelService.getGuacamoleTunnel(user, connection, info);
return tunnelService.getGuacamoleTunnel(user, connection, info, tokens);

// The user does not have permission to connect
throw new GuacamoleSecurityException("Permission denied.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info) throws GuacamoleException {
return connectionService.connect(getCurrentUser(), this, info);
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
return connectionService.connect(getCurrentUser(), this, info, tokens);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Map;
import java.util.Set;
import org.apache.guacamole.auth.jdbc.user.ModeledAuthenticatedUser;
import org.apache.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
Expand Down Expand Up @@ -243,6 +244,10 @@ public Set<String> getIdentifiersWithin(ModeledAuthenticatedUser user,
* @param info
* Information associated with the connecting client.
*
* @param tokens
* A Map containing the token names and corresponding values to be
* applied as parameter tokens when establishing the connection.
*
* @return
* A connected GuacamoleTunnel associated with a newly-established
* connection.
Expand All @@ -251,12 +256,12 @@ public Set<String> getIdentifiersWithin(ModeledAuthenticatedUser user,
* If permission to connect to this connection is denied.
*/
public GuacamoleTunnel connect(ModeledAuthenticatedUser user,
ModeledConnectionGroup connectionGroup, GuacamoleClientInformation info)
throws GuacamoleException {
ModeledConnectionGroup connectionGroup, GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {

// Connect only if READ permission is granted
if (hasObjectPermission(user, connectionGroup.getIdentifier(), ObjectPermission.Type.READ))
return tunnelService.getGuacamoleTunnel(user, connectionGroup, info);
return tunnelService.getGuacamoleTunnel(user, connectionGroup, info, tokens);

// The user does not have permission to connect
throw new GuacamoleSecurityException("Permission denied.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public void setName(String name) {
}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
return connectionGroupService.connect(getCurrentUser(), this, info);
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
return connectionGroupService.connect(getCurrentUser(), this, info, tokens);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void setIdentifier(String identifier) {
}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public void setConfiguration(GuacamoleConfiguration config) {
}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
return tunnelService.getGuacamoleTunnel(user, definition, info);
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
return tunnelService.getGuacamoleTunnel(user, definition, info, tokens);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void setParentIdentifier(String parentIdentifier) {
}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.apache.guacamole.protocol.GuacamoleClientInformation;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.token.StandardTokens;
import org.apache.guacamole.token.TokenFilter;
import org.mybatis.guice.transactional.Transactional;
import org.apache.guacamole.auth.jdbc.connection.ConnectionParameterMapper;
Expand Down Expand Up @@ -233,13 +232,6 @@ private GuacamoleConfiguration getGuacamoleConfiguration(RemoteAuthenticatedUser
for (ConnectionParameterModel parameter : parameters)
config.setParameter(parameter.getName(), parameter.getValue());

// Build token filter containing credential tokens
TokenFilter tokenFilter = new TokenFilter();
StandardTokens.addStandardTokens(tokenFilter, user);

// Filter the configuration
tokenFilter.filterValues(config.getParameters());

return config;

}
Expand Down Expand Up @@ -279,13 +271,6 @@ private GuacamoleConfiguration getGuacamoleConfiguration(RemoteAuthenticatedUser
for (SharingProfileParameterModel parameter : parameters)
config.setParameter(parameter.getName(), parameter.getValue());

// Build token filter containing credential tokens
TokenFilter tokenFilter = new TokenFilter();
StandardTokens.addStandardTokens(tokenFilter, user);

// Filter the configuration
tokenFilter.filterValues(config.getParameters());

return config;

}
Expand Down Expand Up @@ -454,6 +439,10 @@ public void run() {
* Information describing the Guacamole client connecting to the given
* connection.
*
* @param tokens
* A Map containing the token names and corresponding values to be
* applied as parameter tokens when establishing the connection.
*
* @param interceptErrors
* Whether errors from the upstream remote desktop should be
* intercepted and rethrown as GuacamoleUpstreamExceptions.
Expand All @@ -467,7 +456,8 @@ public void run() {
* while connection configuration information is being retrieved.
*/
private GuacamoleTunnel assignGuacamoleTunnel(ActiveConnectionRecord activeConnection,
GuacamoleClientInformation info, boolean interceptErrors) throws GuacamoleException {
GuacamoleClientInformation info, Map<String, String> tokens,
boolean interceptErrors) throws GuacamoleException {

// Record new active connection
Runnable cleanupTask = new ConnectionCleanupTask(activeConnection);
Expand Down Expand Up @@ -504,6 +494,13 @@ private GuacamoleTunnel assignGuacamoleTunnel(ActiveConnectionRecord activeConne

}

// Build token filter containing credential tokens
TokenFilter tokenFilter = new TokenFilter();
tokenFilter.setTokens(tokens);

// Filter the configuration
tokenFilter.filterValues(config.getParameters());

// Obtain socket which will automatically run the cleanup task
ConfiguredGuacamoleSocket socket = new ConfiguredGuacamoleSocket(
getUnconfiguredGuacamoleSocket(connection.getGuacamoleProxyConfiguration(),
Expand Down Expand Up @@ -651,16 +648,16 @@ public Collection<ActiveConnectionRecord> getActiveConnections(ModeledAuthentica
@Override
@Transactional
public GuacamoleTunnel getGuacamoleTunnel(final ModeledAuthenticatedUser user,
final ModeledConnection connection, GuacamoleClientInformation info)
throws GuacamoleException {
final ModeledConnection connection, GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {

// Acquire access to single connection, ignoring the failover-only flag
acquire(user, Collections.singletonList(connection), true);

// Connect only if the connection was successfully acquired
ActiveConnectionRecord connectionRecord = activeConnectionRecordProvider.get();
connectionRecord.init(user, connection);
return assignGuacamoleTunnel(connectionRecord, info, false);
return assignGuacamoleTunnel(connectionRecord, info, tokens, false);

}

Expand All @@ -673,7 +670,8 @@ public Collection<ActiveConnectionRecord> getActiveConnections(Connection connec
@Transactional
public GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
ModeledConnectionGroup connectionGroup,
GuacamoleClientInformation info) throws GuacamoleException {
GuacamoleClientInformation info, Map<String, String> tokens)
throws GuacamoleException {

// Track failures in upstream (remote desktop) connections
boolean upstreamHasFailed = false;
Expand Down Expand Up @@ -706,7 +704,8 @@ public GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
// Connect to acquired child
ActiveConnectionRecord connectionRecord = activeConnectionRecordProvider.get();
connectionRecord.init(user, connectionGroup, connection);
GuacamoleTunnel tunnel = assignGuacamoleTunnel(connectionRecord, info, connections.size() > 1);
GuacamoleTunnel tunnel = assignGuacamoleTunnel(connectionRecord,
info, tokens, connections.size() > 1);

// If session affinity is enabled, prefer this connection going forward
if (connectionGroup.isSessionAffinityEnabled())
Expand Down Expand Up @@ -755,7 +754,7 @@ public Collection<ActiveConnectionRecord> getActiveConnections(ConnectionGroup c
@Transactional
public GuacamoleTunnel getGuacamoleTunnel(RemoteAuthenticatedUser user,
SharedConnectionDefinition definition,
GuacamoleClientInformation info)
GuacamoleClientInformation info, Map<String, String> tokens)
throws GuacamoleException {

// Create a connection record which describes the shared connection
Expand All @@ -764,7 +763,7 @@ public GuacamoleTunnel getGuacamoleTunnel(RemoteAuthenticatedUser user,
definition.getSharingProfile());

// Connect to shared connection described by the created record
GuacamoleTunnel tunnel = assignGuacamoleTunnel(connectionRecord, info, false);
GuacamoleTunnel tunnel = assignGuacamoleTunnel(connectionRecord, info, tokens, false);

// Register tunnel, such that it is closed when the
// SharedConnectionDefinition is invalidated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.guacamole.auth.jdbc.tunnel;

import java.util.Collection;
import java.util.Map;
import org.apache.guacamole.auth.jdbc.user.ModeledAuthenticatedUser;
import org.apache.guacamole.auth.jdbc.connection.ModeledConnection;
import org.apache.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
Expand Down Expand Up @@ -73,6 +74,10 @@ public Collection<ActiveConnectionRecord> getActiveConnections(ModeledAuthentica
* Information describing the Guacamole client connecting to the given
* connection.
*
* @param tokens
* A Map containing the token names and corresponding values to be
* applied as parameter tokens when establishing the connection.
*
* @return
* A new GuacamoleTunnel which is configured and connected to the given
* connection.
Expand All @@ -82,8 +87,8 @@ public Collection<ActiveConnectionRecord> getActiveConnections(ModeledAuthentica
* rules.
*/
GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
ModeledConnection connection, GuacamoleClientInformation info)
throws GuacamoleException;
ModeledConnection connection, GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException;

/**
* Returns a collection containing connection records representing all
Expand Down Expand Up @@ -117,6 +122,10 @@ GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
* Information describing the Guacamole client connecting to the given
* connection group.
*
* @param tokens
* A Map containing the token names and corresponding values to be
* applied as parameter tokens when establishing the connection.
*
* @return
* A new GuacamoleTunnel which is configured and connected to the given
* connection group.
Expand All @@ -127,7 +136,7 @@ GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
*/
GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
ModeledConnectionGroup connectionGroup,
GuacamoleClientInformation info)
GuacamoleClientInformation info, Map<String, String> tokens)
throws GuacamoleException;

/**
Expand Down Expand Up @@ -163,6 +172,10 @@ GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
* Information describing the Guacamole client connecting to the given
* connection.
*
* @param tokens
* A Map containing the token names and corresponding values to be
* applied as parameter tokens when establishing the connection.
*
* @return
* A new GuacamoleTunnel which is configured and connected to the given
* active connection.
Expand All @@ -173,7 +186,7 @@ GuacamoleTunnel getGuacamoleTunnel(ModeledAuthenticatedUser user,
*/
GuacamoleTunnel getGuacamoleTunnel(RemoteAuthenticatedUser user,
SharedConnectionDefinition definition,
GuacamoleClientInformation info)
GuacamoleClientInformation info, Map<String, String> tokens)
throws GuacamoleException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public ModeledAuthenticatedUser(AuthenticatedUser authenticatedUser,
super(authenticatedUser.getAuthenticationProvider(), authenticatedUser.getCredentials(), authenticatedUser.getEffectiveUserGroups());
this.modelAuthenticationProvider = modelAuthenticationProvider;
this.user = user;
super.setAttributes(authenticatedUser.getAttributes());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.guacamole.auth.jdbc.user;

import java.util.Map;
import java.util.Collections;
import java.util.Set;
import org.apache.guacamole.net.auth.AuthenticatedUser;
Expand Down Expand Up @@ -52,16 +51,6 @@ public abstract class RemoteAuthenticatedUser implements AuthenticatedUser {
*/
private final Set<String> effectiveGroups;

@Override
public Map<String, String> getAttributes() {
return Collections.<String, String>emptyMap();
}

@Override
public void setAttributes(Map<String, String> attributes) {
// No attributes supported
}

/**
* Creates a new RemoteAuthenticatedUser, deriving the associated remote
* host from the given credentials.
Expand Down
8 changes: 8 additions & 0 deletions extensions/guacamole-auth-ldap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@
<version>3.0</version>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>

0 comments on commit dfd4332

Please sign in to comment.