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 javax.servlet.ServletException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpSession;
24 import net.sourceforge.guacamole.GuacamoleException;
25 import net.sourceforge.guacamole.net.InetGuacamoleSocket;
26 import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
27 import net.sourceforge.guacamole.properties.GuacamoleProperties;
28 import net.sourceforge.guacamole.net.GuacamoleSocket;
29 import net.sourceforge.guacamole.servlet.GuacamoleSession;
30 import net.sourceforge.guacamole.net.GuacamoleTunnel;
31 import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
32 import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
33 import net.sourceforge.guacamole.servlet.GuacamoleTunnelServlet;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
39 private Logger logger = LoggerFactory.getLogger(BasicGuacamoleTunnelServlet.class);
41 private AuthenticationProvider authProvider;
44 public void init() throws ServletException {
46 // Get auth provider instance
48 authProvider = GuacamoleProperties.getProperty(BasicGuacamoleProperties.AUTH_PROVIDER);
50 catch (GuacamoleException e) {
51 throw new ServletException(e);
57 protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
59 HttpSession httpSession = request.getSession(true);
61 // Retrieve username and password from parms
62 String username = request.getParameter("username");
63 String password = request.getParameter("password");
65 // Get authorized config
66 GuacamoleConfiguration config = authProvider.getAuthorizedConfiguration(username, password);
68 logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username);
69 throw new GuacamoleException("Invalid login");
72 logger.debug("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
74 // Configure and connect socket
75 String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
76 int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT);
78 GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
79 new InetGuacamoleSocket(hostname, port),
83 // Associate socket with tunnel
84 GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
86 // Attach tunnel to session
87 GuacamoleSession session = new GuacamoleSession(httpSession);
88 session.attachTunnel(tunnel);