Refactored supporting revised API.

This commit is contained in:
Michael Jumper
2011-05-13 00:53:11 -07:00
parent 74dd8ad735
commit eb8da4d644
5 changed files with 136 additions and 53 deletions

View File

@@ -2,10 +2,10 @@
package net.sourceforge.guacamole.net.basic; package net.sourceforge.guacamole.net.basic;
import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.Configuration; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
public interface AuthenticationProvider { public interface AuthenticationProvider {
public Configuration getAuthorizedConfiguration(String username, String password) throws GuacamoleException; public GuacamoleConfiguration getAuthorizedConfiguration(String username, String password) throws GuacamoleException;
} }

View File

@@ -27,8 +27,9 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.Configuration; import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
import net.sourceforge.guacamole.net.GuacamoleProperties; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
import net.sourceforge.guacamole.properties.GuacamoleProperties;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
@@ -42,12 +43,8 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
private File getUserMappingFile() throws GuacamoleException { private File getUserMappingFile() throws GuacamoleException {
// Get user mapping filename // Get user mapping file
String filename = GuacamoleProperties.getProperty("basic-user-mapping"); return GuacamoleProperties.getProperty(BasicGuacamoleProperties.BASIC_USER_MAPPING);
if (filename == null)
return null;
return new File(filename);
} }
@@ -81,7 +78,7 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
} }
@Override @Override
public Configuration getAuthorizedConfiguration(String username, String password) throws GuacamoleException { public GuacamoleConfiguration getAuthorizedConfiguration(String username, String password) throws GuacamoleException {
// Check mapping file mod time // Check mapping file mod time
File userMappingFile = getUserMappingFile(); File userMappingFile = getUserMappingFile();
@@ -114,14 +111,14 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
private String auth_password; private String auth_password;
private Encoding auth_encoding; private Encoding auth_encoding;
private Configuration config; private GuacamoleConfiguration config;
public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) { public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) {
this.auth_username = auth_username; this.auth_username = auth_username;
this.auth_password = auth_password; this.auth_password = auth_password;
this.auth_encoding = auth_encoding; this.auth_encoding = auth_encoding;
config = new Configuration(); config = new GuacamoleConfiguration();
} }
private static final char HEX_CHARS[] = { private static final char HEX_CHARS[] = {
@@ -177,7 +174,7 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
} }
public Configuration getConfiguration() { public GuacamoleConfiguration getConfiguration() {
return config; return config;
} }

View File

@@ -18,17 +18,19 @@ 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.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
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.net.InetGuacamoleSocket;
import net.sourceforge.guacamole.net.Configuration; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
import net.sourceforge.guacamole.net.GuacamoleProperties; import net.sourceforge.guacamole.properties.GuacamoleProperties;
import net.sourceforge.guacamole.net.GuacamoleSession; import net.sourceforge.guacamole.net.GuacamoleSocket;
import net.sourceforge.guacamole.net.tunnel.GuacamoleTunnel; import net.sourceforge.guacamole.servlet.GuacamoleSession;
import net.sourceforge.guacamole.net.tunnel.GuacamoleTunnelServlet; import net.sourceforge.guacamole.net.GuacamoleTunnel;
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
import net.sourceforge.guacamole.servlet.GuacamoleTunnelServlet;
public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet { public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
@@ -39,34 +41,11 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
// Get auth provider instance // Get auth provider instance
try { try {
String authProviderClassName = GuacamoleProperties.getProperty("auth-provider"); authProvider = GuacamoleProperties.getProperty(BasicGuacamoleProperties.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) { catch (GuacamoleException e) {
throw new ServletException(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());
}
} }
@@ -80,19 +59,21 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
String password = request.getParameter("password"); String password = request.getParameter("password");
// Get authorized config // Get authorized config
Configuration config = authProvider.getAuthorizedConfiguration(username, password); GuacamoleConfiguration config = authProvider.getAuthorizedConfiguration(username, password);
if (config == null) if (config == null)
throw new GuacamoleException("Invalid login"); throw new GuacamoleException("Invalid login");
// Configure and connect client // Configure and connect socket
String hostname = GuacamoleProperties.getProperty("guacd-hostname"); String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
int port = GuacamoleProperties.getIntProperty("guacd-port", null); int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT);
GuacamoleTCPClient client = new GuacamoleTCPClient(hostname, port); GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
client.connect(config); new InetGuacamoleSocket(hostname, port),
config
);
// Associate client with tunnel // Associate socket with tunnel
GuacamoleTunnel tunnel = new GuacamoleTunnel(client); GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
// Attach tunnel to session // Attach tunnel to session
GuacamoleSession session = new GuacamoleSession(httpSession); GuacamoleSession session = new GuacamoleSession(httpSession);

View File

@@ -0,0 +1,63 @@
package net.sourceforge.guacamole.net.basic.properties;
/*
* 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.lang.reflect.InvocationTargetException;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.basic.AuthenticationProvider;
import net.sourceforge.guacamole.properties.GuacamoleProperty;
public abstract class AuthenticationProviderProperty implements GuacamoleProperty<AuthenticationProvider> {
@Override
public AuthenticationProvider parseValue(String authProviderClassName) throws GuacamoleException {
// Get auth provider instance
try {
Object obj = Class.forName(authProviderClassName).getConstructor().newInstance();
if (!(obj instanceof AuthenticationProvider))
throw new GuacamoleException("Specified authentication provider class is not a AuthenticationProvider.");
return (AuthenticationProvider) obj;
}
catch (ClassNotFoundException e) {
throw new GuacamoleException("Authentication provider class not found", e);
}
catch (NoSuchMethodException e) {
throw new GuacamoleException("Default constructor for authentication provider not present", e);
}
catch (SecurityException e) {
throw new GuacamoleException("Creation of authentication provider disallowed; check your security settings", e);
}
catch (InstantiationException e) {
throw new GuacamoleException("Unable to instantiate authentication provider", e);
}
catch (IllegalAccessException e) {
throw new GuacamoleException("Unable to access default constructor of authentication provider", e);
}
catch (InvocationTargetException e) {
throw new GuacamoleException("Internal error in constructor of authentication provider", e.getTargetException());
}
}
}

View File

@@ -0,0 +1,42 @@
package net.sourceforge.guacamole.net.basic.properties;
import net.sourceforge.guacamole.properties.FileGuacamoleProperty;
/*
* 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/>.
*/
public class BasicGuacamoleProperties {
private BasicGuacamoleProperties() {}
public static final FileGuacamoleProperty BASIC_USER_MAPPING = new FileGuacamoleProperty() {
@Override
public String getName() { return "basic-user-mapping"; }
};
public static final AuthenticationProviderProperty AUTH_PROVIDER = new AuthenticationProviderProperty() {
@Override
public String getName() { return "auth-provider"; }
};
}