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/>.
21 import net.sourceforge.guacamole.net.auth.AuthenticationProvider;
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpSession;
25 import net.sourceforge.guacamole.GuacamoleException;
26 import net.sourceforge.guacamole.net.InetGuacamoleSocket;
27 import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
28 import net.sourceforge.guacamole.properties.GuacamoleProperties;
29 import net.sourceforge.guacamole.net.GuacamoleSocket;
30 import net.sourceforge.guacamole.servlet.GuacamoleSession;
31 import net.sourceforge.guacamole.net.GuacamoleTunnel;
32 import net.sourceforge.guacamole.net.auth.UserConfiguration;
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 UserConfiguration userConfig = (UserConfiguration)
69 httpSession.getAttribute("GUAC_USER_CONFIG");
71 // If no configs in session, not authorized
72 if (userConfig == null)
73 throw new GuacamoleException("No authorized configurations.");
75 // Get authorized config
76 GuacamoleConfiguration config = userConfig.getConfiguration(id);
78 logger.error("Error retrieving authorized configuration id={}.", id);
79 throw new GuacamoleException("Unknown configuration ID.");
82 logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id);
84 // Configure and connect socket
85 String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
86 int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT);
88 GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
89 new InetGuacamoleSocket(hostname, port),
93 // Associate socket with tunnel
94 GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
96 // Attach tunnel to session
97 GuacamoleSession session = new GuacamoleSession(httpSession);
98 session.attachTunnel(tunnel);