Added auth provider to properties, fixed classnames

This commit is contained in:
Michael Jumper
2010-12-05 15:04:11 -08:00
parent f99f9cff15
commit 4ef133d2b5
4 changed files with 74 additions and 11 deletions

View File

@@ -21,6 +21,9 @@ guacd-hostname: localhost
guacd-port: 4822
# Session provider class (provides and configured guacamole session based on authentication information)
session-provider: net.sourceforge.guacamole.basic.BasicGuacamoleSessionProvider
session-provider: net.sourceforge.guacamole.net.authentication.basic.BasicGuacamoleSessionProvider
# Auth provider class (authenticates user/pass combination, needed if using the provided login screen)
auth-provider: net.sourceforge.guacamole.net.authentication.basic.BasicFileAuthenticationProvider
basic-user-mapping: /path/to/user-mapping.xml

View File

@@ -2,20 +2,26 @@
package net.sourceforge.guacamole.net;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.servlet.ServletException;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.authentication.basic.BasicLogin;
public class GuacamoleProperties {
private static final Properties properties = new Properties();
private static final Properties properties;
private static GuacamoleException exception;
static {
properties = new Properties();
try {
properties.load(BasicLogin.class.getResourceAsStream("/guacamole.properties"));
InputStream stream = GuacamoleProperties.class.getResourceAsStream("/guacamole.properties");
if (stream == null)
throw new IOException("Resource /guacamole.properties not found.");
properties.load(stream);
}
catch (IOException e) {
exception = new GuacamoleException("Error reading guacamole.properties", e);

View File

@@ -9,6 +9,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.GuacamoleProperties;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@@ -20,11 +21,10 @@ public class BasicFileAuthenticationProvider implements BasicLogin.Authenticatio
private long mappingTime;
private Map<String, AuthInfo> mapping;
private File getUserMappingFile() {
private File getUserMappingFile() throws GuacamoleException {
// Get user mapping filename
//String filename = context.getInitParameter("basic-user-mapping");
String filename = ""; // FIXME
String filename = GuacamoleProperties.getProperty("basic-user-mapping");
if (filename == null)
return null;

View File

@@ -2,17 +2,71 @@
package net.sourceforge.guacamole.net.authentication.basic;
import java.io.IOException;
import java.util.Properties;
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;
public class BasicLogin extends HttpServlet {
private AuthenticationProvider authProvider;
private Config config;
@Override
public void init() throws ServletException {
try {
config = new Config();
}
catch (GuacamoleException e) {
throw new ServletException(e);
}
}
private class Config extends Configuration {
private AuthenticationProvider authProvider;
public Config() throws GuacamoleException {
// Get auth provider instance
try {
String authProviderClassName = readParameter("auth-provider");
Object obj = Class.forName(authProviderClassName).getConstructor().newInstance();
if (!(obj instanceof AuthenticationProvider))
throw new GuacamoleException("Specified session provider class is not a GuacamoleSessionProvider");
authProvider = (AuthenticationProvider) obj;
}
catch (ClassNotFoundException e) {
throw new GuacamoleException("Session provider class not found", e);
}
catch (NoSuchMethodException e) {
throw new GuacamoleException("Default constructor for session provider not present", e);
}
catch (SecurityException e) {
throw new GuacamoleException("Creation of session provider disallowed; check your security settings", e);
}
catch (InstantiationException e) {
throw new GuacamoleException("Unable to instantiate session provider", e);
}
catch (IllegalAccessException e) {
throw new GuacamoleException("Unable to access default constructor of session provider", e);
}
catch (InvocationTargetException e) {
throw new GuacamoleException("Internal error in constructor of session provider", e.getTargetException());
}
}
public AuthenticationProvider getAuthenticationProvider() {
return authProvider;
}
}
public static interface AuthenticationProvider {
public AuthorizedConfiguration getAuthorizedConfiguration(String username, String password) throws GuacamoleException;
@@ -61,7 +115,7 @@ public class BasicLogin extends HttpServlet {
// Validate username and password
try {
AuthorizedConfiguration info = authProvider.getAuthorizedConfiguration(username, password);
AuthorizedConfiguration info = config.getAuthenticationProvider().getAuthorizedConfiguration(username, password);
if (info != null) {
// Store authorized configuration