959bf0e6edf8d4f55d7cb7d8f3a5680d31666914
[guacamole.git] / web / guacamole-default-webapp / src / main / java / net / sourceforge / guacamole / net / authentication / basic / BasicGuacamoleSessionProvider.java
1
2 package net.sourceforge.guacamole.net.authentication.basic;
3
4 import javax.servlet.http.HttpSession;
5 import net.sourceforge.guacamole.GuacamoleException;
6 import net.sourceforge.guacamole.net.GuacamoleSession;
7 import net.sourceforge.guacamole.net.authentication.GuacamoleSessionProvider;
8
9 /*
10  *  Guacamole - Clientless Remote Desktop
11  *  Copyright (C) 2010  Michael Jumper
12  *
13  *  This program is free software: you can redistribute it and/or modify
14  *  it under the terms of the GNU Affero General Public License as published by
15  *  the Free Software Foundation, either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  This program is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Affero General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Affero General Public License
24  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26
27 public class BasicGuacamoleSessionProvider implements GuacamoleSessionProvider {
28
29     public GuacamoleSession createSession(HttpSession session) throws GuacamoleException {
30
31         // Retrieve authorized config data from session
32         BasicLogin.AuthorizedConfiguration config = (BasicLogin.AuthorizedConfiguration)
33                 session.getAttribute("BASIC-LOGIN-AUTH");
34
35         // If no data, not authorized
36         if (config == null)
37             throw new GuacamoleException("Unauthorized");
38
39         // Configure session from authorized config info
40         GuacamoleSession guacSession = new GuacamoleSession(session);
41         guacSession.setConnection(config.getProtocol(), config.getHostname(), config.getPort());
42         if (config.getPassword() != null)
43             guacSession.setPassword(config.getPassword());
44
45         // Return authorized session
46         return guacSession;
47
48     }
49
50 }