Working multiple-config login stub.
[guacamole.git] / src / main / java / net / sourceforge / guacamole / net / basic / ConfigurationList.java
1 package net.sourceforge.guacamole.net.basic;
2
3 /*
4  *  Guacamole - Clientless Remote Desktop
5  *  Copyright (C) 2010  Michael Jumper
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Affero General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Affero General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Affero General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 import java.io.IOException;
22 import java.io.PrintWriter;
23 import java.util.Map;
24 import java.util.Map.Entry;
25 import javax.servlet.http.HttpServlet;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.servlet.http.HttpSession;
29 import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class ConfigurationList extends HttpServlet {
34
35     private Logger logger = LoggerFactory.getLogger(ConfigurationList.class);
36    
37     @Override
38     protected void service(HttpServletRequest request, HttpServletResponse response)
39     throws IOException {
40
41         HttpSession httpSession = request.getSession(true);
42
43         // Get authorized configs
44         Map<String, GuacamoleConfiguration> configs =
45                 (Map<String, GuacamoleConfiguration>)
46                 httpSession.getAttribute("GUAC_AUTH_CONFIGS");
47
48         // If no configs in session, not authorized
49         if (configs == null) {
50             response.sendError(HttpServletResponse.SC_FORBIDDEN);
51             return;
52         }
53
54         // Write XML
55         response.setHeader("Content-Type", "text/xml");
56         PrintWriter out = response.getWriter();
57         out.println("<configs>");
58         
59         for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) {
60
61             GuacamoleConfiguration config = entry.getValue();
62
63             // Write config
64             out.print("<config id=\"");
65             out.print(entry.getKey());
66             out.print("\" protocol=\"");
67             out.print(config.getProtocol());
68             out.println("\"/>");
69
70
71         }
72
73         out.println("</configs>");
74     }
75
76 }
77