mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
import net.sourceforge.guacamole.net.auth.UserConfiguration;
|
|
||||||
import net.sourceforge.guacamole.net.auth.UsernamePassword;
|
import net.sourceforge.guacamole.net.auth.UsernamePassword;
|
||||||
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||||
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||||
@@ -87,7 +86,7 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserConfiguration getUserConfiguration(UsernamePassword credentials) throws GuacamoleException {
|
public Map<String, GuacamoleConfiguration> getAuthorizedConfigurations(UsernamePassword credentials) throws GuacamoleException {
|
||||||
|
|
||||||
// Check mapping file mod time
|
// Check mapping file mod time
|
||||||
File userMappingFile = getUserMappingFile();
|
File userMappingFile = getUserMappingFile();
|
||||||
@@ -107,19 +106,19 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U
|
|||||||
if (mapping == null)
|
if (mapping == null)
|
||||||
throw new GuacamoleException("User mapping could not be read.");
|
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
|
// Validate and return info for given user and pass
|
||||||
AuthInfo info = mapping.get(credentials.getUsername());
|
AuthInfo info = mapping.get(credentials.getUsername());
|
||||||
if (info != null && info.validate(credentials.getUsername(), credentials.getPassword()))
|
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 {
|
public static class AuthInfo {
|
||||||
|
|
||||||
protected static final String CONFIG_ID = "DEFAULT";
|
|
||||||
|
|
||||||
public static enum Encoding {
|
public static enum Encoding {
|
||||||
PLAIN_TEXT,
|
PLAIN_TEXT,
|
||||||
MD5
|
MD5
|
||||||
@@ -129,16 +128,14 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U
|
|||||||
private String auth_password;
|
private String auth_password;
|
||||||
private Encoding auth_encoding;
|
private Encoding auth_encoding;
|
||||||
|
|
||||||
private BasicUserConfiguration userConfig;
|
private GuacamoleConfiguration config;
|
||||||
|
|
||||||
public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) {
|
public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) {
|
||||||
this.auth_username = auth_username;
|
this.auth_username = auth_username;
|
||||||
this.auth_password = auth_password;
|
this.auth_password = auth_password;
|
||||||
this.auth_encoding = auth_encoding;
|
this.auth_encoding = auth_encoding;
|
||||||
|
|
||||||
userConfig = new BasicUserConfiguration();
|
config = new GuacamoleConfiguration();
|
||||||
userConfig.setConfiguration(CONFIG_ID, new GuacamoleConfiguration());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final char HEX_CHARS[] = {
|
private static final char HEX_CHARS[] = {
|
||||||
@@ -194,8 +191,8 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicUserConfiguration getUserConfiguration() {
|
public GuacamoleConfiguration getConfiguration() {
|
||||||
return userConfig;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -355,12 +352,12 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider<U
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
||||||
case PROTOCOL:
|
case PROTOCOL:
|
||||||
current.getUserConfiguration().getConfiguration(AuthInfo.CONFIG_ID)
|
current.getConfiguration()
|
||||||
.setProtocol(str);
|
.setProtocol(str);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PARAMETER:
|
case PARAMETER:
|
||||||
current.getUserConfiguration().getConfiguration(AuthInfo.CONFIG_ID)
|
current.getConfiguration()
|
||||||
.setParameter(currentParameter, str);
|
.setParameter(currentParameter, str);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ package net.sourceforge.guacamole.net.basic;
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import net.sourceforge.guacamole.net.auth.AuthenticationProvider;
|
import net.sourceforge.guacamole.net.auth.AuthenticationProvider;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
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.net.GuacamoleSocket;
|
||||||
import net.sourceforge.guacamole.servlet.GuacamoleSession;
|
import net.sourceforge.guacamole.servlet.GuacamoleSession;
|
||||||
import net.sourceforge.guacamole.net.GuacamoleTunnel;
|
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.net.basic.properties.BasicGuacamoleProperties;
|
||||||
import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
|
import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
|
||||||
import net.sourceforge.guacamole.servlet.GuacamoleTunnelServlet;
|
import net.sourceforge.guacamole.servlet.GuacamoleTunnelServlet;
|
||||||
@@ -65,15 +65,15 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
|
|||||||
String id = request.getParameter("id");
|
String id = request.getParameter("id");
|
||||||
|
|
||||||
// Get authorized configs
|
// Get authorized configs
|
||||||
UserConfiguration userConfig = (UserConfiguration)
|
Map<String, GuacamoleConfiguration> configs = (Map<String, GuacamoleConfiguration>)
|
||||||
httpSession.getAttribute("GUAC_USER_CONFIG");
|
httpSession.getAttribute("GUAC_CONFIGS");
|
||||||
|
|
||||||
// If no configs in session, not authorized
|
// If no configs in session, not authorized
|
||||||
if (userConfig == null)
|
if (configs == null)
|
||||||
throw new GuacamoleException("No authorized configurations.");
|
throw new GuacamoleException("No authorized configurations.");
|
||||||
|
|
||||||
// Get authorized config
|
// Get authorized config
|
||||||
GuacamoleConfiguration config = userConfig.getConfiguration(id);
|
GuacamoleConfiguration config = configs.get(id);
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
logger.error("Error retrieving authorized configuration id={}.", id);
|
logger.error("Error retrieving authorized configuration id={}.", id);
|
||||||
throw new GuacamoleException("Unknown configuration 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/>.
|
* 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 net.sourceforge.guacamole.net.auth.AuthenticationProvider;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
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.net.auth.UsernamePassword;
|
||||||
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||||
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -68,17 +69,17 @@ public class BasicLogin extends HttpServlet {
|
|||||||
credentials.setPassword(password);
|
credentials.setPassword(password);
|
||||||
|
|
||||||
// Get authorized configs
|
// Get authorized configs
|
||||||
UserConfiguration config;
|
Map<String, GuacamoleConfiguration> configs;
|
||||||
try {
|
try {
|
||||||
config = authProvider.getUserConfiguration(credentials);
|
configs = authProvider.getAuthorizedConfigurations(credentials);
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
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);
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config == null) {
|
if (configs == null) {
|
||||||
logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
@@ -87,7 +88,7 @@ public class BasicLogin extends HttpServlet {
|
|||||||
logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
||||||
|
|
||||||
// Associate configs with session
|
// 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.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import net.sourceforge.guacamole.net.auth.UserConfiguration;
|
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -41,11 +41,12 @@ public class ConfigurationList extends HttpServlet {
|
|||||||
HttpSession httpSession = request.getSession(true);
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
|
||||||
// Get user configuration
|
// Get user configuration
|
||||||
UserConfiguration userConfig = (UserConfiguration)
|
// Get authorized configs
|
||||||
httpSession.getAttribute("GUAC_USER_CONFIG");
|
Map<String, GuacamoleConfiguration> configs = (Map<String, GuacamoleConfiguration>)
|
||||||
|
httpSession.getAttribute("GUAC_CONFIGS");
|
||||||
|
|
||||||
// If no userConfig in session, not authorized
|
// If no configs in session, not authorized
|
||||||
if (userConfig == null) {
|
if (configs == null) {
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,13 +56,13 @@ public class ConfigurationList extends HttpServlet {
|
|||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
out.println("<configs>");
|
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
|
// Write config
|
||||||
out.print("<config id=\"");
|
out.print("<config id=\"");
|
||||||
out.print(id);
|
out.print(entry.getKey());
|
||||||
out.print("\" protocol=\"");
|
out.print("\" protocol=\"");
|
||||||
out.print(config.getProtocol());
|
out.print(config.getProtocol());
|
||||||
out.println("\"/>");
|
out.println("\"/>");
|
||||||
|
@@ -39,6 +39,17 @@
|
|||||||
<url-pattern>/login</url-pattern>
|
<url-pattern>/login</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- Basic Logout Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<description>Logout servlet.</description>
|
||||||
|
<servlet-name>Logout</servlet-name>
|
||||||
|
<servlet-class>net.sourceforge.guacamole.net.basic.BasicLogout</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Logout</servlet-name>
|
||||||
|
<url-pattern>/logout</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Configuration List Servlet -->
|
<!-- Configuration List Servlet -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<description>Configuration list servlet.</description>
|
<description>Configuration list servlet.</description>
|
||||||
|
@@ -50,7 +50,7 @@
|
|||||||
<img id="status-logo" class="logo" src="images/guacamole-logo-24.png" alt="Guacamole" title="Guacamole ${project.version}"/>
|
<img id="status-logo" class="logo" src="images/guacamole-logo-24.png" alt="Guacamole" title="Guacamole ${project.version}"/>
|
||||||
<span id="state"></span>
|
<span id="state"></span>
|
||||||
|
|
||||||
<a href="agpl-3.0-standalone.html"><img id="license" src="images/agpl-logo.png" alt="AGPLv3"/></a>
|
<a href="logout">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -71,6 +71,10 @@
|
|||||||
Available Connections
|
Available Connections
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
<div id="logout">
|
||||||
|
<a href="logout">Logout</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="connections">
|
<table class="connections">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
Reference in New Issue
Block a user