a6bfeeb5283bcd3681eb3bc9dacc9d17c8462c6c
[guacamole.git] / web / guacamole-common / src / main / java / net / sourceforge / guacamole / net / GuacamoleConfiguration.java
1
2 package net.sourceforge.guacamole.net;
3
4 /*
5  *  Guacamole - Clientless Remote Desktop
6  *  Copyright (C) 2010  Michael Jumper
7  *
8  *  This program is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU Affero General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU Affero General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Affero General Public License
19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 import net.sourceforge.guacamole.net.authentication.GuacamoleSessionProvider;
23 import java.lang.reflect.InvocationTargetException;
24 import javax.servlet.http.HttpSession;
25 import net.sourceforge.guacamole.GuacamoleException;
26
27 public class GuacamoleConfiguration extends Configuration {
28
29     private String guacd_hostname;
30     private int guacd_port;
31     private GuacamoleSessionProvider sessionProvider;
32
33     public GuacamoleConfiguration() throws GuacamoleException {
34
35         guacd_hostname       = readParameter("guacd-hostname");
36         guacd_port           = readIntParameter("guacd-port", null);
37
38         // Get session provider instance
39         try {
40             String sessionProviderClassName = readParameter("session-provider");
41             Object obj = Class.forName(sessionProviderClassName).getConstructor().newInstance();
42             if (!(obj instanceof GuacamoleSessionProvider))
43                 throw new GuacamoleException("Specified session provider class is not a GuacamoleSessionProvider");
44
45             sessionProvider = (GuacamoleSessionProvider) obj;
46         }
47         catch (ClassNotFoundException e) {
48             throw new GuacamoleException("Session provider class not found", e);
49         }
50         catch (NoSuchMethodException e) {
51             throw new GuacamoleException("Default constructor for session provider not present", e);
52         }
53         catch (SecurityException e) {
54             throw new GuacamoleException("Creation of session provider disallowed; check your security settings", e);
55         }
56         catch (InstantiationException e) {
57             throw new GuacamoleException("Unable to instantiate session provider", e);
58         }
59         catch (IllegalAccessException e) {
60             throw new GuacamoleException("Unable to access default constructor of session provider", e);
61         }
62         catch (InvocationTargetException e) {
63             throw new GuacamoleException("Internal error in constructor of session provider", e.getTargetException());
64         }
65
66     }
67
68     public int getProxyPort() {
69         return guacd_port;
70     }
71
72     public String getProxyHostname() {
73         return guacd_hostname;
74     }
75
76     public GuacamoleSession createSession(HttpSession session) throws GuacamoleException {
77         return sessionProvider.createSession(session);
78     }
79
80 }