mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 14:41:21 +00:00
Working multiple-config login stub.
This commit is contained in:
@@ -18,8 +18,10 @@ package net.sourceforge.guacamole.net.basic;
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, GuacamoleConfiguration> configs =
|
||||
(Map<String, GuacamoleConfiguration>)
|
||||
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.error("Error retrieving authorized configuration id={}.", id);
|
||||
throw new GuacamoleException("Unknown configuration ID.");
|
||||
}
|
||||
|
||||
if (config == null) {
|
||||
logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
||||
throw new GuacamoleException("Invalid login");
|
||||
}
|
||||
|
||||
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);
|
||||
|
@@ -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<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>();
|
||||
configs.put("TEST-UID", config);
|
||||
|
||||
httpSession.setAttribute("GUAC_AUTH_CONFIGS", configs);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, GuacamoleConfiguration> configs =
|
||||
(Map<String, GuacamoleConfiguration>)
|
||||
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("<configs>");
|
||||
|
||||
for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) {
|
||||
|
||||
GuacamoleConfiguration config = entry.getValue();
|
||||
|
||||
// Write config
|
||||
out.print("<config id=\"");
|
||||
out.print(entry.getKey());
|
||||
out.print("\" protocol=\"");
|
||||
out.print(config.getProtocol());
|
||||
out.println("\"/>");
|
||||
|
||||
|
||||
}
|
||||
|
||||
out.println("</configs>");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user