1 package net.sourceforge.guacamole.net.basic;
4 * Guacamole - Clientless Remote Desktop
5 * Copyright (C) 2010 Michael Jumper
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.servlet.http.HttpSession;
26 import net.sourceforge.guacamole.GuacamoleException;
27 import net.sourceforge.guacamole.net.InetGuacamoleSocket;
28 import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
29 import net.sourceforge.guacamole.properties.GuacamoleProperties;
30 import net.sourceforge.guacamole.net.GuacamoleSocket;
31 import net.sourceforge.guacamole.servlet.GuacamoleSession;
32 import net.sourceforge.guacamole.net.GuacamoleTunnel;
33 import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
34 import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
35 import net.sourceforge.guacamole.servlet.GuacamoleTunnelServlet;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
41 private Logger logger = LoggerFactory.getLogger(BasicGuacamoleTunnelServlet.class);
43 private AuthenticationProvider authProvider;
46 public void init() throws ServletException {
48 // Get auth provider instance
50 authProvider = GuacamoleProperties.getProperty(BasicGuacamoleProperties.AUTH_PROVIDER);
52 catch (GuacamoleException e) {
53 logger.error("Error getting authentication provider from properties.", e);
54 throw new ServletException(e);
60 protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
62 HttpSession httpSession = request.getSession(true);
64 // Get ID of connection
65 String id = request.getParameter("id");
67 // Get authorized configs
68 Map<String, GuacamoleConfiguration> configs =
69 (Map<String, GuacamoleConfiguration>)
70 httpSession.getAttribute("GUAC_AUTH_CONFIGS");
72 // If no configs in session, not authorized
74 throw new GuacamoleException("No authorized configurations.");
76 // Get authorized config
77 GuacamoleConfiguration config = configs.get(id);
79 logger.error("Error retrieving authorized configuration id={}.", id);
80 throw new GuacamoleException("Unknown configuration ID.");
83 logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id);
85 // Configure and connect socket
86 String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
87 int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT);
89 GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
90 new InetGuacamoleSocket(hostname, port),
94 // Associate socket with tunnel
95 GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
97 // Attach tunnel to session
98 GuacamoleSession session = new GuacamoleSession(httpSession);
99 session.attachTunnel(tunnel);