From: Michael Jumper Date: Sat, 13 Aug 2011 04:40:07 +0000 (-0700) Subject: Working multiple-config login stub. X-Git-Url: http://git.alex.org.uk Working multiple-config login stub. --- diff --git a/pom.xml b/pom.xml index 5b465e3..17f2cc0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-default-webapp war - 0.4.0 + 0.5.0 guacamole-default-webapp http://guacamole.sourceforge.net/ diff --git a/src/main/java/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.java b/src/main/java/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.java index e2d447f..d23f631 100644 --- a/src/main/java/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.java +++ b/src/main/java/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.java @@ -18,8 +18,10 @@ package net.sourceforge.guacamole.net.basic; * along with this program. If not, see . */ +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.net.InetGuacamoleSocket; @@ -59,26 +61,26 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet { HttpSession httpSession = request.getSession(true); - // Retrieve username and password from parms - String username = request.getParameter("username"); - String password = request.getParameter("password"); + // Get ID of connection + String id = request.getParameter("id"); + + // Get authorized configs + Map configs = + (Map) + httpSession.getAttribute("GUAC_AUTH_CONFIGS"); + + // If no configs in session, not authorized + if (configs == null) + throw new GuacamoleException("No authorized configurations."); // Get authorized config - GuacamoleConfiguration config; - try { - config = authProvider.getAuthorizedConfiguration(username, password); - } - catch (GuacamoleException e) { - logger.error("Error retrieving authorized configuration for user {}.", username); - throw e; - } - + GuacamoleConfiguration config = configs.get(id); if (config == null) { - logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username); - throw new GuacamoleException("Invalid login"); + logger.error("Error retrieving authorized configuration id={}.", id); + throw new GuacamoleException("Unknown configuration ID."); } - - logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username); + + logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id); // Configure and connect socket String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME); diff --git a/src/main/java/net/sourceforge/guacamole/net/basic/BasicLogin.java b/src/main/java/net/sourceforge/guacamole/net/basic/BasicLogin.java index 1702421..0884f46 100644 --- a/src/main/java/net/sourceforge/guacamole/net/basic/BasicLogin.java +++ b/src/main/java/net/sourceforge/guacamole/net/basic/BasicLogin.java @@ -19,6 +19,8 @@ package net.sourceforge.guacamole.net.basic; */ import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -80,7 +82,11 @@ public class BasicLogin extends HttpServlet { logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username); - httpSession.setAttribute("GUAC_AUTH_CONFIGS", new Integer(0)); + // Build map of authorized configs + Map configs = new HashMap(); + configs.put("TEST-UID", config); + + httpSession.setAttribute("GUAC_AUTH_CONFIGS", configs); } diff --git a/src/main/java/net/sourceforge/guacamole/net/basic/ConfigurationList.java b/src/main/java/net/sourceforge/guacamole/net/basic/ConfigurationList.java new file mode 100644 index 0000000..b3dae6e --- /dev/null +++ b/src/main/java/net/sourceforge/guacamole/net/basic/ConfigurationList.java @@ -0,0 +1,77 @@ +package net.sourceforge.guacamole.net.basic; + +/* + * Guacamole - Clientless Remote Desktop + * Copyright (C) 2010 Michael Jumper + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; +import java.util.Map.Entry; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfigurationList extends HttpServlet { + + private Logger logger = LoggerFactory.getLogger(ConfigurationList.class); + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws IOException { + + HttpSession httpSession = request.getSession(true); + + // Get authorized configs + Map configs = + (Map) + httpSession.getAttribute("GUAC_AUTH_CONFIGS"); + + // If no configs in session, not authorized + if (configs == null) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return; + } + + // Write XML + response.setHeader("Content-Type", "text/xml"); + PrintWriter out = response.getWriter(); + out.println(""); + + for (Entry entry : configs.entrySet()) { + + GuacamoleConfiguration config = entry.getValue(); + + // Write config + out.print(""); + + + } + + out.println(""); + } + +} + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 3983287..2b64e11 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -39,6 +39,17 @@ /login + + + Configuration list servlet. + Configs + net.sourceforge.guacamole.net.basic.ConfigurationList + + + Configs + /configs + + Tunnel servlet. diff --git a/src/main/webapp/client.xhtml b/src/main/webapp/client.xhtml index 97bdb64..58529bd 100644 --- a/src/main/webapp/client.xhtml +++ b/src/main/webapp/client.xhtml @@ -91,16 +91,6 @@ new Guacamole.HTTPTunnel("tunnel") ); - try { - - // Connect client - guac.connect(data); - - } - catch (e) { - // TODO: Handle exception ... - } - var menu = document.getElementById("menu"); var logo = document.getElementById("status-logo"); @@ -325,6 +315,23 @@ guac.sendKeyEvent(0, KEYSYM_CTRL); } + + try { + + // Get ID + var url = window.location.href; + var query = url.indexOf("?"); + var id = url.substring(query+1); + + // Connect client + guac.connect("id=" + encodeURIComponent(id)); + + } + catch (e) { + // TODO: Handle exception ... + } + + /* ]]> */ diff --git a/src/main/webapp/index.xhtml b/src/main/webapp/index.xhtml index 92fc1ed..5468b7f 100644 --- a/src/main/webapp/index.xhtml +++ b/src/main/webapp/index.xhtml @@ -74,22 +74,11 @@ - - - + + - - - - - - - - - - - +
NameProtocolDescriptionProtocolName
zhz@localhostvncConnect to test.guac-dev.org via vnc.
zhz@localhostsshConnect to test.guac-dev.org via ssh.
@@ -102,6 +91,96 @@ diff --git a/src/main/webapp/styles/login.css b/src/main/webapp/styles/login.css index a64b406..728866a 100644 --- a/src/main/webapp/styles/login.css +++ b/src/main/webapp/styles/login.css @@ -150,6 +150,16 @@ div#connection-list-ui table thead { background: #9A8; } +div#connection-list-ui table thead th.protocol { + width: 1em; + padding: 0.5em; +} + +div#connection-list-ui table thead th.name { + text-align: left; + padding: 0.5em; +} + div#connection-list-ui table thead tr { border-top: 1px solid #676; border-bottom: 1px solid gray; @@ -169,6 +179,10 @@ div#connection-list-ui table td { text-align: center; } +div#connection-list-ui table td.name { + text-align: left; +} + div#connection-list-ui table tbody tr:nth-child(even) { background: #CCC; } div#connection-list-ui table tbody tr:nth-child(odd) { background: #EEE; }