GUACAMOLE-77: Distinguish within REST between the user's identity/permissions and actual existing user objects.

This commit is contained in:
Michael Jumper
2016-08-20 13:54:20 -07:00
parent 87b517ff3e
commit b23dcf83ca
2 changed files with 28 additions and 33 deletions

View File

@@ -38,6 +38,8 @@ import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.rest.activeconnection.APIActiveConnection;
import org.apache.guacamole.rest.connection.APIConnection;
import org.apache.guacamole.rest.connectiongroup.APIConnectionGroup;
import org.apache.guacamole.rest.directory.DirectoryObjectResource;
import org.apache.guacamole.rest.directory.DirectoryObjectResourceFactory;
import org.apache.guacamole.rest.history.HistoryResource;
import org.apache.guacamole.rest.schema.SchemaResource;
import org.apache.guacamole.rest.sharingprofile.APISharingProfile;
@@ -57,6 +59,12 @@ public class UserContextResource {
*/
private final UserContext userContext;
/**
* Factory for creating DirectoryObjectResources which expose a given User.
*/
@Inject
private DirectoryObjectResourceFactory<User, APIUser> userResourceFactory;
/**
* Factory for creating DirectoryResources which expose a given
* ActiveConnection Directory.
@@ -109,6 +117,26 @@ public class UserContextResource {
this.userContext = userContext;
}
/**
* Returns a new resource which represents the User whose access rights
* control the operations of the UserContext exposed by this
* UserContextResource.
*
* @return
* A new resource which represents the User whose access rights
* control the operations of the UserContext exposed by this
* UserContextResource.
*
* @throws GuacamoleException
* If an error occurs while retrieving the User.
*/
@Path("self")
public DirectoryObjectResource<User, APIUser> getSelfResource()
throws GuacamoleException {
return userResourceFactory.create(userContext,
userContext.getUserDirectory(), userContext.self());
}
/**
* Returns a new resource which represents the ActiveConnection Directory
* contained within the UserContext exposed by this UserContextResource.

View File

@@ -29,7 +29,6 @@ import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.rest.directory.DirectoryObjectResource;
import org.apache.guacamole.rest.directory.DirectoryObjectResourceFactory;
import org.apache.guacamole.rest.directory.DirectoryObjectTranslator;
import org.apache.guacamole.rest.directory.DirectoryResource;
@@ -44,23 +43,6 @@ import org.apache.guacamole.rest.directory.DirectoryResource;
@Consumes(MediaType.APPLICATION_JSON)
public class UserDirectoryResource extends DirectoryResource<User, APIUser> {
/**
* The UserContext associated with the Directory which contains the
* User exposed by this resource.
*/
private final UserContext userContext;
/**
* The Directory exposed by this resource.
*/
private final Directory<User> directory;
/**
* A factory which can be used to create instances of resources representing
* Users.
*/
private final DirectoryObjectResourceFactory<User, APIUser> resourceFactory;
/**
* Creates a new UserDirectoryResource which exposes the operations and
* subresources available for the given User Directory.
@@ -85,9 +67,6 @@ public class UserDirectoryResource extends DirectoryResource<User, APIUser> {
DirectoryObjectTranslator<User, APIUser> translator,
DirectoryObjectResourceFactory<User, APIUser> resourceFactory) {
super(userContext, directory, translator, resourceFactory);
this.userContext = userContext;
this.directory = directory;
this.resourceFactory = resourceFactory;
}
@Override
@@ -101,16 +80,4 @@ public class UserDirectoryResource extends DirectoryResource<User, APIUser> {
}
@Override
public DirectoryObjectResource<User, APIUser>
getObjectResource(String identifier) throws GuacamoleException {
// If username is own username, just use self - might not have query permissions
if (userContext.self().getIdentifier().equals(identifier))
return resourceFactory.create(userContext, directory, userContext.self());
return super.getObjectResource(identifier);
}
}