mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-919: Remove use of HttpSession.
This commit is contained in:
@@ -149,10 +149,7 @@ public class GuacamoleSession {
|
||||
* Returns a collection which iterates over instances of all listeners
|
||||
* defined in guacamole.properties. For each listener defined in
|
||||
* guacamole.properties, a new instance is created and stored in this
|
||||
* collection. The contents of this collection is stored within the
|
||||
* HttpSession, and will be reused if available. Each listener is
|
||||
* instantiated once per session. Listeners are singleton classes within the
|
||||
* session, but not globally.
|
||||
* collection.
|
||||
*
|
||||
* @return A collection which iterates over instances of all listeners
|
||||
* defined in guacamole.properties.
|
||||
|
@@ -25,7 +25,6 @@ package org.glyptodon.guacamole.net.basic;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* HTTP-specific implementation of TunnelRequest.
|
||||
@@ -49,11 +48,6 @@ public class HTTPTunnelRequest implements TunnelRequest {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpSession getSession() {
|
||||
return request.getSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
return request.getParameter(name);
|
||||
|
@@ -23,7 +23,6 @@
|
||||
package org.glyptodon.guacamole.net.basic;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* Request interface which provides only the functions absolutely required
|
||||
@@ -90,13 +89,6 @@ public interface TunnelRequest {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current HTTP session, or null if no session yet exists.
|
||||
*
|
||||
* @return The current HTTP session, or null if no session yet exists.
|
||||
*/
|
||||
public HttpSession getSession();
|
||||
|
||||
/**
|
||||
* Returns the value of the parameter having the given name.
|
||||
*
|
||||
|
@@ -27,7 +27,6 @@ import com.google.inject.Singleton;
|
||||
import org.glyptodon.guacamole.net.basic.rest.clipboard.ClipboardRESTService;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||
@@ -39,7 +38,6 @@ import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||
import org.glyptodon.guacamole.net.auth.Credentials;
|
||||
import org.glyptodon.guacamole.net.auth.Directory;
|
||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||
import org.glyptodon.guacamole.net.basic.event.SessionListenerCollection;
|
||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||
import org.glyptodon.guacamole.net.event.TunnelCloseEvent;
|
||||
import org.glyptodon.guacamole.net.event.TunnelConnectEvent;
|
||||
@@ -165,21 +163,6 @@ public class TunnelRequestService {
|
||||
public GuacamoleTunnel createTunnel(TunnelRequest request)
|
||||
throws GuacamoleException {
|
||||
|
||||
HttpSession httpSession = request.getSession();
|
||||
if (httpSession == null)
|
||||
throw new GuacamoleSecurityException("Cannot connect - user not logged in.");
|
||||
|
||||
// Get listeners
|
||||
final SessionListenerCollection listeners;
|
||||
try {
|
||||
listeners = new SessionListenerCollection(httpSession);
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
logger.error("Creation of tunnel to guacd aborted: Failed to retrieve listeners: {}", e.getMessage());
|
||||
logger.debug("Error retrieving listeners.", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Get auth token and session
|
||||
String authToken = request.getParameter("authToken");
|
||||
GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
|
||||
@@ -195,11 +178,10 @@ public class TunnelRequestService {
|
||||
// Remove prefix
|
||||
id = id.substring(id_type.PREFIX.length());
|
||||
|
||||
// Get credentials
|
||||
// Get session-specific elements
|
||||
final Credentials credentials = session.getCredentials();
|
||||
|
||||
// Get context
|
||||
final UserContext context = session.getUserContext();
|
||||
final Collection listeners = session.getListeners();
|
||||
|
||||
// If no context or no credentials, not logged in
|
||||
if (context == null || credentials == null)
|
||||
|
@@ -1,136 +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.event;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||
import org.glyptodon.guacamole.properties.GuacamoleProperties;
|
||||
|
||||
/**
|
||||
* A collection which iterates over instances of all listeners defined in
|
||||
* guacamole.properties. For each listener defined in guacamole.properties, a
|
||||
* new instance is created and stored in this collection. The contents of this
|
||||
* collection is stored within the HttpSession, and will be reused if available.
|
||||
* Each listener is instantiated once per session. Listeners are singleton
|
||||
* classes within the session, but not globally.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class SessionListenerCollection extends AbstractCollection {
|
||||
|
||||
/**
|
||||
* The name of the session attribute which will contain the listener
|
||||
* collection.
|
||||
*/
|
||||
private static final String SESSION_ATTRIBUTE = "GUAC_LISTENERS";
|
||||
|
||||
/**
|
||||
* The wrapped collection of listeners, possibly retrieved from the
|
||||
* session.
|
||||
*/
|
||||
private Collection listeners;
|
||||
|
||||
/**
|
||||
* Creates a new SessionListenerCollection which stores all listeners
|
||||
* defined in guacamole.properties in the provided session. If listeners
|
||||
* are already stored in the provided session, those listeners are used
|
||||
* instead.
|
||||
*
|
||||
* @param session The HttpSession to store listeners within.
|
||||
* @throws GuacamoleException If an error occurs while instantiating new
|
||||
* listeners.
|
||||
*/
|
||||
public SessionListenerCollection(HttpSession session) throws GuacamoleException {
|
||||
|
||||
// Pull cached listeners from session
|
||||
listeners = (Collection) session.getAttribute(SESSION_ATTRIBUTE);
|
||||
|
||||
// If no listeners stored, listeners must be loaded first
|
||||
if (listeners == null) {
|
||||
|
||||
// Load listeners from guacamole.properties
|
||||
listeners = new ArrayList();
|
||||
try {
|
||||
|
||||
// Get all listener classes from properties
|
||||
Collection<Class> listenerClasses =
|
||||
GuacamoleProperties.getProperty(BasicGuacamoleProperties.EVENT_LISTENERS);
|
||||
|
||||
// Add an instance of each class to the list
|
||||
if (listenerClasses != null) {
|
||||
for (Class listenerClass : listenerClasses) {
|
||||
|
||||
// Instantiate listener
|
||||
Object listener = listenerClass.getConstructor().newInstance();
|
||||
|
||||
// Add listener to collection of listeners
|
||||
listeners.add(listener);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new GuacamoleException("Listener class is abstract.", e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new GuacamoleException("No access to listener constructor.", e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// This should not happen, given there ARE no arguments
|
||||
throw new GuacamoleException("Illegal arguments to listener constructor.", e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new GuacamoleException("Error while instantiating listener.", e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new GuacamoleException("Listener has no default constructor.", e);
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
throw new GuacamoleException("Security restrictions prevent instantiation of listener.", e);
|
||||
}
|
||||
|
||||
// Store listeners for next time
|
||||
session.setAttribute(SESSION_ATTRIBUTE, listeners);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
return listeners.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return listeners.size();
|
||||
}
|
||||
|
||||
}
|
@@ -1,27 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Classes used by the Guacamole web application to broadcast events.
|
||||
*/
|
||||
package org.glyptodon.guacamole.net.basic.event;
|
||||
|
@@ -24,7 +24,6 @@ package org.glyptodon.guacamole.net.basic.websocket;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
import org.glyptodon.guacamole.net.basic.TunnelRequest;
|
||||
|
||||
@@ -35,11 +34,6 @@ import org.glyptodon.guacamole.net.basic.TunnelRequest;
|
||||
*/
|
||||
public class WebSocketTunnelRequest implements TunnelRequest {
|
||||
|
||||
/**
|
||||
* The wrapped HandshakeRequest.
|
||||
*/
|
||||
private final HandshakeRequest request;
|
||||
|
||||
/**
|
||||
* All parameters passed via HTTP to the WebSocket handshake.
|
||||
*/
|
||||
@@ -52,15 +46,9 @@ public class WebSocketTunnelRequest implements TunnelRequest {
|
||||
* @param request The HandshakeRequest to wrap.
|
||||
*/
|
||||
public WebSocketTunnelRequest(HandshakeRequest request) {
|
||||
this.request = request;
|
||||
this.handshakeParameters = request.getParameterMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpSession getSession() {
|
||||
return (HttpSession) request.getHttpSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
|
||||
|
@@ -25,7 +25,6 @@ package org.glyptodon.guacamole.net.basic.websocket.jetty9;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.glyptodon.guacamole.net.basic.TunnelRequest;
|
||||
|
||||
@@ -36,11 +35,6 @@ import org.glyptodon.guacamole.net.basic.TunnelRequest;
|
||||
*/
|
||||
public class WebSocketTunnelRequest implements TunnelRequest {
|
||||
|
||||
/**
|
||||
* The wrapped UpgradeRequest.
|
||||
*/
|
||||
private final UpgradeRequest request;
|
||||
|
||||
/**
|
||||
* All parameters passed via HTTP to the WebSocket handshake.
|
||||
*/
|
||||
@@ -53,15 +47,9 @@ public class WebSocketTunnelRequest implements TunnelRequest {
|
||||
* @param request The UpgradeRequest to wrap.
|
||||
*/
|
||||
public WebSocketTunnelRequest(UpgradeRequest request) {
|
||||
this.request = request;
|
||||
this.handshakeParameters = request.getParameterMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpSession getSession() {
|
||||
return (HttpSession) request.getSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
|
||||
|
Reference in New Issue
Block a user