mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-586: Finally remove ClipboardRESTService and associated code (not used).
This commit is contained in:
@@ -22,10 +22,6 @@
|
||||
|
||||
package org.glyptodon.guacamole.net.basic;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
@@ -33,7 +29,6 @@ import org.glyptodon.guacamole.environment.Environment;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.Credentials;
|
||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||
import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -60,11 +55,6 @@ public class GuacamoleSession {
|
||||
*/
|
||||
private UserContext userContext;
|
||||
|
||||
/**
|
||||
* The current clipboard state.
|
||||
*/
|
||||
private final ClipboardState clipboardState = new ClipboardState();
|
||||
|
||||
/**
|
||||
* All currently-active tunnels, indexed by tunnel UUID.
|
||||
*/
|
||||
@@ -141,15 +131,6 @@ public class GuacamoleSession {
|
||||
this.userContext = userContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ClipboardState associated with this session.
|
||||
*
|
||||
* @return The ClipboardState associated with this session.
|
||||
*/
|
||||
public ClipboardState getClipboardState() {
|
||||
return clipboardState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this session has any associated active tunnels.
|
||||
*
|
||||
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.net.basic;
|
||||
|
||||
import java.util.List;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.io.GuacamoleReader;
|
||||
import org.glyptodon.guacamole.protocol.GuacamoleInstruction;
|
||||
|
||||
/**
|
||||
* GuacamoleReader implementation which watches for specific instructions,
|
||||
* maintaining state based on the observed instructions.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class MonitoringGuacamoleReader implements GuacamoleReader {
|
||||
|
||||
/**
|
||||
* The underlying GuacamoleReader.
|
||||
*/
|
||||
private final GuacamoleReader reader;
|
||||
|
||||
/**
|
||||
* Collection of all listeners which will receive events.
|
||||
*/
|
||||
private final ClipboardState clipboard;
|
||||
|
||||
/**
|
||||
* The index of the clipboard stream, if any.
|
||||
*/
|
||||
private String clipboard_stream_index = null;
|
||||
|
||||
/**
|
||||
* Creates a new MonitoringGuacamoleReader which watches the instructions
|
||||
* read by the given GuacamoleReader, firing events when specific
|
||||
* instructions are seen.
|
||||
*
|
||||
* @param clipboard The clipboard state to maintain.
|
||||
* @param reader The reader to observe.
|
||||
*/
|
||||
public MonitoringGuacamoleReader(ClipboardState clipboard,
|
||||
GuacamoleReader reader) {
|
||||
this.clipboard = clipboard;
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean available() throws GuacamoleException {
|
||||
return reader.available();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] read() throws GuacamoleException {
|
||||
|
||||
// Read single instruction, handle end-of-stream
|
||||
GuacamoleInstruction instruction = readInstruction();
|
||||
if (instruction == null)
|
||||
return null;
|
||||
|
||||
return instruction.toString().toCharArray();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleInstruction readInstruction() throws GuacamoleException {
|
||||
|
||||
// Read single instruction, handle end-of-stream
|
||||
GuacamoleInstruction instruction = reader.readInstruction();
|
||||
if (instruction == null)
|
||||
return null;
|
||||
|
||||
// If clipboard changing, reset clipboard state
|
||||
if (instruction.getOpcode().equals("clipboard")) {
|
||||
List<String> args = instruction.getArgs();
|
||||
if (args.size() >= 2) {
|
||||
clipboard_stream_index = args.get(0);
|
||||
clipboard.begin(args.get(1));
|
||||
}
|
||||
}
|
||||
|
||||
// Add clipboard blobs to existing streams
|
||||
else if (instruction.getOpcode().equals("blob")) {
|
||||
List<String> args = instruction.getArgs();
|
||||
if (args.size() >= 2 && args.get(0).equals(clipboard_stream_index)) {
|
||||
String base64 = args.get(1);
|
||||
clipboard.append(DatatypeConverter.parseBase64Binary(base64));
|
||||
}
|
||||
}
|
||||
|
||||
// Terminate and update clipboard at end of stream
|
||||
else if (instruction.getOpcode().equals("end")) {
|
||||
List<String> args = instruction.getArgs();
|
||||
if (args.size() >= 1 && args.get(0).equals(clipboard_stream_index)) {
|
||||
clipboard.commit();
|
||||
clipboard_stream_index = null;
|
||||
}
|
||||
}
|
||||
|
||||
return instruction;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -24,13 +24,11 @@ package org.glyptodon.guacamole.net.basic;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import org.glyptodon.guacamole.net.basic.rest.clipboard.ClipboardRESTService;
|
||||
import java.util.List;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
import org.glyptodon.guacamole.environment.Environment;
|
||||
import org.glyptodon.guacamole.io.GuacamoleReader;
|
||||
import org.glyptodon.guacamole.net.DelegatingGuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
@@ -234,28 +232,6 @@ public class TunnelRequestService {
|
||||
*/
|
||||
private final long connectionStartTime = System.currentTimeMillis();
|
||||
|
||||
@Override
|
||||
public GuacamoleReader acquireReader() {
|
||||
|
||||
// Monitor instructions which pertain to server-side events, if necessary
|
||||
try {
|
||||
if (environment.getProperty(ClipboardRESTService.INTEGRATION_ENABLED, false)) {
|
||||
|
||||
ClipboardState clipboard = session.getClipboardState();
|
||||
return new MonitoringGuacamoleReader(clipboard, super.acquireReader());
|
||||
|
||||
}
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
logger.warn("Clipboard integration failed to initialize: {}", e.getMessage());
|
||||
logger.debug("Error setting up clipboard integration.", e);
|
||||
}
|
||||
|
||||
// Pass through by default.
|
||||
return super.acquireReader();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws GuacamoleException {
|
||||
|
||||
|
@@ -28,7 +28,6 @@ import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
||||
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
|
||||
import org.glyptodon.guacamole.net.basic.rest.auth.TokenRESTService;
|
||||
import org.glyptodon.guacamole.net.basic.rest.clipboard.ClipboardRESTService;
|
||||
import org.glyptodon.guacamole.net.basic.rest.connection.ConnectionRESTService;
|
||||
import org.glyptodon.guacamole.net.basic.rest.connectiongroup.ConnectionGroupRESTService;
|
||||
import org.glyptodon.guacamole.net.basic.rest.activeconnection.ActiveConnectionRESTService;
|
||||
@@ -58,7 +57,6 @@ public class RESTServletModule extends ServletModule {
|
||||
|
||||
// Set up the API endpoints
|
||||
bind(ActiveConnectionRESTService.class);
|
||||
bind(ClipboardRESTService.class);
|
||||
bind(ConnectionGroupRESTService.class);
|
||||
bind(ConnectionRESTService.class);
|
||||
bind(LanguageRESTService.class);
|
||||
|
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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.net.basic.rest.clipboard;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleUnsupportedException;
|
||||
import org.glyptodon.guacamole.environment.Environment;
|
||||
import org.glyptodon.guacamole.net.basic.ClipboardState;
|
||||
import org.glyptodon.guacamole.net.basic.GuacamoleSession;
|
||||
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||
import org.glyptodon.guacamole.properties.BooleanGuacamoleProperty;
|
||||
|
||||
/**
|
||||
* A REST service for reading the current contents of the clipboard.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
@Path("/clipboard")
|
||||
public class ClipboardRESTService {
|
||||
|
||||
/**
|
||||
* The Guacamole server environment.
|
||||
*/
|
||||
@Inject
|
||||
private Environment environment;
|
||||
|
||||
/**
|
||||
* A service for authenticating users from auth tokens.
|
||||
*/
|
||||
@Inject
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
/**
|
||||
* The amount of time to wait for clipboard changes, in milliseconds.
|
||||
*/
|
||||
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"; }
|
||||
|
||||
};
|
||||
|
||||
@GET
|
||||
@AuthProviderRESTExposure
|
||||
public Response getClipboard(@QueryParam("token") String authToken)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Only bother if actually enabled
|
||||
if (environment.getProperty(INTEGRATION_ENABLED, false)) {
|
||||
|
||||
// Get clipboard
|
||||
GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
|
||||
final ClipboardState clipboard = session.getClipboardState();
|
||||
|
||||
// Send clipboard contents
|
||||
synchronized (clipboard) {
|
||||
clipboard.waitForContents(CLIPBOARD_TIMEOUT);
|
||||
return Response.ok(clipboard.getContents(),
|
||||
clipboard.getMimetype()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Otherwise, inform not supported
|
||||
else
|
||||
throw new GuacamoleUnsupportedException("Clipboard integration not supported");
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user