mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Merge pull request #121 from glyptodon/active-connection-directory
GUAC-1132: Implement active connection directory.
This commit is contained in:
@@ -57,6 +57,11 @@ import org.glyptodon.guacamole.auth.jdbc.permission.ConnectionPermissionSet;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.UserPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.UserPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.UserPermissionSet;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionDirectory;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermissionSet;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.TrackedActiveConnection;
|
||||
import org.glyptodon.guacamole.environment.Environment;
|
||||
import org.mybatis.guice.MyBatisModule;
|
||||
import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider;
|
||||
@@ -120,6 +125,8 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
|
||||
addMapperClass(UserPermissionMapper.class);
|
||||
|
||||
// Bind core implementations of guacamole-ext classes
|
||||
bind(ActiveConnectionDirectory.class);
|
||||
bind(ActiveConnectionPermissionSet.class);
|
||||
bind(Environment.class).toInstance(environment);
|
||||
bind(ConnectionDirectory.class);
|
||||
bind(ConnectionGroupDirectory.class);
|
||||
@@ -131,11 +138,14 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
|
||||
bind(ModeledUser.class);
|
||||
bind(RootConnectionGroup.class);
|
||||
bind(SystemPermissionSet.class);
|
||||
bind(TrackedActiveConnection.class);
|
||||
bind(UserContext.class);
|
||||
bind(UserDirectory.class);
|
||||
bind(UserPermissionSet.class);
|
||||
|
||||
// Bind services
|
||||
bind(ActiveConnectionService.class);
|
||||
bind(ActiveConnectionPermissionService.class);
|
||||
bind(ConnectionGroupPermissionService.class);
|
||||
bind(ConnectionGroupService.class);
|
||||
bind(ConnectionPermissionService.class);
|
||||
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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 org.glyptodon.guacamole.auth.jdbc.activeconnection;
|
||||
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
|
||||
import org.glyptodon.guacamole.net.auth.ActiveConnection;
|
||||
import org.glyptodon.guacamole.net.auth.Directory;
|
||||
|
||||
/**
|
||||
* Implementation of a Directory which contains all currently-active
|
||||
* connections.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ActiveConnectionDirectory extends RestrictedObject
|
||||
implements Directory<ActiveConnection> {
|
||||
|
||||
/**
|
||||
* Service for retrieving and manipulating active connections.
|
||||
*/
|
||||
@Inject
|
||||
private ActiveConnectionService activeConnectionService;
|
||||
|
||||
@Override
|
||||
public ActiveConnection get(String identifier) throws GuacamoleException {
|
||||
return activeConnectionService.retrieveObject(getCurrentUser(), identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ActiveConnection> getAll(Collection<String> identifiers)
|
||||
throws GuacamoleException {
|
||||
Collection<TrackedActiveConnection> objects = activeConnectionService.retrieveObjects(getCurrentUser(), identifiers);
|
||||
return Collections.<ActiveConnection>unmodifiableCollection(objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getIdentifiers() throws GuacamoleException {
|
||||
return activeConnectionService.getIdentifiers(getCurrentUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(ActiveConnection object) throws GuacamoleException {
|
||||
activeConnectionService.createObject(getCurrentUser(), object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ActiveConnection object) throws GuacamoleException {
|
||||
TrackedActiveConnection connection = (TrackedActiveConnection) object;
|
||||
activeConnectionService.updateObject(getCurrentUser(), connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(String identifier) throws GuacamoleException {
|
||||
activeConnectionService.deleteObject(getCurrentUser(), identifier);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.activeconnection;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.AbstractPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.ActiveConnectionRecord;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
* manipulating active connections.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ActiveConnectionPermissionService
|
||||
extends AbstractPermissionService<ObjectPermissionSet, ObjectPermission>
|
||||
implements ObjectPermissionService {
|
||||
|
||||
/**
|
||||
* Service for creating and tracking tunnels.
|
||||
*/
|
||||
@Inject
|
||||
private GuacamoleTunnelService tunnelService;
|
||||
|
||||
/**
|
||||
* Provider for active connection permission sets.
|
||||
*/
|
||||
@Inject
|
||||
private Provider<ActiveConnectionPermissionSet> activeConnectionPermissionSetProvider;
|
||||
|
||||
@Override
|
||||
public ObjectPermission retrievePermission(AuthenticatedUser user,
|
||||
ModeledUser targetUser, ObjectPermission.Type type,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Retrieve permissions
|
||||
Set<ObjectPermission> permissions = retrievePermissions(user, targetUser);
|
||||
|
||||
// If retrieved permissions contains the requested permission, return it
|
||||
ObjectPermission permission = new ObjectPermission(type, identifier);
|
||||
if (permissions.contains(permission))
|
||||
return permission;
|
||||
|
||||
// Otherwise, no such permission
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ObjectPermission> retrievePermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException {
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser)) {
|
||||
|
||||
// Only administrators may access active connections
|
||||
if (!targetUser.isAdministrator())
|
||||
return Collections.EMPTY_SET;
|
||||
|
||||
// Get all active connections
|
||||
Collection<ActiveConnectionRecord> records = tunnelService.getActiveConnections(user);
|
||||
|
||||
// We have READ and DELETE on all active connections
|
||||
Set<ObjectPermission> permissions = new HashSet<ObjectPermission>();
|
||||
for (ActiveConnectionRecord record : records) {
|
||||
|
||||
// Add implicit READ and DELETE
|
||||
String identifier = record.getUUID().toString();
|
||||
permissions.add(new ObjectPermission(ObjectPermission.Type.READ, identifier));
|
||||
permissions.add(new ObjectPermission(ObjectPermission.Type.DELETE, identifier));
|
||||
|
||||
}
|
||||
|
||||
return permissions;
|
||||
|
||||
}
|
||||
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> retrieveAccessibleIdentifiers(AuthenticatedUser user,
|
||||
ModeledUser targetUser, Collection<ObjectPermission.Type> permissionTypes,
|
||||
Collection<String> identifiers) throws GuacamoleException {
|
||||
|
||||
Set<ObjectPermission> permissions = retrievePermissions(user, targetUser);
|
||||
Collection<String> accessibleObjects = new ArrayList<String>(permissions.size());
|
||||
|
||||
// For each identifier/permission combination
|
||||
for (String identifier : identifiers) {
|
||||
for (ObjectPermission.Type permissionType : permissionTypes) {
|
||||
|
||||
// Add identifier if at least one requested permission is granted
|
||||
ObjectPermission permission = new ObjectPermission(permissionType, identifier);
|
||||
if (permissions.contains(permission)) {
|
||||
accessibleObjects.add(identifier);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return accessibleObjects;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPermissionSet getPermissionSet(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException {
|
||||
|
||||
// Create permission set for requested user
|
||||
ActiveConnectionPermissionSet permissionSet = activeConnectionPermissionSetProvider.get();
|
||||
permissionSet.init(user, targetUser);
|
||||
|
||||
return permissionSet;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser, Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Creating active connection permissions is not implemented
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser, Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Deleting active connection permissions is not implemented
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.activeconnection;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionSet;
|
||||
|
||||
/**
|
||||
* An implementation of ObjectPermissionSet which uses an injected service to
|
||||
* query and manipulate the permissions associated with active connections.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ActiveConnectionPermissionSet extends ObjectPermissionSet {
|
||||
|
||||
/**
|
||||
* Service for querying and manipulating active connection permissions.
|
||||
*/
|
||||
@Inject
|
||||
private ActiveConnectionPermissionService activeConnectionPermissionService;
|
||||
|
||||
@Override
|
||||
protected ObjectPermissionService getObjectPermissionService() {
|
||||
return activeConnectionPermissionService;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.activeconnection;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.ActiveConnectionRecord;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.ActiveConnection;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
* manipulating active connections.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ActiveConnectionService
|
||||
implements DirectoryObjectService<TrackedActiveConnection, ActiveConnection> {
|
||||
|
||||
/**
|
||||
* Service for creating and tracking tunnels.
|
||||
*/
|
||||
@Inject
|
||||
private GuacamoleTunnelService tunnelService;
|
||||
|
||||
/**
|
||||
* Provider for active connections.
|
||||
*/
|
||||
@Inject
|
||||
private Provider<TrackedActiveConnection> trackedActiveConnectionProvider;
|
||||
|
||||
@Override
|
||||
public TrackedActiveConnection retrieveObject(AuthenticatedUser user,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Only administrators may retrieve active connections
|
||||
if (!user.getUser().isAdministrator())
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
// Retrieve record associated with requested connection
|
||||
ActiveConnectionRecord record = tunnelService.getActiveConnection(user, identifier);
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
// Return tracked active connection using retrieved record
|
||||
TrackedActiveConnection activeConnection = trackedActiveConnectionProvider.get();
|
||||
activeConnection.init(user, record);
|
||||
return activeConnection;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TrackedActiveConnection> retrieveObjects(AuthenticatedUser user,
|
||||
Collection<String> identifiers) throws GuacamoleException {
|
||||
|
||||
// Build list of all active connections with given identifiers
|
||||
Collection<TrackedActiveConnection> activeConnections = new ArrayList<TrackedActiveConnection>(identifiers.size());
|
||||
for (String identifier : identifiers) {
|
||||
|
||||
// Add connection to list if it exists
|
||||
TrackedActiveConnection activeConnection = retrieveObject(user, identifier);
|
||||
if (activeConnection != null)
|
||||
activeConnections.add(activeConnection);
|
||||
|
||||
}
|
||||
|
||||
return activeConnections;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObject(AuthenticatedUser user, String identifier)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Close connection, if it exists (and we have permission)
|
||||
ActiveConnection activeConnection = retrieveObject(user, identifier);
|
||||
if (activeConnection != null) {
|
||||
|
||||
// Close connection if not already closed
|
||||
GuacamoleTunnel tunnel = activeConnection.getTunnel();
|
||||
if (tunnel != null && tunnel.isOpen())
|
||||
tunnel.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getIdentifiers(AuthenticatedUser user)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Retrieve all visible connections (permissions enforced by tunnel service)
|
||||
Collection<ActiveConnectionRecord> records = tunnelService.getActiveConnections(user);
|
||||
|
||||
// Build list of identifiers
|
||||
Set<String> identifiers = new HashSet<String>(records.size());
|
||||
for (ActiveConnectionRecord record : records)
|
||||
identifiers.add(record.getUUID().toString());
|
||||
|
||||
return identifiers;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedActiveConnection createObject(AuthenticatedUser user,
|
||||
ActiveConnection object) throws GuacamoleException {
|
||||
|
||||
// Updating active connections is not implemented
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateObject(AuthenticatedUser user, TrackedActiveConnection object)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Updating active connections is not implemented
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.activeconnection;
|
||||
|
||||
import java.util.Date;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.ActiveConnectionRecord;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.ActiveConnection;
|
||||
|
||||
/**
|
||||
* An implementation of the ActiveConnection object which has an associated
|
||||
* ActiveConnectionRecord.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class TrackedActiveConnection extends RestrictedObject implements ActiveConnection {
|
||||
|
||||
/**
|
||||
* The identifier of this active connection.
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* The identifier of the associated connection.
|
||||
*/
|
||||
private String connectionIdentifier;
|
||||
|
||||
/**
|
||||
* The date and time this active connection began.
|
||||
*/
|
||||
private Date startDate;
|
||||
|
||||
/**
|
||||
* The remote host that initiated this connection.
|
||||
*/
|
||||
private String remoteHost;
|
||||
|
||||
/**
|
||||
* The username of the user that initiated this connection.
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* The underlying GuacamoleTunnel.
|
||||
*/
|
||||
private GuacamoleTunnel tunnel;
|
||||
|
||||
/**
|
||||
* Initializes this TrackedActiveConnection, copying the data associated
|
||||
* with the given active connection record.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user that created or retrieved this object.
|
||||
*
|
||||
* @param activeConnectionRecord
|
||||
* The active connection record to copy.
|
||||
*/
|
||||
public void init(AuthenticatedUser currentUser,
|
||||
ActiveConnectionRecord activeConnectionRecord) {
|
||||
|
||||
super.init(currentUser);
|
||||
|
||||
// Copy all data from given record
|
||||
this.connectionIdentifier = activeConnectionRecord.getConnection().getIdentifier();
|
||||
this.identifier = activeConnectionRecord.getUUID().toString();
|
||||
this.remoteHost = activeConnectionRecord.getRemoteHost();
|
||||
this.startDate = activeConnectionRecord.getStartDate();
|
||||
this.tunnel = activeConnectionRecord.getTunnel();
|
||||
this.username = activeConnectionRecord.getUsername();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionIdentifier() {
|
||||
return connectionIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionIdentifier(String connnectionIdentifier) {
|
||||
this.connectionIdentifier = connnectionIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemoteHost() {
|
||||
return remoteHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoteHost(String remoteHost) {
|
||||
this.remoteHost = remoteHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleTunnel getTunnel() {
|
||||
return tunnel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunnel(GuacamoleTunnel tunnel) {
|
||||
this.tunnel = tunnel;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Classes related to currently-active connections.
|
||||
*/
|
||||
package org.glyptodon.guacamole.auth.jdbc.activeconnection;
|
@@ -22,23 +22,16 @@
|
||||
|
||||
package org.glyptodon.guacamole.auth.jdbc.base;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionModel;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.UserModel;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
* manipulating objects within directories. This service will automatically
|
||||
* enforce the permissions of the current user.
|
||||
* manipulating objects that have unique identifiers, such as the objects
|
||||
* within directories. This service will automatically enforce the permissions
|
||||
* of the current user.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
* @param <InternalType>
|
||||
@@ -48,246 +41,8 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
* @param <ExternalType>
|
||||
* The external interface or implementation of the type of object this
|
||||
* service provides access to, as defined by the guacamole-ext API.
|
||||
*
|
||||
* @param <ModelType>
|
||||
* The underlying model object used to represent InternalType in the
|
||||
* database.
|
||||
*/
|
||||
public abstract class DirectoryObjectService<InternalType extends DirectoryObject<ModelType>,
|
||||
ExternalType, ModelType extends ObjectModel> {
|
||||
|
||||
/**
|
||||
* All object permissions which are implicitly granted upon creation to the
|
||||
* creator of the object.
|
||||
*/
|
||||
private static final ObjectPermission.Type[] IMPLICIT_OBJECT_PERMISSIONS = {
|
||||
ObjectPermission.Type.READ,
|
||||
ObjectPermission.Type.UPDATE,
|
||||
ObjectPermission.Type.DELETE,
|
||||
ObjectPermission.Type.ADMINISTER
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an instance of a mapper for the type of object used by this
|
||||
* service.
|
||||
*
|
||||
* @return
|
||||
* A mapper which provides access to the model objects associated with
|
||||
* the objects used by this service.
|
||||
*/
|
||||
protected abstract DirectoryObjectMapper<ModelType> getObjectMapper();
|
||||
|
||||
/**
|
||||
* Returns an instance of a mapper for the type of permissions that affect
|
||||
* the type of object used by this service.
|
||||
*
|
||||
* @return
|
||||
* A mapper which provides access to the model objects associated with
|
||||
* the permissions that affect the objects used by this service.
|
||||
*/
|
||||
protected abstract ObjectPermissionMapper getPermissionMapper();
|
||||
|
||||
/**
|
||||
* Returns an instance of an object which is backed by the given model
|
||||
* object.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user for whom this object is being created.
|
||||
*
|
||||
* @param model
|
||||
* The model object to use to back the returned object.
|
||||
*
|
||||
* @return
|
||||
* An object which is backed by the given model object.
|
||||
*/
|
||||
protected abstract InternalType getObjectInstance(AuthenticatedUser currentUser,
|
||||
ModelType model);
|
||||
|
||||
/**
|
||||
* Returns an instance of a model object which is based on the given
|
||||
* object.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user for whom this model object is being created.
|
||||
*
|
||||
* @param object
|
||||
* The object to use to produce the returned model object.
|
||||
*
|
||||
* @return
|
||||
* A model object which is based on the given object.
|
||||
*/
|
||||
protected abstract ModelType getModelInstance(AuthenticatedUser currentUser,
|
||||
ExternalType object);
|
||||
|
||||
/**
|
||||
* Returns whether the given user has permission to create the type of
|
||||
* objects that this directory object service manages.
|
||||
*
|
||||
* @param user
|
||||
* The user being checked.
|
||||
*
|
||||
* @return
|
||||
* true if the user has object creation permission relevant to this
|
||||
* directory object service, false otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If permission to read the user's permissions is denied.
|
||||
*/
|
||||
protected abstract boolean hasCreatePermission(AuthenticatedUser user)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns whether the given user has permission to perform a certain
|
||||
* action on a specific object managed by this directory object service.
|
||||
*
|
||||
* @param user
|
||||
* The user being checked.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the object to check.
|
||||
*
|
||||
* @param type
|
||||
* The type of action that will be performed.
|
||||
*
|
||||
* @return
|
||||
* true if the user has object permission relevant described, false
|
||||
* otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If permission to read the user's permissions is denied.
|
||||
*/
|
||||
protected boolean hasObjectPermission(AuthenticatedUser user,
|
||||
String identifier, ObjectPermission.Type type)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Get object permissions
|
||||
ObjectPermissionSet permissionSet = getPermissionSet(user);
|
||||
|
||||
// Return whether permission is granted
|
||||
return user.getUser().isAdministrator()
|
||||
|| permissionSet.hasPermission(type, identifier);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the permission set associated with the given user and related
|
||||
* to the type of objects handled by this directory object service.
|
||||
*
|
||||
* @param user
|
||||
* The user whose permissions are being retrieved.
|
||||
*
|
||||
* @return
|
||||
* A permission set which contains the permissions associated with the
|
||||
* given user and related to the type of objects handled by this
|
||||
* directory object service.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If permission to read the user's permissions is denied.
|
||||
*/
|
||||
protected abstract ObjectPermissionSet getPermissionSet(AuthenticatedUser user)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a collection of objects which are backed by the models in the
|
||||
* given collection.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user for whom these objects are being created.
|
||||
*
|
||||
* @param models
|
||||
* The model objects to use to back the objects within the returned
|
||||
* collection.
|
||||
*
|
||||
* @return
|
||||
* A collection of objects which are backed by the models in the given
|
||||
* collection.
|
||||
*/
|
||||
protected Collection<InternalType> getObjectInstances(AuthenticatedUser currentUser,
|
||||
Collection<ModelType> models) {
|
||||
|
||||
// Create new collection of objects by manually converting each model
|
||||
Collection<InternalType> objects = new ArrayList<InternalType>(models.size());
|
||||
for (ModelType model : models)
|
||||
objects.add(getObjectInstance(currentUser, model));
|
||||
|
||||
return objects;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before any object is created through this directory object
|
||||
* service. This function serves as a final point of validation before
|
||||
* the create operation occurs. In its default implementation,
|
||||
* beforeCreate() performs basic permissions checks.
|
||||
*
|
||||
* @param user
|
||||
* The user creating the object.
|
||||
*
|
||||
* @param model
|
||||
* The model of the object being created.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the object is invalid, or an error prevents validating the given
|
||||
* object.
|
||||
*/
|
||||
protected void beforeCreate(AuthenticatedUser user,
|
||||
ModelType model ) throws GuacamoleException {
|
||||
|
||||
// Verify permission to create objects
|
||||
if (!user.getUser().isAdministrator() && !hasCreatePermission(user))
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before any object is updated through this directory object
|
||||
* service. This function serves as a final point of validation before
|
||||
* the update operation occurs. In its default implementation,
|
||||
* beforeUpdate() performs basic permissions checks.
|
||||
*
|
||||
* @param user
|
||||
* The user updating the existing object.
|
||||
*
|
||||
* @param model
|
||||
* The model of the object being updated.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the object is invalid, or an error prevents validating the given
|
||||
* object.
|
||||
*/
|
||||
protected void beforeUpdate(AuthenticatedUser user,
|
||||
ModelType model) throws GuacamoleException {
|
||||
|
||||
// By default, do nothing.
|
||||
if (!hasObjectPermission(user, model.getIdentifier(), ObjectPermission.Type.UPDATE))
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before any object is deleted through this directory object
|
||||
* service. This function serves as a final point of validation before
|
||||
* the delete operation occurs. In its default implementation,
|
||||
* beforeDelete() performs basic permissions checks.
|
||||
*
|
||||
* @param user
|
||||
* The user deleting the existing object.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the object being deleted.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the object is invalid, or an error prevents validating the given
|
||||
* object.
|
||||
*/
|
||||
protected void beforeDelete(AuthenticatedUser user,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Verify permission to delete objects
|
||||
if (!hasObjectPermission(user, identifier, ObjectPermission.Type.DELETE))
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
public interface DirectoryObjectService<InternalType, ExternalType> {
|
||||
|
||||
/**
|
||||
* Retrieves the single object that has the given identifier, if it exists
|
||||
@@ -306,24 +61,8 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while retrieving the requested object.
|
||||
*/
|
||||
public InternalType retrieveObject(AuthenticatedUser user,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Pull objects having given identifier
|
||||
Collection<InternalType> objects = retrieveObjects(user, Collections.singleton(identifier));
|
||||
|
||||
// If no such object, return null
|
||||
if (objects.isEmpty())
|
||||
return null;
|
||||
|
||||
// The object collection will have exactly one element unless the
|
||||
// database has seriously lost integrity
|
||||
assert(objects.size() == 1);
|
||||
|
||||
// Return first and only object
|
||||
return objects.iterator().next();
|
||||
|
||||
}
|
||||
InternalType retrieveObject(AuthenticatedUser user, String identifier)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Retrieves all objects that have the identifiers in the given collection.
|
||||
@@ -341,73 +80,12 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while retrieving the requested objects.
|
||||
*/
|
||||
public Collection<InternalType> retrieveObjects(AuthenticatedUser user,
|
||||
Collection<String> identifiers) throws GuacamoleException {
|
||||
|
||||
// Do not query if no identifiers given
|
||||
if (identifiers.isEmpty())
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
Collection<ModelType> objects;
|
||||
|
||||
// Bypass permission checks if the user is a system admin
|
||||
if (user.getUser().isAdministrator())
|
||||
objects = getObjectMapper().select(identifiers);
|
||||
|
||||
// Otherwise only return explicitly readable identifiers
|
||||
else
|
||||
objects = getObjectMapper().selectReadable(user.getUser().getModel(), identifiers);
|
||||
|
||||
// Return collection of requested objects
|
||||
return getObjectInstances(user, objects);
|
||||
|
||||
}
|
||||
Collection<InternalType> retrieveObjects(AuthenticatedUser user,
|
||||
Collection<String> identifiers) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a collection of permissions that should be granted due to the
|
||||
* creation of the given object. These permissions need not be granted
|
||||
* solely to the user creating the object.
|
||||
*
|
||||
* @param user
|
||||
* The user creating the object.
|
||||
*
|
||||
* @param model
|
||||
* The object being created.
|
||||
*
|
||||
* @return
|
||||
* The collection of implicit permissions that should be granted due to
|
||||
* the creation of the given object.
|
||||
*/
|
||||
protected Collection<ObjectPermissionModel> getImplicitPermissions(AuthenticatedUser user,
|
||||
ModelType model) {
|
||||
|
||||
// Build list of implicit permissions
|
||||
Collection<ObjectPermissionModel> implicitPermissions =
|
||||
new ArrayList<ObjectPermissionModel>(IMPLICIT_OBJECT_PERMISSIONS.length);
|
||||
|
||||
UserModel userModel = user.getUser().getModel();
|
||||
for (ObjectPermission.Type permission : IMPLICIT_OBJECT_PERMISSIONS) {
|
||||
|
||||
// Create model which grants this permission to the current user
|
||||
ObjectPermissionModel permissionModel = new ObjectPermissionModel();
|
||||
permissionModel.setUserID(userModel.getObjectID());
|
||||
permissionModel.setUsername(userModel.getIdentifier());
|
||||
permissionModel.setType(permission);
|
||||
permissionModel.setObjectIdentifier(model.getIdentifier());
|
||||
|
||||
// Add permission
|
||||
implicitPermissions.add(permissionModel);
|
||||
|
||||
}
|
||||
|
||||
return implicitPermissions;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the given object within the database. If the object already
|
||||
* exists, an error will be thrown. The internal model object will be
|
||||
* updated appropriately to contain the new database ID.
|
||||
* Creates the given object. If the object already exists, an error will be
|
||||
* thrown.
|
||||
*
|
||||
* @param user
|
||||
* The user creating the object.
|
||||
@@ -422,21 +100,8 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
* If the user lacks permission to create the object, or an error
|
||||
* occurs while creating the object.
|
||||
*/
|
||||
public InternalType createObject(AuthenticatedUser user, ExternalType object)
|
||||
throws GuacamoleException {
|
||||
|
||||
ModelType model = getModelInstance(user, object);
|
||||
beforeCreate(user, model);
|
||||
|
||||
// Create object
|
||||
getObjectMapper().insert(model);
|
||||
|
||||
// Add implicit permissions
|
||||
getPermissionMapper().insert(getImplicitPermissions(user, model));
|
||||
|
||||
return getObjectInstance(user, model);
|
||||
|
||||
}
|
||||
InternalType createObject(AuthenticatedUser user, ExternalType object)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Deletes the object having the given identifier. If no such object
|
||||
@@ -452,19 +117,12 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
* If the user lacks permission to delete the object, or an error
|
||||
* occurs while deleting the object.
|
||||
*/
|
||||
public void deleteObject(AuthenticatedUser user, String identifier)
|
||||
throws GuacamoleException {
|
||||
|
||||
beforeDelete(user, identifier);
|
||||
|
||||
// Delete object
|
||||
getObjectMapper().delete(identifier);
|
||||
|
||||
}
|
||||
void deleteObject(AuthenticatedUser user, String identifier)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Updates the given object in the database, applying any changes that have
|
||||
* been made. If no such object exists, this function has no effect.
|
||||
* Updates the given object, applying any changes that have been made. If
|
||||
* no such object exists, this function has no effect.
|
||||
*
|
||||
* @param user
|
||||
* The user updating the object.
|
||||
@@ -476,41 +134,22 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
* If the user lacks permission to update the object, or an error
|
||||
* occurs while updating the object.
|
||||
*/
|
||||
public void updateObject(AuthenticatedUser user, InternalType object)
|
||||
throws GuacamoleException {
|
||||
|
||||
ModelType model = object.getModel();
|
||||
beforeUpdate(user, model);
|
||||
|
||||
// Update object
|
||||
getObjectMapper().update(model);
|
||||
|
||||
}
|
||||
void updateObject(AuthenticatedUser user, InternalType object)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns the set of all identifiers for all objects in the database that
|
||||
* the user has read access to.
|
||||
* Returns the set of all identifiers for all objects that the user has
|
||||
* read access to.
|
||||
*
|
||||
* @param user
|
||||
* The user retrieving the identifiers.
|
||||
*
|
||||
* @return
|
||||
* The set of all identifiers for all objects in the database.
|
||||
* The set of all identifiers for all objects.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while reading identifiers.
|
||||
*/
|
||||
public Set<String> getIdentifiers(AuthenticatedUser user)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Bypass permission checks if the user is a system admin
|
||||
if (user.getUser().isAdministrator())
|
||||
return getObjectMapper().selectIdentifiers();
|
||||
|
||||
// Otherwise only return explicitly readable identifiers
|
||||
else
|
||||
return getObjectMapper().selectReadableIdentifiers(user.getUser().getModel());
|
||||
|
||||
}
|
||||
Set<String> getIdentifiers(AuthenticatedUser user) throws GuacamoleException;
|
||||
|
||||
}
|
||||
|
@@ -26,14 +26,15 @@ import org.glyptodon.guacamole.net.auth.Identifiable;
|
||||
|
||||
/**
|
||||
* Common base class for objects that will ultimately be made available through
|
||||
* the Directory class. All such objects will need the same base set of queries
|
||||
* to fulfill the needs of the Directory class.
|
||||
* the Directory class and are persisted to an underlying database model. All
|
||||
* such objects will need the same base set of queries to fulfill the needs of
|
||||
* the Directory class.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
* @param <ModelType>
|
||||
* The type of model object that corresponds to this object.
|
||||
*/
|
||||
public abstract class DirectoryObject<ModelType extends ObjectModel>
|
||||
public abstract class ModeledDirectoryObject<ModelType extends ObjectModel>
|
||||
extends ModeledObject<ModelType> implements Identifiable {
|
||||
|
||||
@Override
|
@@ -37,7 +37,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
* The type of object contained within the directory whose objects are
|
||||
* mapped by this mapper.
|
||||
*/
|
||||
public interface DirectoryObjectMapper<ModelType> {
|
||||
public interface ModeledDirectoryObjectMapper<ModelType> {
|
||||
|
||||
/**
|
||||
* Selects the identifiers of all objects, regardless of whether they
|
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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 org.glyptodon.guacamole.auth.jdbc.base;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionModel;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.UserModel;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
* manipulating objects within directories. This service will automatically
|
||||
* enforce the permissions of the current user.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
* @param <InternalType>
|
||||
* The specific internal implementation of the type of object this service
|
||||
* provides access to.
|
||||
*
|
||||
* @param <ExternalType>
|
||||
* The external interface or implementation of the type of object this
|
||||
* service provides access to, as defined by the guacamole-ext API.
|
||||
*
|
||||
* @param <ModelType>
|
||||
* The underlying model object used to represent InternalType in the
|
||||
* database.
|
||||
*/
|
||||
public abstract class ModeledDirectoryObjectService<InternalType extends ModeledDirectoryObject<ModelType>,
|
||||
ExternalType, ModelType extends ObjectModel>
|
||||
implements DirectoryObjectService<InternalType, ExternalType> {
|
||||
|
||||
/**
|
||||
* All object permissions which are implicitly granted upon creation to the
|
||||
* creator of the object.
|
||||
*/
|
||||
private static final ObjectPermission.Type[] IMPLICIT_OBJECT_PERMISSIONS = {
|
||||
ObjectPermission.Type.READ,
|
||||
ObjectPermission.Type.UPDATE,
|
||||
ObjectPermission.Type.DELETE,
|
||||
ObjectPermission.Type.ADMINISTER
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an instance of a mapper for the type of object used by this
|
||||
* service.
|
||||
*
|
||||
* @return
|
||||
* A mapper which provides access to the model objects associated with
|
||||
* the objects used by this service.
|
||||
*/
|
||||
protected abstract ModeledDirectoryObjectMapper<ModelType> getObjectMapper();
|
||||
|
||||
/**
|
||||
* Returns an instance of a mapper for the type of permissions that affect
|
||||
* the type of object used by this service.
|
||||
*
|
||||
* @return
|
||||
* A mapper which provides access to the model objects associated with
|
||||
* the permissions that affect the objects used by this service.
|
||||
*/
|
||||
protected abstract ObjectPermissionMapper getPermissionMapper();
|
||||
|
||||
/**
|
||||
* Returns an instance of an object which is backed by the given model
|
||||
* object.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user for whom this object is being created.
|
||||
*
|
||||
* @param model
|
||||
* The model object to use to back the returned object.
|
||||
*
|
||||
* @return
|
||||
* An object which is backed by the given model object.
|
||||
*/
|
||||
protected abstract InternalType getObjectInstance(AuthenticatedUser currentUser,
|
||||
ModelType model);
|
||||
|
||||
/**
|
||||
* Returns an instance of a model object which is based on the given
|
||||
* object.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user for whom this model object is being created.
|
||||
*
|
||||
* @param object
|
||||
* The object to use to produce the returned model object.
|
||||
*
|
||||
* @return
|
||||
* A model object which is based on the given object.
|
||||
*/
|
||||
protected abstract ModelType getModelInstance(AuthenticatedUser currentUser,
|
||||
ExternalType object);
|
||||
|
||||
/**
|
||||
* Returns whether the given user has permission to create the type of
|
||||
* objects that this directory object service manages.
|
||||
*
|
||||
* @param user
|
||||
* The user being checked.
|
||||
*
|
||||
* @return
|
||||
* true if the user has object creation permission relevant to this
|
||||
* directory object service, false otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If permission to read the user's permissions is denied.
|
||||
*/
|
||||
protected abstract boolean hasCreatePermission(AuthenticatedUser user)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns whether the given user has permission to perform a certain
|
||||
* action on a specific object managed by this directory object service.
|
||||
*
|
||||
* @param user
|
||||
* The user being checked.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the object to check.
|
||||
*
|
||||
* @param type
|
||||
* The type of action that will be performed.
|
||||
*
|
||||
* @return
|
||||
* true if the user has object permission relevant described, false
|
||||
* otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If permission to read the user's permissions is denied.
|
||||
*/
|
||||
protected boolean hasObjectPermission(AuthenticatedUser user,
|
||||
String identifier, ObjectPermission.Type type)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Get object permissions
|
||||
ObjectPermissionSet permissionSet = getPermissionSet(user);
|
||||
|
||||
// Return whether permission is granted
|
||||
return user.getUser().isAdministrator()
|
||||
|| permissionSet.hasPermission(type, identifier);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the permission set associated with the given user and related
|
||||
* to the type of objects handled by this directory object service.
|
||||
*
|
||||
* @param user
|
||||
* The user whose permissions are being retrieved.
|
||||
*
|
||||
* @return
|
||||
* A permission set which contains the permissions associated with the
|
||||
* given user and related to the type of objects handled by this
|
||||
* directory object service.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If permission to read the user's permissions is denied.
|
||||
*/
|
||||
protected abstract ObjectPermissionSet getPermissionSet(AuthenticatedUser user)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a collection of objects which are backed by the models in the
|
||||
* given collection.
|
||||
*
|
||||
* @param currentUser
|
||||
* The user for whom these objects are being created.
|
||||
*
|
||||
* @param models
|
||||
* The model objects to use to back the objects within the returned
|
||||
* collection.
|
||||
*
|
||||
* @return
|
||||
* A collection of objects which are backed by the models in the given
|
||||
* collection.
|
||||
*/
|
||||
protected Collection<InternalType> getObjectInstances(AuthenticatedUser currentUser,
|
||||
Collection<ModelType> models) {
|
||||
|
||||
// Create new collection of objects by manually converting each model
|
||||
Collection<InternalType> objects = new ArrayList<InternalType>(models.size());
|
||||
for (ModelType model : models)
|
||||
objects.add(getObjectInstance(currentUser, model));
|
||||
|
||||
return objects;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before any object is created through this directory object
|
||||
* service. This function serves as a final point of validation before
|
||||
* the create operation occurs. In its default implementation,
|
||||
* beforeCreate() performs basic permissions checks.
|
||||
*
|
||||
* @param user
|
||||
* The user creating the object.
|
||||
*
|
||||
* @param model
|
||||
* The model of the object being created.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the object is invalid, or an error prevents validating the given
|
||||
* object.
|
||||
*/
|
||||
protected void beforeCreate(AuthenticatedUser user,
|
||||
ModelType model ) throws GuacamoleException {
|
||||
|
||||
// Verify permission to create objects
|
||||
if (!user.getUser().isAdministrator() && !hasCreatePermission(user))
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before any object is updated through this directory object
|
||||
* service. This function serves as a final point of validation before
|
||||
* the update operation occurs. In its default implementation,
|
||||
* beforeUpdate() performs basic permissions checks.
|
||||
*
|
||||
* @param user
|
||||
* The user updating the existing object.
|
||||
*
|
||||
* @param model
|
||||
* The model of the object being updated.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the object is invalid, or an error prevents validating the given
|
||||
* object.
|
||||
*/
|
||||
protected void beforeUpdate(AuthenticatedUser user,
|
||||
ModelType model) throws GuacamoleException {
|
||||
|
||||
// By default, do nothing.
|
||||
if (!hasObjectPermission(user, model.getIdentifier(), ObjectPermission.Type.UPDATE))
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before any object is deleted through this directory object
|
||||
* service. This function serves as a final point of validation before
|
||||
* the delete operation occurs. In its default implementation,
|
||||
* beforeDelete() performs basic permissions checks.
|
||||
*
|
||||
* @param user
|
||||
* The user deleting the existing object.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the object being deleted.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the object is invalid, or an error prevents validating the given
|
||||
* object.
|
||||
*/
|
||||
protected void beforeDelete(AuthenticatedUser user,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Verify permission to delete objects
|
||||
if (!hasObjectPermission(user, identifier, ObjectPermission.Type.DELETE))
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalType retrieveObject(AuthenticatedUser user,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Pull objects having given identifier
|
||||
Collection<InternalType> objects = retrieveObjects(user, Collections.singleton(identifier));
|
||||
|
||||
// If no such object, return null
|
||||
if (objects.isEmpty())
|
||||
return null;
|
||||
|
||||
// The object collection will have exactly one element unless the
|
||||
// database has seriously lost integrity
|
||||
assert(objects.size() == 1);
|
||||
|
||||
// Return first and only object
|
||||
return objects.iterator().next();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<InternalType> retrieveObjects(AuthenticatedUser user,
|
||||
Collection<String> identifiers) throws GuacamoleException {
|
||||
|
||||
// Do not query if no identifiers given
|
||||
if (identifiers.isEmpty())
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
Collection<ModelType> objects;
|
||||
|
||||
// Bypass permission checks if the user is a system admin
|
||||
if (user.getUser().isAdministrator())
|
||||
objects = getObjectMapper().select(identifiers);
|
||||
|
||||
// Otherwise only return explicitly readable identifiers
|
||||
else
|
||||
objects = getObjectMapper().selectReadable(user.getUser().getModel(), identifiers);
|
||||
|
||||
// Return collection of requested objects
|
||||
return getObjectInstances(user, objects);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of permissions that should be granted due to the
|
||||
* creation of the given object. These permissions need not be granted
|
||||
* solely to the user creating the object.
|
||||
*
|
||||
* @param user
|
||||
* The user creating the object.
|
||||
*
|
||||
* @param model
|
||||
* The object being created.
|
||||
*
|
||||
* @return
|
||||
* The collection of implicit permissions that should be granted due to
|
||||
* the creation of the given object.
|
||||
*/
|
||||
protected Collection<ObjectPermissionModel> getImplicitPermissions(AuthenticatedUser user,
|
||||
ModelType model) {
|
||||
|
||||
// Build list of implicit permissions
|
||||
Collection<ObjectPermissionModel> implicitPermissions =
|
||||
new ArrayList<ObjectPermissionModel>(IMPLICIT_OBJECT_PERMISSIONS.length);
|
||||
|
||||
UserModel userModel = user.getUser().getModel();
|
||||
for (ObjectPermission.Type permission : IMPLICIT_OBJECT_PERMISSIONS) {
|
||||
|
||||
// Create model which grants this permission to the current user
|
||||
ObjectPermissionModel permissionModel = new ObjectPermissionModel();
|
||||
permissionModel.setUserID(userModel.getObjectID());
|
||||
permissionModel.setUsername(userModel.getIdentifier());
|
||||
permissionModel.setType(permission);
|
||||
permissionModel.setObjectIdentifier(model.getIdentifier());
|
||||
|
||||
// Add permission
|
||||
implicitPermissions.add(permissionModel);
|
||||
|
||||
}
|
||||
|
||||
return implicitPermissions;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalType createObject(AuthenticatedUser user, ExternalType object)
|
||||
throws GuacamoleException {
|
||||
|
||||
ModelType model = getModelInstance(user, object);
|
||||
beforeCreate(user, model);
|
||||
|
||||
// Create object
|
||||
getObjectMapper().insert(model);
|
||||
|
||||
// Add implicit permissions
|
||||
getPermissionMapper().insert(getImplicitPermissions(user, model));
|
||||
|
||||
return getObjectInstance(user, model);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObject(AuthenticatedUser user, String identifier)
|
||||
throws GuacamoleException {
|
||||
|
||||
beforeDelete(user, identifier);
|
||||
|
||||
// Delete object
|
||||
getObjectMapper().delete(identifier);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateObject(AuthenticatedUser user, InternalType object)
|
||||
throws GuacamoleException {
|
||||
|
||||
ModelType model = object.getModel();
|
||||
beforeUpdate(user, model);
|
||||
|
||||
// Update object
|
||||
getObjectMapper().update(model);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getIdentifiers(AuthenticatedUser user)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Bypass permission checks if the user is a system admin
|
||||
if (user.getUser().isAdministrator())
|
||||
return getObjectMapper().selectIdentifiers();
|
||||
|
||||
// Otherwise only return explicitly readable identifiers
|
||||
else
|
||||
return getObjectMapper().selectReadableIdentifiers(user.getUser().getModel());
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -33,8 +33,8 @@ import org.glyptodon.guacamole.auth.jdbc.connectiongroup.RootConnectionGroup;
|
||||
* @param <ModelType>
|
||||
* The type of model object that corresponds to this object.
|
||||
*/
|
||||
public abstract class GroupedDirectoryObject<ModelType extends GroupedObjectModel>
|
||||
extends DirectoryObject<ModelType> {
|
||||
public abstract class ModeledGroupedDirectoryObject<ModelType extends GroupedObjectModel>
|
||||
extends ModeledDirectoryObject<ModelType> {
|
||||
|
||||
/**
|
||||
* Returns the identifier of the parent connection group, which cannot be
|
@@ -49,9 +49,9 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
* The underlying model object used to represent InternalType in the
|
||||
* database.
|
||||
*/
|
||||
public abstract class GroupedDirectoryObjectService<InternalType extends GroupedDirectoryObject<ModelType>,
|
||||
public abstract class ModeledGroupedDirectoryObjectService<InternalType extends ModeledGroupedDirectoryObject<ModelType>,
|
||||
ExternalType, ModelType extends GroupedObjectModel>
|
||||
extends DirectoryObjectService<InternalType, ExternalType, ModelType> {
|
||||
extends ModeledDirectoryObjectService<InternalType, ExternalType, ModelType> {
|
||||
|
||||
/**
|
||||
* Returns the set of parent connection groups that are modified by the
|
@@ -23,7 +23,7 @@
|
||||
package org.glyptodon.guacamole.auth.jdbc.connection;
|
||||
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.UserModel;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface ConnectionMapper extends DirectoryObjectMapper<ConnectionModel> {
|
||||
public interface ConnectionMapper extends ModeledDirectoryObjectMapper<ConnectionModel> {
|
||||
|
||||
/**
|
||||
* Selects the identifiers of all connections within the given parent
|
||||
|
@@ -32,12 +32,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.GroupedDirectoryObjectService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObjectService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ConnectionPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionMapper;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
@@ -55,7 +55,7 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
*
|
||||
* @author Michael Jumper, James Muehlner
|
||||
*/
|
||||
public class ConnectionService extends GroupedDirectoryObjectService<ModeledConnection, Connection, ConnectionModel> {
|
||||
public class ConnectionService extends ModeledGroupedDirectoryObjectService<ModeledConnection, Connection, ConnectionModel> {
|
||||
|
||||
/**
|
||||
* Mapper for accessing connections.
|
||||
@@ -94,7 +94,7 @@ public class ConnectionService extends GroupedDirectoryObjectService<ModeledConn
|
||||
private GuacamoleTunnelService tunnelService;
|
||||
|
||||
@Override
|
||||
protected DirectoryObjectMapper<ConnectionModel> getObjectMapper() {
|
||||
protected ModeledDirectoryObjectMapper<ConnectionModel> getObjectMapper() {
|
||||
return connectionMapper;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ import com.google.inject.Provider;
|
||||
import java.util.List;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.GroupedDirectoryObject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObject;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
@@ -41,7 +41,7 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
|
||||
* @author James Muehlner
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ModeledConnection extends GroupedDirectoryObject<ConnectionModel>
|
||||
public class ModeledConnection extends ModeledGroupedDirectoryObject<ConnectionModel>
|
||||
implements Connection {
|
||||
|
||||
/**
|
||||
|
@@ -24,7 +24,6 @@ package org.glyptodon.guacamole.auth.jdbc.connection;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
|
||||
/**
|
||||
@@ -52,11 +51,6 @@ public class ModeledConnectionRecord implements ConnectionRecord {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return model.getConnectionIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartDate() {
|
||||
return model.getStartDate();
|
||||
@@ -82,9 +76,4 @@ public class ModeledConnectionRecord implements ConnectionRecord {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleTunnel getTunnel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
package org.glyptodon.guacamole.auth.jdbc.connectiongroup;
|
||||
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.UserModel;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface ConnectionGroupMapper extends DirectoryObjectMapper<ConnectionGroupModel> {
|
||||
public interface ConnectionGroupMapper extends ModeledDirectoryObjectMapper<ConnectionGroupModel> {
|
||||
|
||||
/**
|
||||
* Selects the identifiers of all connection groups within the given parent
|
||||
|
@@ -26,13 +26,13 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.GroupedDirectoryObjectService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObjectService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ConnectionGroupPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionMapper;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
@@ -49,7 +49,7 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
*
|
||||
* @author Michael Jumper, James Muehlner
|
||||
*/
|
||||
public class ConnectionGroupService extends GroupedDirectoryObjectService<ModeledConnectionGroup,
|
||||
public class ConnectionGroupService extends ModeledGroupedDirectoryObjectService<ModeledConnectionGroup,
|
||||
ConnectionGroup, ConnectionGroupModel> {
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ public class ConnectionGroupService extends GroupedDirectoryObjectService<Modele
|
||||
private GuacamoleTunnelService tunnelService;
|
||||
|
||||
@Override
|
||||
protected DirectoryObjectMapper<ConnectionGroupModel> getObjectMapper() {
|
||||
protected ModeledDirectoryObjectMapper<ConnectionGroupModel> getObjectMapper() {
|
||||
return connectionGroupMapper;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.GroupedDirectoryObject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObject;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
@@ -38,7 +38,7 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
*
|
||||
* @author James Muehlner
|
||||
*/
|
||||
public class ModeledConnectionGroup extends GroupedDirectoryObject<ConnectionGroupModel>
|
||||
public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject<ConnectionGroupModel>
|
||||
implements ConnectionGroup {
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.permission;
|
||||
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
import org.glyptodon.guacamole.net.auth.permission.Permission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.PermissionSet;
|
||||
|
||||
/**
|
||||
* Abstract PermissionService implementation which provides additional
|
||||
* convenience methods for enforcing the permission model.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
* @param <PermissionSetType>
|
||||
* The type of permission sets this service provides access to.
|
||||
*
|
||||
* @param <PermissionType>
|
||||
* The type of permission this service provides access to.
|
||||
*/
|
||||
public abstract class AbstractPermissionService<PermissionSetType extends PermissionSet<PermissionType>,
|
||||
PermissionType extends Permission>
|
||||
implements PermissionService<PermissionSetType, PermissionType> {
|
||||
|
||||
/**
|
||||
* Determines whether the given user can read the permissions currently
|
||||
* granted to the given target user. If the reading user and the target
|
||||
* user are not the same, then explicit READ or SYSTEM_ADMINISTER access is
|
||||
* required.
|
||||
*
|
||||
* @param user
|
||||
* The user attempting to read permissions.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user whose permissions are being read.
|
||||
*
|
||||
* @return
|
||||
* true if permission is granted, false otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while checking permission status, or if
|
||||
* permission is denied to read the current user's permissions.
|
||||
*/
|
||||
protected boolean canReadPermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException {
|
||||
|
||||
// A user can always read their own permissions
|
||||
if (user.getUser().getIdentifier().equals(targetUser.getIdentifier()))
|
||||
return true;
|
||||
|
||||
// A system adminstrator can do anything
|
||||
if (user.getUser().isAdministrator())
|
||||
return true;
|
||||
|
||||
// Can read permissions on target user if explicit READ is granted
|
||||
ObjectPermissionSet userPermissionSet = user.getUser().getUserPermissions();
|
||||
return userPermissionSet.hasPermission(ObjectPermission.Type.READ, targetUser.getIdentifier());
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -35,7 +35,7 @@ import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ConnectionGroupPermissionService extends ObjectPermissionService {
|
||||
public class ConnectionGroupPermissionService extends ModeledObjectPermissionService {
|
||||
|
||||
/**
|
||||
* Mapper for connection group permissions.
|
||||
|
@@ -35,7 +35,7 @@ import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ConnectionPermissionService extends ObjectPermissionService {
|
||||
public class ConnectionPermissionService extends ModeledObjectPermissionService {
|
||||
|
||||
/**
|
||||
* Mapper for connection permissions.
|
||||
|
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.permission;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
* deleting object permissions within a backend database model. This service
|
||||
* will automatically enforce the permissions of the current user.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public abstract class ModeledObjectPermissionService
|
||||
extends ModeledPermissionService<ObjectPermissionSet, ObjectPermission, ObjectPermissionModel>
|
||||
implements ObjectPermissionService {
|
||||
|
||||
@Override
|
||||
protected abstract ObjectPermissionMapper getPermissionMapper();
|
||||
|
||||
@Override
|
||||
protected ObjectPermission getPermissionInstance(ObjectPermissionModel model) {
|
||||
return new ObjectPermission(model.getType(), model.getObjectIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectPermissionModel getModelInstance(ModeledUser targetUser,
|
||||
ObjectPermission permission) {
|
||||
|
||||
ObjectPermissionModel model = new ObjectPermissionModel();
|
||||
|
||||
// Populate model object with data from user and permission
|
||||
model.setUserID(targetUser.getModel().getObjectID());
|
||||
model.setUsername(targetUser.getModel().getIdentifier());
|
||||
model.setType(permission.getType());
|
||||
model.setObjectIdentifier(permission.getObjectIdentifier());
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current user has permission to update the given
|
||||
* target user, adding or removing the given permissions. Such permission
|
||||
* depends on whether the current user is a system administrator, whether
|
||||
* they have explicit UPDATE permission on the target user, and whether
|
||||
* they have explicit ADMINISTER permission on all affected objects.
|
||||
*
|
||||
* @param user
|
||||
* The user who is changing permissions.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user whose permissions are being changed.
|
||||
*
|
||||
* @param permissions
|
||||
* The permissions that are being added or removed from the target
|
||||
* user.
|
||||
*
|
||||
* @return
|
||||
* true if the user has permission to change the target users
|
||||
* permissions as specified, false otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while checking permission status, or if
|
||||
* permission is denied to read the current user's permissions.
|
||||
*/
|
||||
protected boolean canAlterPermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// A system adminstrator can do anything
|
||||
if (user.getUser().isAdministrator())
|
||||
return true;
|
||||
|
||||
// Verify user has update permission on the target user
|
||||
ObjectPermissionSet userPermissionSet = user.getUser().getUserPermissions();
|
||||
if (!userPermissionSet.hasPermission(ObjectPermission.Type.UPDATE, targetUser.getIdentifier()))
|
||||
return false;
|
||||
|
||||
// Produce collection of affected identifiers
|
||||
Collection<String> affectedIdentifiers = new HashSet(permissions.size());
|
||||
for (ObjectPermission permission : permissions)
|
||||
affectedIdentifiers.add(permission.getObjectIdentifier());
|
||||
|
||||
// Determine subset of affected identifiers that we have admin access to
|
||||
ObjectPermissionSet affectedPermissionSet = getPermissionSet(user, user.getUser());
|
||||
Collection<String> allowedSubset = affectedPermissionSet.getAccessibleObjects(
|
||||
Collections.singleton(ObjectPermission.Type.ADMINISTER),
|
||||
affectedIdentifiers
|
||||
);
|
||||
|
||||
// The permissions can be altered if and only if the set of objects we
|
||||
// are allowed to administer is equal to the set of objects we will be
|
||||
// affecting.
|
||||
|
||||
return affectedIdentifiers.size() == allowedSubset.size();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Create permissions only if user has permission to do so
|
||||
if (canAlterPermissions(user, targetUser, permissions)) {
|
||||
Collection<ObjectPermissionModel> models = getModelInstances(targetUser, permissions);
|
||||
getPermissionMapper().insert(models);
|
||||
return;
|
||||
}
|
||||
|
||||
// User lacks permission to create object permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Delete permissions only if user has permission to do so
|
||||
if (canAlterPermissions(user, targetUser, permissions)) {
|
||||
Collection<ObjectPermissionModel> models = getModelInstances(targetUser, permissions);
|
||||
getPermissionMapper().delete(models);
|
||||
return;
|
||||
}
|
||||
|
||||
// User lacks permission to delete object permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPermission retrievePermission(AuthenticatedUser user,
|
||||
ModeledUser targetUser, ObjectPermission.Type type,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser)) {
|
||||
|
||||
// Read permission from database, return null if not found
|
||||
ObjectPermissionModel model = getPermissionMapper().selectOne(targetUser.getModel(), type, identifier);
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return getPermissionInstance(model);
|
||||
|
||||
}
|
||||
|
||||
// User cannot read this user's permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> retrieveAccessibleIdentifiers(AuthenticatedUser user,
|
||||
ModeledUser targetUser, Collection<ObjectPermission.Type> permissions,
|
||||
Collection<String> identifiers) throws GuacamoleException {
|
||||
|
||||
// Nothing is always accessible
|
||||
if (identifiers.isEmpty())
|
||||
return identifiers;
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser)) {
|
||||
|
||||
// If user is an admin, everything is accessible
|
||||
if (user.getUser().isAdministrator())
|
||||
return identifiers;
|
||||
|
||||
// Otherwise, return explicitly-retrievable identifiers
|
||||
return getPermissionMapper().selectAccessibleIdentifiers(targetUser.getModel(), permissions, identifiers);
|
||||
|
||||
}
|
||||
|
||||
// User cannot read this user's permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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 org.glyptodon.guacamole.auth.jdbc.permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.net.auth.permission.Permission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.PermissionSet;
|
||||
|
||||
/**
|
||||
* Service which provides convenience methods for creating, retrieving, and
|
||||
* deleting permissions within a backend database model, and for obtaining the
|
||||
* permission sets that contain these permissions. This service will
|
||||
* automatically enforce the permissions of the current user.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
* @param <PermissionSetType>
|
||||
* The type of permission sets this service provides access to.
|
||||
*
|
||||
* @param <PermissionType>
|
||||
* The type of permission this service provides access to.
|
||||
*
|
||||
* @param <ModelType>
|
||||
* The underlying model object used to represent PermissionType in the
|
||||
* database.
|
||||
*/
|
||||
public abstract class ModeledPermissionService<PermissionSetType extends PermissionSet<PermissionType>,
|
||||
PermissionType extends Permission, ModelType>
|
||||
extends AbstractPermissionService<PermissionSetType, PermissionType> {
|
||||
|
||||
/**
|
||||
* Returns an instance of a mapper for the type of permission used by this
|
||||
* service.
|
||||
*
|
||||
* @return
|
||||
* A mapper which provides access to the model objects associated with
|
||||
* the permissions used by this service.
|
||||
*/
|
||||
protected abstract PermissionMapper<ModelType> getPermissionMapper();
|
||||
|
||||
/**
|
||||
* Returns an instance of a permission which is based on the given model
|
||||
* object.
|
||||
*
|
||||
* @param model
|
||||
* The model object to use to produce the returned permission.
|
||||
*
|
||||
* @return
|
||||
* A permission which is based on the given model object.
|
||||
*/
|
||||
protected abstract PermissionType getPermissionInstance(ModelType model);
|
||||
|
||||
/**
|
||||
* Returns a collection of permissions which are based on the models in
|
||||
* the given collection.
|
||||
*
|
||||
* @param models
|
||||
* The model objects to use to produce the permissions within the
|
||||
* returned set.
|
||||
*
|
||||
* @return
|
||||
* A set of permissions which are based on the models in the given
|
||||
* collection.
|
||||
*/
|
||||
protected Set<PermissionType> getPermissionInstances(Collection<ModelType> models) {
|
||||
|
||||
// Create new collection of permissions by manually converting each model
|
||||
Set<PermissionType> permissions = new HashSet<PermissionType>(models.size());
|
||||
for (ModelType model : models)
|
||||
permissions.add(getPermissionInstance(model));
|
||||
|
||||
return permissions;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a model object which is based on the given
|
||||
* permission and target user.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user to whom this permission is granted.
|
||||
*
|
||||
* @param permission
|
||||
* The permission to use to produce the returned model object.
|
||||
*
|
||||
* @return
|
||||
* A model object which is based on the given permission and target
|
||||
* user.
|
||||
*/
|
||||
protected abstract ModelType getModelInstance(ModeledUser targetUser,
|
||||
PermissionType permission);
|
||||
|
||||
/**
|
||||
* Returns a collection of model objects which are based on the given
|
||||
* permissions and target user.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user to whom this permission is granted.
|
||||
*
|
||||
* @param permissions
|
||||
* The permissions to use to produce the returned model objects.
|
||||
*
|
||||
* @return
|
||||
* A collection of model objects which are based on the given
|
||||
* permissions and target user.
|
||||
*/
|
||||
protected Collection<ModelType> getModelInstances(ModeledUser targetUser,
|
||||
Collection<PermissionType> permissions) {
|
||||
|
||||
// Create new collection of models by manually converting each permission
|
||||
Collection<ModelType> models = new ArrayList<ModelType>(permissions.size());
|
||||
for (PermissionType permission : permissions)
|
||||
models.add(getModelInstance(targetUser, permission));
|
||||
|
||||
return models;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionType> retrievePermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException {
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser))
|
||||
return getPermissionInstances(getPermissionMapper().select(targetUser.getModel()));
|
||||
|
||||
// User cannot read this user's permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -23,12 +23,9 @@
|
||||
package org.glyptodon.guacamole.auth.jdbc.permission;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
|
||||
@@ -39,124 +36,8 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public abstract class ObjectPermissionService
|
||||
extends PermissionService<ObjectPermissionSet, ObjectPermission, ObjectPermissionModel> {
|
||||
|
||||
@Override
|
||||
protected abstract ObjectPermissionMapper getPermissionMapper();
|
||||
|
||||
@Override
|
||||
protected ObjectPermission getPermissionInstance(ObjectPermissionModel model) {
|
||||
return new ObjectPermission(model.getType(), model.getObjectIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectPermissionModel getModelInstance(ModeledUser targetUser,
|
||||
ObjectPermission permission) {
|
||||
|
||||
ObjectPermissionModel model = new ObjectPermissionModel();
|
||||
|
||||
// Populate model object with data from user and permission
|
||||
model.setUserID(targetUser.getModel().getObjectID());
|
||||
model.setUsername(targetUser.getModel().getIdentifier());
|
||||
model.setType(permission.getType());
|
||||
model.setObjectIdentifier(permission.getObjectIdentifier());
|
||||
|
||||
return model;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current user has permission to update the given
|
||||
* target user, adding or removing the given permissions. Such permission
|
||||
* depends on whether the current user is a system administrator, whether
|
||||
* they have explicit UPDATE permission on the target user, and whether
|
||||
* they have explicit ADMINISTER permission on all affected objects.
|
||||
*
|
||||
* @param user
|
||||
* The user who is changing permissions.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user whose permissions are being changed.
|
||||
*
|
||||
* @param permissions
|
||||
* The permissions that are being added or removed from the target
|
||||
* user.
|
||||
*
|
||||
* @return
|
||||
* true if the user has permission to change the target users
|
||||
* permissions as specified, false otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while checking permission status, or if
|
||||
* permission is denied to read the current user's permissions.
|
||||
*/
|
||||
protected boolean canAlterPermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// A system adminstrator can do anything
|
||||
if (user.getUser().isAdministrator())
|
||||
return true;
|
||||
|
||||
// Verify user has update permission on the target user
|
||||
ObjectPermissionSet userPermissionSet = user.getUser().getUserPermissions();
|
||||
if (!userPermissionSet.hasPermission(ObjectPermission.Type.UPDATE, targetUser.getIdentifier()))
|
||||
return false;
|
||||
|
||||
// Produce collection of affected identifiers
|
||||
Collection<String> affectedIdentifiers = new HashSet(permissions.size());
|
||||
for (ObjectPermission permission : permissions)
|
||||
affectedIdentifiers.add(permission.getObjectIdentifier());
|
||||
|
||||
// Determine subset of affected identifiers that we have admin access to
|
||||
ObjectPermissionSet affectedPermissionSet = getPermissionSet(user, user.getUser());
|
||||
Collection<String> allowedSubset = affectedPermissionSet.getAccessibleObjects(
|
||||
Collections.singleton(ObjectPermission.Type.ADMINISTER),
|
||||
affectedIdentifiers
|
||||
);
|
||||
|
||||
// The permissions can be altered if and only if the set of objects we
|
||||
// are allowed to administer is equal to the set of objects we will be
|
||||
// affecting.
|
||||
|
||||
return affectedIdentifiers.size() == allowedSubset.size();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Create permissions only if user has permission to do so
|
||||
if (canAlterPermissions(user, targetUser, permissions)) {
|
||||
Collection<ObjectPermissionModel> models = getModelInstances(targetUser, permissions);
|
||||
getPermissionMapper().insert(models);
|
||||
return;
|
||||
}
|
||||
|
||||
// User lacks permission to create object permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<ObjectPermission> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Delete permissions only if user has permission to do so
|
||||
if (canAlterPermissions(user, targetUser, permissions)) {
|
||||
Collection<ObjectPermissionModel> models = getModelInstances(targetUser, permissions);
|
||||
getPermissionMapper().delete(models);
|
||||
return;
|
||||
}
|
||||
|
||||
// User lacks permission to delete object permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
public interface ObjectPermissionService
|
||||
extends PermissionService<ObjectPermissionSet, ObjectPermission> {
|
||||
|
||||
/**
|
||||
* Retrieves the permission of the given type associated with the given
|
||||
@@ -181,26 +62,9 @@ public abstract class ObjectPermissionService
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while retrieving the requested permission.
|
||||
*/
|
||||
public ObjectPermission retrievePermission(AuthenticatedUser user,
|
||||
ObjectPermission retrievePermission(AuthenticatedUser user,
|
||||
ModeledUser targetUser, ObjectPermission.Type type,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser)) {
|
||||
|
||||
// Read permission from database, return null if not found
|
||||
ObjectPermissionModel model = getPermissionMapper().selectOne(targetUser.getModel(), type, identifier);
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return getPermissionInstance(model);
|
||||
|
||||
}
|
||||
|
||||
// User cannot read this user's permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
String identifier) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Retrieves the subset of the given identifiers for which the given user
|
||||
@@ -228,29 +92,8 @@ public abstract class ObjectPermissionService
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while retrieving permissions.
|
||||
*/
|
||||
public Collection<String> retrieveAccessibleIdentifiers(AuthenticatedUser user,
|
||||
Collection<String> retrieveAccessibleIdentifiers(AuthenticatedUser user,
|
||||
ModeledUser targetUser, Collection<ObjectPermission.Type> permissions,
|
||||
Collection<String> identifiers) throws GuacamoleException {
|
||||
|
||||
// Nothing is always accessible
|
||||
if (identifiers.isEmpty())
|
||||
return identifiers;
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser)) {
|
||||
|
||||
// If user is an admin, everything is accessible
|
||||
if (user.getUser().isAdministrator())
|
||||
return identifiers;
|
||||
|
||||
// Otherwise, return explicitly-retrievable identifiers
|
||||
return getPermissionMapper().selectAccessibleIdentifiers(targetUser.getModel(), permissions, identifiers);
|
||||
|
||||
}
|
||||
|
||||
// User cannot read this user's permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
Collection<String> identifiers) throws GuacamoleException;
|
||||
|
||||
}
|
||||
|
@@ -47,137 +47,9 @@ import org.glyptodon.guacamole.net.auth.permission.PermissionSet;
|
||||
*
|
||||
* @param <PermissionType>
|
||||
* The type of permission this service provides access to.
|
||||
*
|
||||
* @param <ModelType>
|
||||
* The underlying model object used to represent PermissionType in the
|
||||
* database.
|
||||
*/
|
||||
public abstract class PermissionService<PermissionSetType extends PermissionSet<PermissionType>,
|
||||
PermissionType extends Permission, ModelType> {
|
||||
|
||||
/**
|
||||
* Returns an instance of a mapper for the type of permission used by this
|
||||
* service.
|
||||
*
|
||||
* @return
|
||||
* A mapper which provides access to the model objects associated with
|
||||
* the permissions used by this service.
|
||||
*/
|
||||
protected abstract PermissionMapper<ModelType> getPermissionMapper();
|
||||
|
||||
/**
|
||||
* Returns an instance of a permission which is based on the given model
|
||||
* object.
|
||||
*
|
||||
* @param model
|
||||
* The model object to use to produce the returned permission.
|
||||
*
|
||||
* @return
|
||||
* A permission which is based on the given model object.
|
||||
*/
|
||||
protected abstract PermissionType getPermissionInstance(ModelType model);
|
||||
|
||||
/**
|
||||
* Returns a collection of permissions which are based on the models in
|
||||
* the given collection.
|
||||
*
|
||||
* @param models
|
||||
* The model objects to use to produce the permissions within the
|
||||
* returned set.
|
||||
*
|
||||
* @return
|
||||
* A set of permissions which are based on the models in the given
|
||||
* collection.
|
||||
*/
|
||||
protected Set<PermissionType> getPermissionInstances(Collection<ModelType> models) {
|
||||
|
||||
// Create new collection of permissions by manually converting each model
|
||||
Set<PermissionType> permissions = new HashSet<PermissionType>(models.size());
|
||||
for (ModelType model : models)
|
||||
permissions.add(getPermissionInstance(model));
|
||||
|
||||
return permissions;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a model object which is based on the given
|
||||
* permission and target user.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user to whom this permission is granted.
|
||||
*
|
||||
* @param permission
|
||||
* The permission to use to produce the returned model object.
|
||||
*
|
||||
* @return
|
||||
* A model object which is based on the given permission and target
|
||||
* user.
|
||||
*/
|
||||
protected abstract ModelType getModelInstance(ModeledUser targetUser,
|
||||
PermissionType permission);
|
||||
|
||||
/**
|
||||
* Returns a collection of model objects which are based on the given
|
||||
* permissions and target user.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user to whom this permission is granted.
|
||||
*
|
||||
* @param permissions
|
||||
* The permissions to use to produce the returned model objects.
|
||||
*
|
||||
* @return
|
||||
* A collection of model objects which are based on the given
|
||||
* permissions and target user.
|
||||
*/
|
||||
protected Collection<ModelType> getModelInstances(ModeledUser targetUser,
|
||||
Collection<PermissionType> permissions) {
|
||||
|
||||
// Create new collection of models by manually converting each permission
|
||||
Collection<ModelType> models = new ArrayList<ModelType>(permissions.size());
|
||||
for (PermissionType permission : permissions)
|
||||
models.add(getModelInstance(targetUser, permission));
|
||||
|
||||
return models;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given user can read the permissions currently
|
||||
* granted to the given target user. If the reading user and the target
|
||||
* user are not the same, then explicit READ or SYSTEM_ADMINISTER access is
|
||||
* required.
|
||||
*
|
||||
* @param user
|
||||
* The user attempting to read permissions.
|
||||
*
|
||||
* @param targetUser
|
||||
* The user whose permissions are being read.
|
||||
*
|
||||
* @return
|
||||
* true if permission is granted, false otherwise.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while checking permission status, or if
|
||||
* permission is denied to read the current user's permissions.
|
||||
*/
|
||||
protected boolean canReadPermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException {
|
||||
|
||||
// A user can always read their own permissions
|
||||
if (user.getUser().getIdentifier().equals(targetUser.getIdentifier()))
|
||||
return true;
|
||||
|
||||
// A system adminstrator can do anything
|
||||
if (user.getUser().isAdministrator())
|
||||
return true;
|
||||
|
||||
// Can read permissions on target user if explicit READ is granted
|
||||
ObjectPermissionSet userPermissionSet = user.getUser().getUserPermissions();
|
||||
return userPermissionSet.hasPermission(ObjectPermission.Type.READ, targetUser.getIdentifier());
|
||||
|
||||
}
|
||||
public interface PermissionService<PermissionSetType extends PermissionSet<PermissionType>,
|
||||
PermissionType extends Permission> {
|
||||
|
||||
/**
|
||||
* Returns a permission set that can be used to retrieve and manipulate the
|
||||
@@ -200,7 +72,7 @@ public abstract class PermissionService<PermissionSetType extends PermissionSet<
|
||||
* user, or if permission to retrieve the permissions of the given
|
||||
* user is denied.
|
||||
*/
|
||||
public abstract PermissionSetType getPermissionSet(AuthenticatedUser user,
|
||||
PermissionSetType getPermissionSet(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
@@ -218,17 +90,8 @@ public abstract class PermissionService<PermissionSetType extends PermissionSet<
|
||||
* @throws GuacamoleException
|
||||
* If an error occurs while retrieving the requested permissions.
|
||||
*/
|
||||
public Set<PermissionType> retrievePermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException {
|
||||
|
||||
// Retrieve permissions only if allowed
|
||||
if (canReadPermissions(user, targetUser))
|
||||
return getPermissionInstances(getPermissionMapper().select(targetUser.getModel()));
|
||||
|
||||
// User cannot read this user's permissions
|
||||
throw new GuacamoleSecurityException("Permission denied.");
|
||||
|
||||
}
|
||||
Set<PermissionType> retrievePermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Creates the given permissions within the database. If any permissions
|
||||
@@ -247,8 +110,7 @@ public abstract class PermissionService<PermissionSetType extends PermissionSet<
|
||||
* If the user lacks permission to create the permissions, or an error
|
||||
* occurs while creating the permissions.
|
||||
*/
|
||||
public abstract void createPermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser,
|
||||
void createPermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<PermissionType> permissions) throws GuacamoleException;
|
||||
|
||||
/**
|
||||
@@ -268,8 +130,7 @@ public abstract class PermissionService<PermissionSetType extends PermissionSet<
|
||||
* If the user lacks permission to delete the permissions, or an error
|
||||
* occurs while deleting the permissions.
|
||||
*/
|
||||
public abstract void deletePermissions(AuthenticatedUser user,
|
||||
ModeledUser targetUser,
|
||||
void deletePermissions(AuthenticatedUser user, ModeledUser targetUser,
|
||||
Collection<PermissionType> permissions) throws GuacamoleException;
|
||||
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ import org.glyptodon.guacamole.net.auth.permission.SystemPermission;
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class SystemPermissionService
|
||||
extends PermissionService<SystemPermissionSet, SystemPermission, SystemPermissionModel> {
|
||||
extends ModeledPermissionService<SystemPermissionSet, SystemPermission, SystemPermissionModel> {
|
||||
|
||||
/**
|
||||
* Mapper for system-level permissions.
|
||||
|
@@ -35,7 +35,7 @@ import org.glyptodon.guacamole.auth.jdbc.user.ModeledUser;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class UserPermissionService extends ObjectPermissionService {
|
||||
public class UserPermissionService extends ModeledObjectPermissionService {
|
||||
|
||||
/**
|
||||
* Mapper for user permissions.
|
||||
|
@@ -49,7 +49,6 @@ import org.glyptodon.guacamole.net.GuacamoleSocket;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
|
||||
@@ -100,8 +99,8 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
|
||||
/**
|
||||
* All active connections through the tunnel having a given UUID.
|
||||
*/
|
||||
private final Map<String, ConnectionRecord> activeTunnels =
|
||||
new ConcurrentHashMap<String, ConnectionRecord>();
|
||||
private final Map<String, ActiveConnectionRecord> activeTunnels =
|
||||
new ConcurrentHashMap<String, ActiveConnectionRecord>();
|
||||
|
||||
/**
|
||||
* All active connections to a connection having a given identifier.
|
||||
@@ -446,7 +445,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConnectionRecord> getActiveConnections(AuthenticatedUser user)
|
||||
public Collection<ActiveConnectionRecord> getActiveConnections(AuthenticatedUser user)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Only administrators may see all active connections
|
||||
@@ -458,7 +457,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionRecord getActiveConnection(AuthenticatedUser user,
|
||||
public ActiveConnectionRecord getActiveConnection(AuthenticatedUser user,
|
||||
String tunnelUUID) throws GuacamoleException {
|
||||
|
||||
// Only administrators may see all active connections
|
||||
@@ -482,7 +481,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConnectionRecord> getActiveConnections(Connection connection) {
|
||||
public Collection<ActiveConnectionRecord> getActiveConnections(Connection connection) {
|
||||
return activeConnections.get(connection.getIdentifier());
|
||||
}
|
||||
|
||||
@@ -507,7 +506,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup) {
|
||||
public Collection<ActiveConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup) {
|
||||
|
||||
// If not a balancing group, assume no connections
|
||||
if (connectionGroup.getType() != ConnectionGroup.Type.BALANCING)
|
||||
|
@@ -28,8 +28,6 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
|
||||
|
||||
/**
|
||||
* Mapping of object identifiers to lists of connection records. Records are
|
||||
@@ -44,8 +42,8 @@ public class ActiveConnectionMultimap {
|
||||
/**
|
||||
* All active connections to a connection having a given identifier.
|
||||
*/
|
||||
private final Map<String, Set<ConnectionRecord>> records =
|
||||
new HashMap<String, Set<ConnectionRecord>>();
|
||||
private final Map<String, Set<ActiveConnectionRecord>> records =
|
||||
new HashMap<String, Set<ActiveConnectionRecord>>();
|
||||
|
||||
/**
|
||||
* Stores the given connection record in the list of active connections
|
||||
@@ -57,13 +55,13 @@ public class ActiveConnectionMultimap {
|
||||
* @param record
|
||||
* The record associated with the active connection.
|
||||
*/
|
||||
public void put(String identifier, ConnectionRecord record) {
|
||||
public void put(String identifier, ActiveConnectionRecord record) {
|
||||
synchronized (records) {
|
||||
|
||||
// Get set of active connection records, creating if necessary
|
||||
Set<ConnectionRecord> connections = records.get(identifier);
|
||||
Set<ActiveConnectionRecord> connections = records.get(identifier);
|
||||
if (connections == null) {
|
||||
connections = Collections.synchronizedSet(Collections.newSetFromMap(new LinkedHashMap<ConnectionRecord, Boolean>()));
|
||||
connections = Collections.synchronizedSet(Collections.newSetFromMap(new LinkedHashMap<ActiveConnectionRecord, Boolean>()));
|
||||
records.put(identifier, connections);
|
||||
}
|
||||
|
||||
@@ -83,11 +81,11 @@ public class ActiveConnectionMultimap {
|
||||
* @param record
|
||||
* The record associated with the active connection.
|
||||
*/
|
||||
public void remove(String identifier, ConnectionRecord record) {
|
||||
public void remove(String identifier, ActiveConnectionRecord record) {
|
||||
synchronized (records) {
|
||||
|
||||
// Get set of active connection records
|
||||
Set<ConnectionRecord> connections = records.get(identifier);
|
||||
Set<ActiveConnectionRecord> connections = records.get(identifier);
|
||||
assert(connections != null);
|
||||
|
||||
// Remove old record
|
||||
@@ -114,11 +112,11 @@ public class ActiveConnectionMultimap {
|
||||
* the given identifier, or an empty collection if there are no such
|
||||
* records.
|
||||
*/
|
||||
public Collection<ConnectionRecord> get(String identifier) {
|
||||
public Collection<ActiveConnectionRecord> get(String identifier) {
|
||||
synchronized (records) {
|
||||
|
||||
// Get set of active connection records
|
||||
Collection<ConnectionRecord> connections = records.get(identifier);
|
||||
Collection<ActiveConnectionRecord> connections = records.get(identifier);
|
||||
if (connections != null)
|
||||
return Collections.unmodifiableCollection(connections);
|
||||
|
||||
|
@@ -164,11 +164,6 @@ public class ActiveConnectionRecord implements ConnectionRecord {
|
||||
return balancingGroup != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return connection.getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
@@ -200,7 +195,14 @@ public class ActiveConnectionRecord implements ConnectionRecord {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Returns the GuacamoleTunnel currently associated with the active
|
||||
* connection represented by this connection record.
|
||||
*
|
||||
* @return
|
||||
* The GuacamoleTunnel currently associated with the active connection
|
||||
* represented by this connection record.
|
||||
*/
|
||||
public GuacamoleTunnel getTunnel() {
|
||||
return tunnel;
|
||||
}
|
||||
|
@@ -30,7 +30,6 @@ import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
||||
|
||||
|
||||
@@ -57,7 +56,7 @@ public interface GuacamoleTunnelService {
|
||||
* If an error occurs while retrieving all active connections, or if
|
||||
* permission is denied.
|
||||
*/
|
||||
public Collection<ConnectionRecord> getActiveConnections(AuthenticatedUser user)
|
||||
public Collection<ActiveConnectionRecord> getActiveConnections(AuthenticatedUser user)
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
@@ -80,7 +79,7 @@ public interface GuacamoleTunnelService {
|
||||
* If an error occurs while retrieving all active connections, or if
|
||||
* permission is denied.
|
||||
*/
|
||||
public ConnectionRecord getActiveConnection(AuthenticatedUser user,
|
||||
public ActiveConnectionRecord getActiveConnection(AuthenticatedUser user,
|
||||
String tunnelUUID)
|
||||
throws GuacamoleException;
|
||||
|
||||
@@ -114,7 +113,7 @@ public interface GuacamoleTunnelService {
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a connection containing connection records representing all
|
||||
* Returns a collection containing connection records representing all
|
||||
* currently-active connections using the given connection. These records
|
||||
* will have usernames and start dates, but no end date, and will be
|
||||
* sorted in ascending order by start date.
|
||||
@@ -126,7 +125,7 @@ public interface GuacamoleTunnelService {
|
||||
* A collection containing connection records representing all
|
||||
* currently-active connections.
|
||||
*/
|
||||
public Collection<ConnectionRecord> getActiveConnections(Connection connection);
|
||||
public Collection<ActiveConnectionRecord> getActiveConnections(Connection connection);
|
||||
|
||||
/**
|
||||
* Creates a socket for the given user which connects to the given
|
||||
@@ -171,6 +170,6 @@ public interface GuacamoleTunnelService {
|
||||
* A collection containing connection records representing all
|
||||
* currently-active connections.
|
||||
*/
|
||||
public Collection<ConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup);
|
||||
public Collection<ActiveConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup);
|
||||
|
||||
}
|
||||
|
@@ -23,11 +23,12 @@
|
||||
package org.glyptodon.guacamole.auth.jdbc.user;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.security.PasswordEncryptionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.security.SaltService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.SystemPermissionService;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ConnectionGroupPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ConnectionPermissionService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.UserPermissionService;
|
||||
@@ -42,7 +43,7 @@ import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet;
|
||||
* @author James Muehlner
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class ModeledUser extends DirectoryObject<UserModel> implements User {
|
||||
public class ModeledUser extends ModeledDirectoryObject<UserModel> implements User {
|
||||
|
||||
/**
|
||||
* Service for hashing passwords.
|
||||
@@ -73,7 +74,13 @@ public class ModeledUser extends DirectoryObject<UserModel> implements User {
|
||||
*/
|
||||
@Inject
|
||||
private ConnectionGroupPermissionService connectionGroupPermissionService;
|
||||
|
||||
|
||||
/**
|
||||
* Service for retrieving active connection permissions.
|
||||
*/
|
||||
@Inject
|
||||
private ActiveConnectionPermissionService activeConnectionPermissionService;
|
||||
|
||||
/**
|
||||
* Service for retrieving user permissions.
|
||||
*/
|
||||
@@ -160,6 +167,12 @@ public class ModeledUser extends DirectoryObject<UserModel> implements User {
|
||||
return connectionGroupPermissionService.getPermissionSet(getCurrentUser(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPermissionSet getActiveConnectionPermissions()
|
||||
throws GuacamoleException {
|
||||
return activeConnectionPermissionService.getPermissionSet(getCurrentUser(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPermissionSet getUserPermissions()
|
||||
throws GuacamoleException {
|
||||
|
@@ -28,14 +28,12 @@ import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ConnectionGroupDirector
|
||||
import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionDirectory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
|
||||
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionDirectory;
|
||||
import org.glyptodon.guacamole.net.auth.ActiveConnection;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
import org.glyptodon.guacamole.net.auth.Directory;
|
||||
import org.glyptodon.guacamole.net.auth.User;
|
||||
|
||||
@@ -49,12 +47,6 @@ import org.glyptodon.guacamole.net.auth.User;
|
||||
public class UserContext extends RestrictedObject
|
||||
implements org.glyptodon.guacamole.net.auth.UserContext {
|
||||
|
||||
/**
|
||||
* Service for creating and tracking tunnels.
|
||||
*/
|
||||
@Inject
|
||||
private GuacamoleTunnelService tunnelService;
|
||||
|
||||
/**
|
||||
* User directory restricted by the permissions of the user associated
|
||||
* with this context.
|
||||
@@ -76,6 +68,13 @@ public class UserContext extends RestrictedObject
|
||||
@Inject
|
||||
private ConnectionGroupDirectory connectionGroupDirectory;
|
||||
|
||||
/**
|
||||
* ActiveConnection directory restricted by the permissions of the user
|
||||
* associated with this context.
|
||||
*/
|
||||
@Inject
|
||||
private ActiveConnectionDirectory activeConnectionDirectory;
|
||||
|
||||
/**
|
||||
* Provider for creating the root group.
|
||||
*/
|
||||
@@ -91,6 +90,7 @@ public class UserContext extends RestrictedObject
|
||||
userDirectory.init(currentUser);
|
||||
connectionDirectory.init(currentUser);
|
||||
connectionGroupDirectory.init(currentUser);
|
||||
activeConnectionDirectory.init(currentUser);
|
||||
|
||||
}
|
||||
|
||||
@@ -114,6 +114,12 @@ public class UserContext extends RestrictedObject
|
||||
return connectionGroupDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Directory<ActiveConnection> getActiveConnectionDirectory()
|
||||
throws GuacamoleException {
|
||||
return activeConnectionDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionGroup getRootConnectionGroup() throws GuacamoleException {
|
||||
|
||||
@@ -124,29 +130,4 @@ public class UserContext extends RestrictedObject
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConnectionRecord> getActiveConnections()
|
||||
throws GuacamoleException {
|
||||
return tunnelService.getActiveConnections(getCurrentUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUIDs)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Look up active connections for each given tunnel UUID
|
||||
Collection<ConnectionRecord> records = new ArrayList<ConnectionRecord>(tunnelUUIDs.size());
|
||||
for (String tunnelUUID : tunnelUUIDs) {
|
||||
|
||||
// Add corresponding record only if it exists
|
||||
ConnectionRecord record = tunnelService.getActiveConnection(getCurrentUser(), tunnelUUID);
|
||||
if (record != null)
|
||||
records.add(record);
|
||||
|
||||
}
|
||||
|
||||
return records;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
package org.glyptodon.guacamole.auth.jdbc.user;
|
||||
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public interface UserMapper extends DirectoryObjectMapper<UserModel> {
|
||||
public interface UserMapper extends ModeledDirectoryObjectMapper<UserModel> {
|
||||
|
||||
/**
|
||||
* Returns the user having the given username, if any. If no such user
|
||||
|
@@ -28,8 +28,8 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import org.glyptodon.guacamole.net.auth.Credentials;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectService;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.base.ModeledDirectoryObjectService;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
|
||||
@@ -49,7 +49,7 @@ import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet;
|
||||
*
|
||||
* @author Michael Jumper, James Muehlner
|
||||
*/
|
||||
public class UserService extends DirectoryObjectService<ModeledUser, User, UserModel> {
|
||||
public class UserService extends ModeledDirectoryObjectService<ModeledUser, User, UserModel> {
|
||||
|
||||
/**
|
||||
* All user permissions which are implicitly granted to the new user upon
|
||||
@@ -85,7 +85,7 @@ public class UserService extends DirectoryObjectService<ModeledUser, User, UserM
|
||||
private PasswordEncryptionService encryptionService;
|
||||
|
||||
@Override
|
||||
protected DirectoryObjectMapper<UserModel> getObjectMapper() {
|
||||
protected ModeledDirectoryObjectMapper<UserModel> getObjectMapper() {
|
||||
return userMapper;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user