mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	Auth API improvements, logout link.
This commit is contained in:
		| @@ -28,7 +28,6 @@ import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import net.sourceforge.guacamole.GuacamoleException; | ||||
| import net.sourceforge.guacamole.net.auth.UserConfiguration; | ||||
| import net.sourceforge.guacamole.net.auth.UsernamePassword; | ||||
| import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties; | ||||
| import net.sourceforge.guacamole.properties.GuacamoleProperties; | ||||
| @@ -87,7 +86,7 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public UserConfiguration getUserConfiguration(UsernamePassword credentials) throws GuacamoleException { | ||||
|     public Map<String, GuacamoleConfiguration> getAuthorizedConfigurations(UsernamePassword credentials) throws GuacamoleException { | ||||
|  | ||||
|         // Check mapping file mod time | ||||
|         File userMappingFile = getUserMappingFile(); | ||||
| @@ -107,19 +106,19 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U | ||||
|         if (mapping == null) | ||||
|             throw new GuacamoleException("User mapping could not be read."); | ||||
|          | ||||
|         Map<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>(); | ||||
|          | ||||
|         // Validate and return info for given user and pass | ||||
|         AuthInfo info = mapping.get(credentials.getUsername()); | ||||
|         if (info != null && info.validate(credentials.getUsername(), credentials.getPassword())) | ||||
|             return info.getUserConfiguration(); | ||||
|                 configs.put("DEFAULT", info.getConfiguration()); | ||||
|  | ||||
|         return null; | ||||
|         return configs; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public static class AuthInfo { | ||||
|  | ||||
|         protected static final String CONFIG_ID = "DEFAULT"; | ||||
|  | ||||
|         public static enum Encoding { | ||||
|             PLAIN_TEXT, | ||||
|             MD5 | ||||
| @@ -129,16 +128,14 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U | ||||
|         private String auth_password; | ||||
|         private Encoding auth_encoding; | ||||
|  | ||||
|         private BasicUserConfiguration userConfig; | ||||
|         private GuacamoleConfiguration config; | ||||
|  | ||||
|         public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) { | ||||
|             this.auth_username = auth_username; | ||||
|             this.auth_password = auth_password; | ||||
|             this.auth_encoding = auth_encoding; | ||||
|  | ||||
|             userConfig = new BasicUserConfiguration(); | ||||
|             userConfig.setConfiguration(CONFIG_ID, new GuacamoleConfiguration()); | ||||
|  | ||||
|             config = new GuacamoleConfiguration(); | ||||
|         } | ||||
|  | ||||
|         private static final char HEX_CHARS[] = { | ||||
| @@ -194,8 +191,8 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U | ||||
|  | ||||
|         } | ||||
|  | ||||
|         public BasicUserConfiguration getUserConfiguration() { | ||||
|             return userConfig; | ||||
|         public GuacamoleConfiguration getConfiguration() { | ||||
|             return config; | ||||
|         } | ||||
|  | ||||
|     } | ||||
| @@ -355,12 +352,12 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U | ||||
|             switch (state) { | ||||
|  | ||||
|                 case PROTOCOL: | ||||
|                     current.getUserConfiguration().getConfiguration(AuthInfo.CONFIG_ID) | ||||
|                     current.getConfiguration() | ||||
|                             .setProtocol(str); | ||||
|                     return; | ||||
|  | ||||
|                 case PARAMETER: | ||||
|                     current.getUserConfiguration().getConfiguration(AuthInfo.CONFIG_ID) | ||||
|                     current.getConfiguration() | ||||
|                             .setParameter(currentParameter, str); | ||||
|                     return; | ||||
|                  | ||||
|   | ||||
| @@ -18,6 +18,7 @@ package net.sourceforge.guacamole.net.basic; | ||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| import java.util.Map; | ||||
| import net.sourceforge.guacamole.net.auth.AuthenticationProvider; | ||||
| import javax.servlet.ServletException; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| @@ -29,7 +30,6 @@ import net.sourceforge.guacamole.properties.GuacamoleProperties; | ||||
| import net.sourceforge.guacamole.net.GuacamoleSocket; | ||||
| import net.sourceforge.guacamole.servlet.GuacamoleSession; | ||||
| import net.sourceforge.guacamole.net.GuacamoleTunnel; | ||||
| import net.sourceforge.guacamole.net.auth.UserConfiguration; | ||||
| import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties; | ||||
| import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket; | ||||
| import net.sourceforge.guacamole.servlet.GuacamoleTunnelServlet; | ||||
| @@ -65,15 +65,15 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet { | ||||
|         String id = request.getParameter("id"); | ||||
|          | ||||
|         // Get authorized configs | ||||
|         UserConfiguration userConfig = (UserConfiguration)  | ||||
|                 httpSession.getAttribute("GUAC_USER_CONFIG"); | ||||
|         Map<String, GuacamoleConfiguration> configs = (Map<String, GuacamoleConfiguration>)  | ||||
|                 httpSession.getAttribute("GUAC_CONFIGS"); | ||||
|  | ||||
|         // If no configs in session, not authorized | ||||
|         if (userConfig == null) | ||||
|         if (configs == null) | ||||
|             throw new GuacamoleException("No authorized configurations."); | ||||
|  | ||||
|         // Get authorized config | ||||
|         GuacamoleConfiguration config = userConfig.getConfiguration(id); | ||||
|         GuacamoleConfiguration config = configs.get(id); | ||||
|         if (config == null) { | ||||
|             logger.error("Error retrieving authorized configuration id={}.", id); | ||||
|             throw new GuacamoleException("Unknown configuration ID."); | ||||
|   | ||||
| @@ -18,9 +18,9 @@ package net.sourceforge.guacamole.net.basic; | ||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| import net.sourceforge.guacamole.net.auth.UserConfiguration; | ||||
| import net.sourceforge.guacamole.net.auth.AuthenticationProvider; | ||||
| import java.io.IOException; | ||||
| import java.util.Map; | ||||
| import javax.servlet.ServletException; | ||||
| import javax.servlet.http.HttpServlet; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| @@ -30,6 +30,7 @@ import net.sourceforge.guacamole.GuacamoleException; | ||||
| import net.sourceforge.guacamole.net.auth.UsernamePassword; | ||||
| import net.sourceforge.guacamole.properties.GuacamoleProperties; | ||||
| import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties; | ||||
| import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| @@ -68,17 +69,17 @@ public class BasicLogin extends HttpServlet { | ||||
|         credentials.setPassword(password); | ||||
|          | ||||
|         // Get authorized configs | ||||
|         UserConfiguration config; | ||||
|         Map<String, GuacamoleConfiguration> configs; | ||||
|         try { | ||||
|             config = authProvider.getUserConfiguration(credentials); | ||||
|             configs = authProvider.getAuthorizedConfigurations(credentials); | ||||
|         } | ||||
|         catch (GuacamoleException e) { | ||||
|             logger.error("Error retrieving configuration for user {}.", username); | ||||
|             logger.error("Error retrieving configuration(s) for user {}.", username); | ||||
|             response.sendError(HttpServletResponse.SC_FORBIDDEN); | ||||
|             return; | ||||
|         } | ||||
|          | ||||
|         if (config == null) { | ||||
|         if (configs == null) { | ||||
|             logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username); | ||||
|             response.sendError(HttpServletResponse.SC_FORBIDDEN); | ||||
|             return; | ||||
| @@ -87,7 +88,7 @@ public class BasicLogin extends HttpServlet { | ||||
|         logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username); | ||||
|  | ||||
|         // Associate configs with session | ||||
|         httpSession.setAttribute("GUAC_USER_CONFIG", config); | ||||
|         httpSession.setAttribute("GUAC_CONFIGS", configs); | ||||
|  | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,44 @@ | ||||
| package net.sourceforge.guacamole.net.basic; | ||||
|  | ||||
| /* | ||||
|  *  Guacamole - Clientless Remote Desktop | ||||
|  *  Copyright (C) 2010  Michael Jumper | ||||
|  * | ||||
|  *  This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as published by | ||||
|  *  the Free Software Foundation, either version 3 of the License, or | ||||
|  *  (at your option) any later version. | ||||
|  * | ||||
|  *  This program is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  *  GNU Affero General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Affero General Public License | ||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| import java.io.IOException; | ||||
| import javax.servlet.http.HttpServlet; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.servlet.http.HttpSession; | ||||
|  | ||||
| public class BasicLogout extends HttpServlet { | ||||
|  | ||||
|     @Override | ||||
|     protected void service(HttpServletRequest request, HttpServletResponse response) | ||||
|     throws IOException { | ||||
|  | ||||
|         // Invalidate session, if any | ||||
|         HttpSession httpSession = request.getSession(false); | ||||
|         if (httpSession != null) | ||||
|             httpSession.invalidate(); | ||||
|  | ||||
|         // Redirect to index | ||||
|         response.sendRedirect("index.xhtml"); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| @@ -1,29 +0,0 @@ | ||||
|  | ||||
| package net.sourceforge.guacamole.net.basic; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import net.sourceforge.guacamole.net.auth.UserConfiguration; | ||||
| import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; | ||||
|  | ||||
| public class BasicUserConfiguration implements UserConfiguration { | ||||
|  | ||||
|     private Map<String, GuacamoleConfiguration> configs = | ||||
|             new HashMap<String, GuacamoleConfiguration>(); | ||||
|  | ||||
|     @Override | ||||
|     public GuacamoleConfiguration getConfiguration(String id) { | ||||
|         return configs.get(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<String> listConfigurations() { | ||||
|         return configs.keySet(); | ||||
|     } | ||||
|      | ||||
|     protected void setConfiguration(String id, GuacamoleConfiguration config) { | ||||
|         configs.put(id, config); | ||||
|     } | ||||
|      | ||||
| } | ||||
| @@ -20,12 +20,12 @@ package net.sourceforge.guacamole.net.basic; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.io.PrintWriter; | ||||
| import java.util.Map; | ||||
| import java.util.Map.Entry; | ||||
| import javax.servlet.http.HttpServlet; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.servlet.http.HttpSession; | ||||
| import net.sourceforge.guacamole.net.auth.UserConfiguration; | ||||
| import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| @@ -41,11 +41,12 @@ public class ConfigurationList extends HttpServlet { | ||||
|         HttpSession httpSession = request.getSession(true); | ||||
|  | ||||
|         // Get user configuration | ||||
|         UserConfiguration userConfig = (UserConfiguration) | ||||
|                 httpSession.getAttribute("GUAC_USER_CONFIG"); | ||||
|         // Get authorized configs | ||||
|         Map<String, GuacamoleConfiguration> configs = (Map<String, GuacamoleConfiguration>)  | ||||
|                 httpSession.getAttribute("GUAC_CONFIGS"); | ||||
|  | ||||
|         // If no userConfig in session, not authorized | ||||
|         if (userConfig == null) { | ||||
|         // If no configs in session, not authorized | ||||
|         if (configs == null) { | ||||
|             response.sendError(HttpServletResponse.SC_FORBIDDEN); | ||||
|             return; | ||||
|         } | ||||
| @@ -55,13 +56,13 @@ public class ConfigurationList extends HttpServlet { | ||||
|         PrintWriter out = response.getWriter(); | ||||
|         out.println("<configs>"); | ||||
|          | ||||
|         for (String id : userConfig.listConfigurations()) { | ||||
|         for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) { | ||||
|  | ||||
|             GuacamoleConfiguration config = userConfig.getConfiguration(id); | ||||
|             GuacamoleConfiguration config = entry.getValue(); | ||||
|  | ||||
|             // Write config | ||||
|             out.print("<config id=\""); | ||||
|             out.print(id); | ||||
|             out.print(entry.getKey()); | ||||
|             out.print("\" protocol=\""); | ||||
|             out.print(config.getProtocol()); | ||||
|             out.println("\"/>"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user