GUACAMOLE-5: Validate that data was provided when creating/updating resources.

This commit is contained in:
Michael Jumper
2016-07-12 00:20:36 -07:00
parent e579eae95c
commit f440f55823
2 changed files with 12 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.guacamole.GuacamoleClientException;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.Identifiable;
@@ -120,8 +121,15 @@ public class DirectoryObjectResource<InternalType extends Identifiable, External
*/
@PUT
public void updateObject(ExternalType modifiedObject) throws GuacamoleException {
// Validate that data was provided
if (modifiedObject == null)
throw new GuacamoleClientException("Data must be submitted when updating objects.");
// Perform update
translator.applyExternalChanges(object, modifiedObject);
directory.update(object);
}
/**

View File

@@ -222,6 +222,10 @@ public class DirectoryResource<InternalType extends Identifiable, ExternalType>
public ExternalType createObject(ExternalType object)
throws GuacamoleException {
// Validate that data was provided
if (object == null)
throw new GuacamoleClientException("Data must be submitted when creating objects.");
// Create the new object within the directory
directory.add(translator.toInternalObject(object));