Added auth provider to properties, fixed classnames
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Sun, 5 Dec 2010 23:04:11 +0000 (15:04 -0800)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Sun, 5 Dec 2010 23:04:11 +0000 (15:04 -0800)
web-client/doc/example/guacamole.properties
web-client/src/net/sourceforge/guacamole/net/GuacamoleProperties.java
web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicFileAuthenticationProvider.java
web-client/src/net/sourceforge/guacamole/net/authentication/basic/BasicLogin.java

index fb8b939..b7524a3 100644 (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
 
index 25eef84..9d0fad3 100644 (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);
index 34a6312..880ae3d 100644 (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;
 
index 76287bd..03028e0 100644 (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