diff --git a/guacamole/web-client/doc/example/guacamole.properties b/guacamole/web-client/doc/example/guacamole.properties index fb8b93900..b7524a330 100644 --- a/guacamole/web-client/doc/example/guacamole.properties +++ b/guacamole/web-client/doc/example/guacamole.properties @@ -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 diff --git a/guacamole/web-client/src/net/sourceforge/guacamole/net/GuacamoleProperties.java b/guacamole/web-client/src/net/sourceforge/guacamole/net/GuacamoleProperties.java index 25eef84ca..9d0fad318 100644 --- a/guacamole/web-client/src/net/sourceforge/guacamole/net/GuacamoleProperties.java +++ b/guacamole/web-client/src/net/sourceforge/guacamole/net/GuacamoleProperties.java @@ -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); diff --git a/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicFileAuthenticationProvider.java b/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicFileAuthenticationProvider.java index 34a631279..880ae3d41 100644 --- a/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicFileAuthenticationProvider.java +++ b/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicFileAuthenticationProvider.java @@ -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 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; diff --git a/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicLogin.java b/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicLogin.java index 76287bd01..03028e0b1 100644 --- a/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicLogin.java +++ b/guacamole/web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicLogin.java @@ -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