mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Migrated to new tunnel API.
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.net.basic;
|
||||||
|
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.net.Configuration;
|
||||||
|
|
||||||
|
public interface AuthenticationProvider {
|
||||||
|
|
||||||
|
public Configuration getAuthorizedConfiguration(String username, String password) throws GuacamoleException;
|
||||||
|
|
||||||
|
}
|
@@ -35,7 +35,7 @@ import org.xml.sax.XMLReader;
|
|||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
public class BasicFileAuthenticationProvider implements BasicLogin.AuthenticationProvider {
|
public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
||||||
|
|
||||||
private long mappingTime;
|
private long mappingTime;
|
||||||
private Map<String, AuthInfo> mapping;
|
private Map<String, AuthInfo> mapping;
|
||||||
|
@@ -18,40 +18,87 @@ package net.sourceforge.guacamole.net.basic;
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
import net.sourceforge.guacamole.GuacamoleTCPClient;
|
import net.sourceforge.guacamole.GuacamoleTCPClient;
|
||||||
import net.sourceforge.guacamole.net.Configuration;
|
import net.sourceforge.guacamole.net.Configuration;
|
||||||
import net.sourceforge.guacamole.net.GuacamoleProperties;
|
import net.sourceforge.guacamole.net.GuacamoleProperties;
|
||||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||||
|
import net.sourceforge.guacamole.net.tunnel.GuacamoleTunnel;
|
||||||
import net.sourceforge.guacamole.net.tunnel.GuacamoleTunnelServlet;
|
import net.sourceforge.guacamole.net.tunnel.GuacamoleTunnelServlet;
|
||||||
|
|
||||||
public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
|
public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
|
||||||
|
|
||||||
|
private AuthenticationProvider authProvider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doConnect(HttpServletRequest request, HttpServletResponse response) throws GuacamoleException {
|
public void init() throws ServletException {
|
||||||
|
|
||||||
// Session must already exist from login
|
// Get auth provider instance
|
||||||
HttpSession httpSession = request.getSession(false);
|
try {
|
||||||
|
String authProviderClassName = GuacamoleProperties.getProperty("auth-provider");
|
||||||
|
Object obj = Class.forName(authProviderClassName).getConstructor().newInstance();
|
||||||
|
if (!(obj instanceof AuthenticationProvider))
|
||||||
|
throw new ServletException("Specified authentication provider class is not a AuthenticationProvider.");
|
||||||
|
|
||||||
// Retrieve authorized config data from session
|
authProvider = (AuthenticationProvider) obj;
|
||||||
Configuration config = (Configuration) httpSession.getAttribute("BASIC-LOGIN-AUTH");
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
throw new ServletException(e);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
throw new ServletException("Authentication provider class not found", e);
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodException e) {
|
||||||
|
throw new ServletException("Default constructor for authentication provider not present", e);
|
||||||
|
}
|
||||||
|
catch (SecurityException e) {
|
||||||
|
throw new ServletException("Creation of authentication provider disallowed; check your security settings", e);
|
||||||
|
}
|
||||||
|
catch (InstantiationException e) {
|
||||||
|
throw new ServletException("Unable to instantiate authentication provider", e);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
|
throw new ServletException("Unable to access default constructor of authentication provider", e);
|
||||||
|
}
|
||||||
|
catch (InvocationTargetException e) {
|
||||||
|
throw new ServletException("Internal error in constructor of authentication provider", e.getTargetException());
|
||||||
|
}
|
||||||
|
|
||||||
// If no data, not authorized
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
|
||||||
|
// Retrieve username and password from parms
|
||||||
|
String username = request.getParameter("username");
|
||||||
|
String password = request.getParameter("password");
|
||||||
|
|
||||||
|
// Get authorized config
|
||||||
|
Configuration config = authProvider.getAuthorizedConfiguration(username, password);
|
||||||
if (config == null)
|
if (config == null)
|
||||||
throw new GuacamoleException("Unauthorized");
|
throw new GuacamoleException("Invalid login");
|
||||||
|
|
||||||
|
// Configure and connect client
|
||||||
String hostname = GuacamoleProperties.getProperty("guacd-hostname");
|
String hostname = GuacamoleProperties.getProperty("guacd-hostname");
|
||||||
int port = GuacamoleProperties.getIntProperty("guacd-port", null);
|
int port = GuacamoleProperties.getIntProperty("guacd-port", null);
|
||||||
|
|
||||||
GuacamoleTCPClient client = new GuacamoleTCPClient(hostname, port);
|
GuacamoleTCPClient client = new GuacamoleTCPClient(hostname, port);
|
||||||
client.connect(config);
|
client.connect(config);
|
||||||
|
|
||||||
// Set client for session
|
// Associate client with tunnel
|
||||||
|
GuacamoleTunnel tunnel = new GuacamoleTunnel(client);
|
||||||
|
|
||||||
|
// Attach tunnel to session
|
||||||
GuacamoleSession session = new GuacamoleSession(httpSession);
|
GuacamoleSession session = new GuacamoleSession(httpSession);
|
||||||
session.attachClient(client);
|
session.attachTunnel(tunnel);
|
||||||
|
|
||||||
|
return tunnel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,112 +0,0 @@
|
|||||||
|
|
||||||
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.lang.reflect.InvocationTargetException;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
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.Configuration;
|
|
||||||
import net.sourceforge.guacamole.net.GuacamoleProperties;
|
|
||||||
|
|
||||||
public class BasicLogin extends HttpServlet {
|
|
||||||
|
|
||||||
private AuthenticationProvider authProvider;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() throws ServletException {
|
|
||||||
|
|
||||||
// Get auth provider instance
|
|
||||||
try {
|
|
||||||
String authProviderClassName = GuacamoleProperties.getProperty("auth-provider");
|
|
||||||
Object obj = Class.forName(authProviderClassName).getConstructor().newInstance();
|
|
||||||
if (!(obj instanceof AuthenticationProvider))
|
|
||||||
throw new ServletException("Specified authentication provider class is not a AuthenticationProvider.");
|
|
||||||
|
|
||||||
authProvider = (AuthenticationProvider) obj;
|
|
||||||
}
|
|
||||||
catch (GuacamoleException e) {
|
|
||||||
throw new ServletException(e);
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException e) {
|
|
||||||
throw new ServletException("Authentication provider class not found", e);
|
|
||||||
}
|
|
||||||
catch (NoSuchMethodException e) {
|
|
||||||
throw new ServletException("Default constructor for authentication provider not present", e);
|
|
||||||
}
|
|
||||||
catch (SecurityException e) {
|
|
||||||
throw new ServletException("Creation of authentication provider disallowed; check your security settings", e);
|
|
||||||
}
|
|
||||||
catch (InstantiationException e) {
|
|
||||||
throw new ServletException("Unable to instantiate authentication provider", e);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e) {
|
|
||||||
throw new ServletException("Unable to access default constructor of authentication provider", e);
|
|
||||||
}
|
|
||||||
catch (InvocationTargetException e) {
|
|
||||||
throw new ServletException("Internal error in constructor of authentication provider", e.getTargetException());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static interface AuthenticationProvider {
|
|
||||||
public Configuration getAuthorizedConfiguration(String username, String password) throws GuacamoleException;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
||||||
|
|
||||||
// Retrieve username and password from parms
|
|
||||||
String username = req.getParameter("username");
|
|
||||||
String password = req.getParameter("password");
|
|
||||||
|
|
||||||
// Validate username and password
|
|
||||||
try {
|
|
||||||
|
|
||||||
Configuration config = authProvider.getAuthorizedConfiguration(username, password);
|
|
||||||
if (config != null) {
|
|
||||||
|
|
||||||
// Store authorized configuration
|
|
||||||
HttpSession session = req.getSession(true);
|
|
||||||
session.setAttribute(
|
|
||||||
"BASIC-LOGIN-AUTH",
|
|
||||||
config
|
|
||||||
);
|
|
||||||
|
|
||||||
// Success
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Report "forbidden" on any failure
|
|
||||||
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Login invalid");
|
|
||||||
}
|
|
||||||
catch (GuacamoleException e) {
|
|
||||||
throw new ServletException("Error validating credentials", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -17,6 +17,7 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||||
|
|
||||||
<!-- Basic config -->
|
<!-- Basic config -->
|
||||||
<welcome-file-list>
|
<welcome-file-list>
|
||||||
<welcome-file>index.html</welcome-file>
|
<welcome-file>index.html</welcome-file>
|
||||||
@@ -38,14 +39,4 @@
|
|||||||
<url-pattern>/tunnel</url-pattern>
|
<url-pattern>/tunnel</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Basic Login Servlet -->
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>BasicLogin</servlet-name>
|
|
||||||
<servlet-class>net.sourceforge.guacamole.net.basic.BasicLogin</servlet-class>
|
|
||||||
</servlet>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>BasicLogin</servlet-name>
|
|
||||||
<url-pattern>/login</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
||||||
|
@@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
<p id="login-error"></p>
|
<p id="login-error"></p>
|
||||||
|
|
||||||
<form id="login-form" action="login" method="post">
|
<form id="login-form" action="#" method="post">
|
||||||
<table id="login-fields">
|
<table id="login-fields">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
@@ -124,6 +124,7 @@
|
|||||||
|
|
||||||
var loginForm = document.getElementById("login-form");
|
var loginForm = document.getElementById("login-form");
|
||||||
var loginUI = document.getElementById("login-ui");
|
var loginUI = document.getElementById("login-ui");
|
||||||
|
var display = document.getElementById("display");
|
||||||
|
|
||||||
loginForm.onsubmit = function() {
|
loginForm.onsubmit = function() {
|
||||||
|
|
||||||
@@ -134,38 +135,44 @@
|
|||||||
"username=" + encodeURIComponent(username.value)
|
"username=" + encodeURIComponent(username.value)
|
||||||
+ "&password=" + encodeURIComponent(password.value)
|
+ "&password=" + encodeURIComponent(password.value)
|
||||||
|
|
||||||
var xmlhttprequest = new XMLHttpRequest();
|
// Instantiate client
|
||||||
xmlhttprequest.open("POST", "login", false);
|
var guac = new GuacamoleClient(
|
||||||
xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
display,
|
||||||
xmlhttprequest.setRequestHeader("Content-length", data.length);
|
new GuacamoleHTTPTunnel("tunnel")
|
||||||
xmlhttprequest.send(data);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Connect client
|
||||||
|
guac.connect(data);
|
||||||
|
|
||||||
if (xmlhttprequest.status == 200) {
|
|
||||||
loginUI.style.display = "none";
|
|
||||||
startGuacamole();
|
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
|
|
||||||
var loginError = document.getElementById("login-error");
|
var loginError = document.getElementById("login-error");
|
||||||
|
|
||||||
// Display error, reset and refocus password field
|
// Display error, reset and refocus password field
|
||||||
loginError.textContent = "Invalid login. Please try again.";
|
loginError.textContent = e.message;
|
||||||
password.value = "";
|
password.value = "";
|
||||||
password.focus();
|
password.focus();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On success, display UI
|
||||||
|
startGuacamole(guac);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shows guacamole interface and initiates connection to guacamole
|
// Shows guacamole interface and initiates connection to guacamole
|
||||||
function startGuacamole() {
|
function startGuacamole(guac) {
|
||||||
|
|
||||||
|
loginUI.style.display = "none";
|
||||||
document.getElementById("main-guacamole-ui").style.display = "block";
|
document.getElementById("main-guacamole-ui").style.display = "block";
|
||||||
|
|
||||||
var menu = document.getElementById("menu");
|
var menu = document.getElementById("menu");
|
||||||
var display = document.getElementById("display");
|
|
||||||
var logo = document.getElementById("logo");
|
var logo = document.getElementById("logo");
|
||||||
|
|
||||||
var errorDialog = document.getElementById("errorDialog");
|
var errorDialog = document.getElementById("errorDialog");
|
||||||
@@ -178,12 +185,6 @@
|
|||||||
|
|
||||||
window.onresize();
|
window.onresize();
|
||||||
|
|
||||||
// Instantiate client
|
|
||||||
var guac = new GuacamoleClient(
|
|
||||||
display,
|
|
||||||
new GuacamoleHTTPTunnel("tunnel")
|
|
||||||
);
|
|
||||||
|
|
||||||
var state = document.getElementById("state");
|
var state = document.getElementById("state");
|
||||||
guac.setOnStateChangeHandler(function(clientState) {
|
guac.setOnStateChangeHandler(function(clientState) {
|
||||||
|
|
||||||
@@ -311,9 +312,6 @@
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect
|
|
||||||
guac.connect();
|
|
||||||
|
|
||||||
// Disconnect on close
|
// Disconnect on close
|
||||||
window.onunload = function() {
|
window.onunload = function() {
|
||||||
guac.disconnect();
|
guac.disconnect();
|
||||||
|
Reference in New Issue
Block a user