GUAC-1101: Move tracking of current user into RestrictedObject.

This commit is contained in:
Michael Jumper
2015-02-28 14:27:27 -08:00
parent 68fd8e225c
commit 03633fb902
10 changed files with 140 additions and 175 deletions

View File

@@ -34,7 +34,7 @@ import org.glyptodon.guacamole.net.auth.Identifiable;
* The type of model object that corresponds to this object. * The type of model object that corresponds to this object.
*/ */
public abstract class DirectoryObject<ModelType extends ObjectModel> public abstract class DirectoryObject<ModelType extends ObjectModel>
extends RestrictedObject<ModelType> implements Identifiable { extends ModeledObject<ModelType> implements Identifiable {
@Override @Override
public String getIdentifier() { public String getIdentifier() {

View File

@@ -0,0 +1,82 @@
/*
* 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.base;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
/**
* Common base class for objects have an underlying model. For the purposes of
* JDBC-driven authentication providers, all modeled objects are also
* restricted.
*
* @author Michael Jumper
* @param <ModelType>
* The type of model object which corresponds to this object.
*/
public abstract class ModeledObject<ModelType> extends RestrictedObject {
/**
* The internal model object containing the values which represent this
* object in the database.
*/
private ModelType model;
/**
* Initializes this object, associating it with the current authenticated
* user and populating it with data from the given model object
*
* @param currentUser
* The user that created or retrieved this object.
*
* @param model
* The backing model object.
*/
public void init(AuthenticatedUser currentUser, ModelType model) {
super.init(currentUser);
setModel(model);
}
/**
* Returns the backing model object. Changes to the model object will
* affect this object, and changes to this object will affect the model
* object.
*
* @return
* The backing model object.
*/
public ModelType getModel() {
return model;
}
/**
* Sets the backing model object. This will effectively replace all data
* contained within this object.
*
* @param model
* The backing model object.
*/
public void setModel(ModelType model) {
this.model = model;
}
}

View File

@@ -26,13 +26,11 @@ import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
/** /**
* Common base class for objects that are associated with the users that * Common base class for objects that are associated with the users that
* query them, and have an underlying model. * obtain them.
* *
* @author Michael Jumper * @author Michael Jumper
* @param <ModelType>
* The type of model object which corresponds to this object.
*/ */
public abstract class RestrictedObject<ModelType> { public abstract class RestrictedObject {
/** /**
* The user this object belongs to. Access is based on his/her permission * The user this object belongs to. Access is based on his/her permission
@@ -40,25 +38,15 @@ public abstract class RestrictedObject<ModelType> {
*/ */
private AuthenticatedUser currentUser; private AuthenticatedUser currentUser;
/**
* The internal model object containing the values which represent this
* object in the database.
*/
private ModelType model;
/** /**
* Initializes this object, associating it with the current authenticated * Initializes this object, associating it with the current authenticated
* user and populating it with data from the given model object * user and populating it with data from the given model object
* *
* @param currentUser * @param currentUser
* The user that created or retrieved this object. * The user that created or retrieved this object.
*
* @param model
* The backing model object.
*/ */
public void init(AuthenticatedUser currentUser, ModelType model) { public void init(AuthenticatedUser currentUser) {
setCurrentUser(currentUser); setCurrentUser(currentUser);
setModel(model);
} }
/** /**
@@ -85,27 +73,4 @@ public abstract class RestrictedObject<ModelType> {
this.currentUser = currentUser; this.currentUser = currentUser;
} }
/**
* Returns the backing model object. Changes to the model object will
* affect this object, and changes to this object will affect the model
* object.
*
* @return
* The backing model object.
*/
public ModelType getModel() {
return model;
}
/**
* Sets the backing model object. This will effectively replace all data
* contained within this object.
*
* @param model
* The backing model object.
*/
public void setModel(ModelType model) {
this.model = model;
}
} }

View File

@@ -27,8 +27,8 @@ import com.google.inject.Inject;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
import org.mybatis.guice.transactional.Transactional; import org.mybatis.guice.transactional.Transactional;
@@ -40,13 +40,8 @@ import org.mybatis.guice.transactional.Transactional;
* @author James Muehlner * @author James Muehlner
* @author Michael Jumper * @author Michael Jumper
*/ */
public class ConnectionDirectory implements Directory<Connection> { public class ConnectionDirectory extends RestrictedObject
implements Directory<Connection> {
/**
* The user this connection directory belongs to. Access is based on
* his/her permission settings.
*/
private AuthenticatedUser currentUser;
/** /**
* Service for managing connection objects. * Service for managing connection objects.
@@ -54,52 +49,41 @@ public class ConnectionDirectory implements Directory<Connection> {
@Inject @Inject
private ConnectionService connectionService; private ConnectionService connectionService;
/**
* Set the user for this directory.
*
* @param currentUser
* The user whose permissions define the visibility of connections in
* this directory.
*/
public void init(AuthenticatedUser currentUser) {
this.currentUser = currentUser;
}
@Override @Override
public Connection get(String identifier) throws GuacamoleException { public Connection get(String identifier) throws GuacamoleException {
return connectionService.retrieveObject(currentUser, identifier); return connectionService.retrieveObject(getCurrentUser(), identifier);
} }
@Override @Override
@Transactional @Transactional
public Collection<Connection> getAll(Collection<String> identifiers) throws GuacamoleException { public Collection<Connection> getAll(Collection<String> identifiers) throws GuacamoleException {
Collection<ModeledConnection> objects = connectionService.retrieveObjects(currentUser, identifiers); Collection<ModeledConnection> objects = connectionService.retrieveObjects(getCurrentUser(), identifiers);
return Collections.<Connection>unmodifiableCollection(objects); return Collections.<Connection>unmodifiableCollection(objects);
} }
@Override @Override
@Transactional @Transactional
public Set<String> getIdentifiers() throws GuacamoleException { public Set<String> getIdentifiers() throws GuacamoleException {
return connectionService.getIdentifiers(currentUser); return connectionService.getIdentifiers(getCurrentUser());
} }
@Override @Override
@Transactional @Transactional
public void add(Connection object) throws GuacamoleException { public void add(Connection object) throws GuacamoleException {
connectionService.createObject(currentUser, object); connectionService.createObject(getCurrentUser(), object);
} }
@Override @Override
@Transactional @Transactional
public void update(Connection object) throws GuacamoleException { public void update(Connection object) throws GuacamoleException {
ModeledConnection connection = (ModeledConnection) object; ModeledConnection connection = (ModeledConnection) object;
connectionService.updateObject(currentUser, connection); connectionService.updateObject(getCurrentUser(), connection);
} }
@Override @Override
@Transactional @Transactional
public void remove(String identifier) throws GuacamoleException { public void remove(String identifier) throws GuacamoleException {
connectionService.deleteObject(currentUser, identifier); connectionService.deleteObject(getCurrentUser(), identifier);
} }
} }

View File

@@ -27,8 +27,8 @@ import com.google.inject.Inject;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
import org.mybatis.guice.transactional.Transactional; import org.mybatis.guice.transactional.Transactional;
@@ -40,13 +40,8 @@ import org.mybatis.guice.transactional.Transactional;
* @author James Muehlner * @author James Muehlner
* @author Michael Jumper * @author Michael Jumper
*/ */
public class ConnectionGroupDirectory implements Directory<ConnectionGroup> { public class ConnectionGroupDirectory extends RestrictedObject
implements Directory<ConnectionGroup> {
/**
* The user this connection group directory belongs to. Access is based on
* his/her permission settings.
*/
private AuthenticatedUser currentUser;
/** /**
* Service for managing connection group objects. * Service for managing connection group objects.
@@ -54,52 +49,41 @@ public class ConnectionGroupDirectory implements Directory<ConnectionGroup> {
@Inject @Inject
private ConnectionGroupService connectionGroupService; private ConnectionGroupService connectionGroupService;
/**
* Set the user for this directory.
*
* @param currentUser
* The user whose permissions define the visibility of connection
* groups in this directory.
*/
public void init(AuthenticatedUser currentUser) {
this.currentUser = currentUser;
}
@Override @Override
public ConnectionGroup get(String identifier) throws GuacamoleException { public ConnectionGroup get(String identifier) throws GuacamoleException {
return connectionGroupService.retrieveObject(currentUser, identifier); return connectionGroupService.retrieveObject(getCurrentUser(), identifier);
} }
@Override @Override
@Transactional @Transactional
public Collection<ConnectionGroup> getAll(Collection<String> identifiers) throws GuacamoleException { public Collection<ConnectionGroup> getAll(Collection<String> identifiers) throws GuacamoleException {
Collection<ModeledConnectionGroup> objects = connectionGroupService.retrieveObjects(currentUser, identifiers); Collection<ModeledConnectionGroup> objects = connectionGroupService.retrieveObjects(getCurrentUser(), identifiers);
return Collections.<ConnectionGroup>unmodifiableCollection(objects); return Collections.<ConnectionGroup>unmodifiableCollection(objects);
} }
@Override @Override
@Transactional @Transactional
public Set<String> getIdentifiers() throws GuacamoleException { public Set<String> getIdentifiers() throws GuacamoleException {
return connectionGroupService.getIdentifiers(currentUser); return connectionGroupService.getIdentifiers(getCurrentUser());
} }
@Override @Override
@Transactional @Transactional
public void add(ConnectionGroup object) throws GuacamoleException { public void add(ConnectionGroup object) throws GuacamoleException {
connectionGroupService.createObject(currentUser, object); connectionGroupService.createObject(getCurrentUser(), object);
} }
@Override @Override
@Transactional @Transactional
public void update(ConnectionGroup object) throws GuacamoleException { public void update(ConnectionGroup object) throws GuacamoleException {
ModeledConnectionGroup connectionGroup = (ModeledConnectionGroup) object; ModeledConnectionGroup connectionGroup = (ModeledConnectionGroup) object;
connectionGroupService.updateObject(currentUser, connectionGroup); connectionGroupService.updateObject(getCurrentUser(), connectionGroup);
} }
@Override @Override
@Transactional @Transactional
public void remove(String identifier) throws GuacamoleException { public void remove(String identifier) throws GuacamoleException {
connectionGroupService.deleteObject(currentUser, identifier); connectionGroupService.deleteObject(getCurrentUser(), identifier);
} }
} }

View File

@@ -24,10 +24,10 @@ package org.glyptodon.guacamole.auth.jdbc.connectiongroup;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionService; import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionService;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleSecurityException; import org.glyptodon.guacamole.GuacamoleSecurityException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.GuacamoleSocket; import org.glyptodon.guacamole.net.GuacamoleSocket;
import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
@@ -38,7 +38,8 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
public class RootConnectionGroup implements ConnectionGroup { public class RootConnectionGroup extends RestrictedObject
implements ConnectionGroup {
/** /**
* The identifier used to represent the root connection group. There is no * The identifier used to represent the root connection group. There is no
@@ -54,12 +55,6 @@ public class RootConnectionGroup implements ConnectionGroup {
*/ */
public static final String NAME = "ROOT"; public static final String NAME = "ROOT";
/**
* The user this group belongs to. Access is based on his/her permission
* settings.
*/
private AuthenticatedUser currentUser;
/** /**
* Service for managing connection objects. * Service for managing connection objects.
*/ */
@@ -78,17 +73,6 @@ public class RootConnectionGroup implements ConnectionGroup {
public RootConnectionGroup() { public RootConnectionGroup() {
} }
/**
* Initializes this root connection group, associating it with the current
* authenticated user.
*
* @param currentUser
* The user that created or retrieved this object.
*/
public void init(AuthenticatedUser currentUser) {
this.currentUser = currentUser;
}
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;
@@ -121,13 +105,13 @@ public class RootConnectionGroup implements ConnectionGroup {
@Override @Override
public Set<String> getConnectionIdentifiers() throws GuacamoleException { public Set<String> getConnectionIdentifiers() throws GuacamoleException {
return connectionService.getIdentifiersWithin(currentUser, null); return connectionService.getIdentifiersWithin(getCurrentUser(), null);
} }
@Override @Override
public Set<String> getConnectionGroupIdentifiers() public Set<String> getConnectionGroupIdentifiers()
throws GuacamoleException { throws GuacamoleException {
return connectionGroupService.getIdentifiersWithin(currentUser, null); return connectionGroupService.getIdentifiersWithin(getCurrentUser(), null);
} }
@Override @Override

View File

@@ -28,6 +28,7 @@ import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser; import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
/** /**
@@ -37,15 +38,9 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
public abstract class ObjectPermissionSet public abstract class ObjectPermissionSet extends RestrictedObject
implements org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet { implements org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet {
/**
* The user that queried this permission set. Access is based on his/her
* permission settings.
*/
private AuthenticatedUser currentUser;
/** /**
* The user associated with this permission set. Each of the permissions in * The user associated with this permission set. Each of the permissions in
* this permission set is granted to this user. * this permission set is granted to this user.
@@ -72,7 +67,7 @@ public abstract class ObjectPermissionSet
* The user to whom the permissions in this set are granted. * The user to whom the permissions in this set are granted.
*/ */
public void init(AuthenticatedUser currentUser, ModeledUser user) { public void init(AuthenticatedUser currentUser, ModeledUser user) {
this.currentUser = currentUser; super.init(currentUser);
this.user = user; this.user = user;
} }
@@ -88,13 +83,13 @@ public abstract class ObjectPermissionSet
@Override @Override
public Set<ObjectPermission> getPermissions() throws GuacamoleException { public Set<ObjectPermission> getPermissions() throws GuacamoleException {
return getObjectPermissionService().retrievePermissions(currentUser, user); return getObjectPermissionService().retrievePermissions(getCurrentUser(), user);
} }
@Override @Override
public boolean hasPermission(ObjectPermission.Type permission, public boolean hasPermission(ObjectPermission.Type permission,
String identifier) throws GuacamoleException { String identifier) throws GuacamoleException {
return getObjectPermissionService().retrievePermission(currentUser, user, permission, identifier) != null; return getObjectPermissionService().retrievePermission(getCurrentUser(), user, permission, identifier) != null;
} }
@Override @Override
@@ -118,13 +113,13 @@ public abstract class ObjectPermissionSet
@Override @Override
public void addPermissions(Set<ObjectPermission> permissions) public void addPermissions(Set<ObjectPermission> permissions)
throws GuacamoleException { throws GuacamoleException {
getObjectPermissionService().createPermissions(currentUser, user, permissions); getObjectPermissionService().createPermissions(getCurrentUser(), user, permissions);
} }
@Override @Override
public void removePermissions(Set<ObjectPermission> permissions) public void removePermissions(Set<ObjectPermission> permissions)
throws GuacamoleException { throws GuacamoleException {
getObjectPermissionService().deletePermissions(currentUser, user, permissions); getObjectPermissionService().deletePermissions(getCurrentUser(), user, permissions);
} }
} }

View File

@@ -28,6 +28,7 @@ import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser; import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.auth.permission.SystemPermission; import org.glyptodon.guacamole.net.auth.permission.SystemPermission;
/** /**
@@ -37,15 +38,9 @@ import org.glyptodon.guacamole.net.auth.permission.SystemPermission;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
public class SystemPermissionSet public class SystemPermissionSet extends RestrictedObject
implements org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet { implements org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet {
/**
* The user that queried this permission set. Access is based on his/her
* permission settings.
*/
private AuthenticatedUser currentUser;
/** /**
* The user associated with this permission set. Each of the permissions in * The user associated with this permission set. Each of the permissions in
* this permission set is granted to this user. * this permission set is granted to this user.
@@ -78,19 +73,19 @@ public class SystemPermissionSet
* The user to whom the permissions in this set are granted. * The user to whom the permissions in this set are granted.
*/ */
public void init(AuthenticatedUser currentUser, ModeledUser user) { public void init(AuthenticatedUser currentUser, ModeledUser user) {
this.currentUser = currentUser; super.init(currentUser);
this.user = user; this.user = user;
} }
@Override @Override
public Set<SystemPermission> getPermissions() throws GuacamoleException { public Set<SystemPermission> getPermissions() throws GuacamoleException {
return systemPermissionService.retrievePermissions(currentUser, user); return systemPermissionService.retrievePermissions(getCurrentUser(), user);
} }
@Override @Override
public boolean hasPermission(SystemPermission.Type permission) public boolean hasPermission(SystemPermission.Type permission)
throws GuacamoleException { throws GuacamoleException {
return systemPermissionService.retrievePermission(currentUser, user, permission) != null; return systemPermissionService.retrievePermission(getCurrentUser(), user, permission) != null;
} }
@Override @Override
@@ -108,13 +103,13 @@ public class SystemPermissionSet
@Override @Override
public void addPermissions(Set<SystemPermission> permissions) public void addPermissions(Set<SystemPermission> permissions)
throws GuacamoleException { throws GuacamoleException {
systemPermissionService.createPermissions(currentUser, user, permissions); systemPermissionService.createPermissions(getCurrentUser(), user, permissions);
} }
@Override @Override
public void removePermissions(Set<SystemPermission> permissions) public void removePermissions(Set<SystemPermission> permissions)
throws GuacamoleException { throws GuacamoleException {
systemPermissionService.deletePermissions(currentUser, user, permissions); systemPermissionService.deletePermissions(getCurrentUser(), user, permissions);
} }
} }

View File

@@ -29,6 +29,7 @@ import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionDirectory;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
@@ -41,14 +42,9 @@ import org.glyptodon.guacamole.net.auth.User;
* @author James Muehlner * @author James Muehlner
* @author Michael Jumper * @author Michael Jumper
*/ */
public class UserContext public class UserContext extends RestrictedObject
implements org.glyptodon.guacamole.net.auth.UserContext { implements org.glyptodon.guacamole.net.auth.UserContext {
/**
* The the user owning this context.
*/
private AuthenticatedUser currentUser;
/** /**
* User directory restricted by the permissions of the user associated * User directory restricted by the permissions of the user associated
* with this context. * with this context.
@@ -76,15 +72,10 @@ public class UserContext
@Inject @Inject
private Provider<RootConnectionGroup> rootGroupProvider; private Provider<RootConnectionGroup> rootGroupProvider;
/** @Override
* Initializes the user and directories associated with this context.
*
* @param currentUser
* The user owning this context.
*/
public void init(AuthenticatedUser currentUser) { public void init(AuthenticatedUser currentUser) {
this.currentUser = currentUser; super.init(currentUser);
// Init directories // Init directories
userDirectory.init(currentUser); userDirectory.init(currentUser);
@@ -95,7 +86,7 @@ public class UserContext
@Override @Override
public User self() { public User self() {
return currentUser.getUser(); return getCurrentUser().getUser();
} }
@Override @Override
@@ -118,7 +109,7 @@ public class UserContext
// Build and return a root group for the current user // Build and return a root group for the current user
RootConnectionGroup rootGroup = rootGroupProvider.get(); RootConnectionGroup rootGroup = rootGroupProvider.get();
rootGroup.init(currentUser); rootGroup.init(getCurrentUser());
return rootGroup; return rootGroup;
} }

View File

@@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
import org.glyptodon.guacamole.net.auth.User; import org.glyptodon.guacamole.net.auth.User;
import org.mybatis.guice.transactional.Transactional; import org.mybatis.guice.transactional.Transactional;
@@ -39,13 +40,8 @@ import org.mybatis.guice.transactional.Transactional;
* @author James Muehlner * @author James Muehlner
* @author Michael Jumper * @author Michael Jumper
*/ */
public class UserDirectory implements Directory<User> { public class UserDirectory extends RestrictedObject
implements Directory<User> {
/**
* The user this user directory belongs to. Access is based on his/her
* permission settings.
*/
private AuthenticatedUser currentUser;
/** /**
* Service for managing user objects. * Service for managing user objects.
@@ -53,52 +49,41 @@ public class UserDirectory implements Directory<User> {
@Inject @Inject
private UserService userService; private UserService userService;
/**
* Set the user for this directory.
*
* @param currentUser
* The user whose permissions define the visibility of other users in
* this directory.
*/
public void init(AuthenticatedUser currentUser) {
this.currentUser = currentUser;
}
@Override @Override
public User get(String identifier) throws GuacamoleException { public User get(String identifier) throws GuacamoleException {
return userService.retrieveObject(currentUser, identifier); return userService.retrieveObject(getCurrentUser(), identifier);
} }
@Override @Override
@Transactional @Transactional
public Collection<User> getAll(Collection<String> identifiers) throws GuacamoleException { public Collection<User> getAll(Collection<String> identifiers) throws GuacamoleException {
Collection<ModeledUser> objects = userService.retrieveObjects(currentUser, identifiers); Collection<ModeledUser> objects = userService.retrieveObjects(getCurrentUser(), identifiers);
return Collections.<User>unmodifiableCollection(objects); return Collections.<User>unmodifiableCollection(objects);
} }
@Override @Override
@Transactional @Transactional
public Set<String> getIdentifiers() throws GuacamoleException { public Set<String> getIdentifiers() throws GuacamoleException {
return userService.getIdentifiers(currentUser); return userService.getIdentifiers(getCurrentUser());
} }
@Override @Override
@Transactional @Transactional
public void add(User object) throws GuacamoleException { public void add(User object) throws GuacamoleException {
userService.createObject(currentUser, object); userService.createObject(getCurrentUser(), object);
} }
@Override @Override
@Transactional @Transactional
public void update(User object) throws GuacamoleException { public void update(User object) throws GuacamoleException {
ModeledUser user = (ModeledUser) object; ModeledUser user = (ModeledUser) object;
userService.updateObject(currentUser, user); userService.updateObject(getCurrentUser(), user);
} }
@Override @Override
@Transactional @Transactional
public void remove(String identifier) throws GuacamoleException { public void remove(String identifier) throws GuacamoleException {
userService.deleteObject(currentUser, identifier); userService.deleteObject(getCurrentUser(), identifier);
} }
} }