Add controlling enable-clipboard-integration property.

This commit is contained in:
Michael Jumper
2014-03-03 09:39:09 -08:00
parent 65451a37f8
commit 3c8d72653e

View File

@@ -29,8 +29,8 @@ import javax.servlet.http.HttpSession;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleServerException; import org.glyptodon.guacamole.GuacamoleServerException;
import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.auth.UserContext;
import org.slf4j.Logger; import org.glyptodon.guacamole.properties.BooleanGuacamoleProperty;
import org.slf4j.LoggerFactory; import org.glyptodon.guacamole.properties.GuacamoleProperties;
/** /**
* Servlet which dumps the current contents of the clipboard. * Servlet which dumps the current contents of the clipboard.
@@ -39,35 +39,46 @@ import org.slf4j.LoggerFactory;
*/ */
public class CaptureClipboard extends AuthenticatingHttpServlet { public class CaptureClipboard extends AuthenticatingHttpServlet {
/**
* Logger for this class.
*/
private Logger logger = LoggerFactory.getLogger(CaptureClipboard.class);
/** /**
* The amount of time to wait for clipboard changes, in milliseconds. * The amount of time to wait for clipboard changes, in milliseconds.
*/ */
private static final int CLIPBOARD_TIMEOUT = 250; private static final int CLIPBOARD_TIMEOUT = 250;
/**
* Whether clipboard integration is enabled.
*/
public static final BooleanGuacamoleProperty INTEGRATION_ENABLED = new BooleanGuacamoleProperty() {
@Override
public String getName() { return "enable-clipboard-integration"; }
};
@Override @Override
protected void authenticatedService( protected void authenticatedService(
UserContext context, UserContext context,
HttpServletRequest request, HttpServletResponse response) HttpServletRequest request, HttpServletResponse response)
throws GuacamoleException { throws GuacamoleException {
// Get clipboard // Only bother if actually enabled
final HttpSession session = request.getSession(true); if (GuacamoleProperties.getProperty(INTEGRATION_ENABLED, false)) {
final ClipboardState clipboard = getClipboardState(session);
// Send clipboard contents
try {
response.setContentType("text/plain");
response.getWriter().print(clipboard.waitForContents(CLIPBOARD_TIMEOUT));
}
catch (IOException e) {
throw new GuacamoleServerException("Unable to send clipboard contents", e);
}
// Get clipboard
final HttpSession session = request.getSession(true);
final ClipboardState clipboard = getClipboardState(session);
// Send clipboard contents
try {
response.setContentType("text/plain");
response.getWriter().print(clipboard.waitForContents(CLIPBOARD_TIMEOUT));
}
catch (IOException e) {
throw new GuacamoleServerException("Unable to send clipboard contents", e);
}
}
} }
} }