mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Converted to generic credentials.
This commit is contained in:
@@ -3,8 +3,8 @@ package net.sourceforge.guacamole.net.auth;
|
|||||||
|
|
||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
|
||||||
public interface AuthenticationProvider {
|
public interface AuthenticationProvider<CredentialType> {
|
||||||
|
|
||||||
public UserConfiguration getUserConfiguration(String username, String password) throws GuacamoleException;
|
public UserConfiguration getUserConfiguration(CredentialType credentials) throws GuacamoleException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package net.sourceforge.guacamole.net.auth;
|
||||||
|
|
||||||
|
public class UsernamePassword {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -29,6 +29,7 @@ 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.UserConfiguration;
|
||||||
|
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;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
@@ -40,7 +41,7 @@ import org.xml.sax.XMLReader;
|
|||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
public class BasicFileAuthenticationProvider implements AuthenticationProvider<UsernamePassword> {
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(BasicFileAuthenticationProvider.class);
|
private Logger logger = LoggerFactory.getLogger(BasicFileAuthenticationProvider.class);
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserConfiguration getUserConfiguration(String username, String password) throws GuacamoleException {
|
public UserConfiguration getUserConfiguration(UsernamePassword credentials) throws GuacamoleException {
|
||||||
|
|
||||||
// Check mapping file mod time
|
// Check mapping file mod time
|
||||||
File userMappingFile = getUserMappingFile();
|
File userMappingFile = getUserMappingFile();
|
||||||
@@ -107,8 +108,8 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
throw new GuacamoleException("User mapping could not be read.");
|
throw new GuacamoleException("User mapping could not be read.");
|
||||||
|
|
||||||
// Validate and return info for given user and pass
|
// Validate and return info for given user and pass
|
||||||
AuthInfo info = mapping.get(username);
|
AuthInfo info = mapping.get(credentials.getUsername());
|
||||||
if (info != null && info.validate(username, password))
|
if (info != null && info.validate(credentials.getUsername(), credentials.getPassword()))
|
||||||
return info.getUserConfiguration();
|
return info.getUserConfiguration();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -27,6 +27,7 @@ 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.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
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 org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -62,10 +63,14 @@ public class BasicLogin extends HttpServlet {
|
|||||||
String username = request.getParameter("username");
|
String username = request.getParameter("username");
|
||||||
String password = request.getParameter("password");
|
String password = request.getParameter("password");
|
||||||
|
|
||||||
|
UsernamePassword credentials = new UsernamePassword();
|
||||||
|
credentials.setUsername(username);
|
||||||
|
credentials.setPassword(password);
|
||||||
|
|
||||||
// Get authorized configs
|
// Get authorized configs
|
||||||
UserConfiguration config;
|
UserConfiguration config;
|
||||||
try {
|
try {
|
||||||
config = authProvider.getUserConfiguration(username, password);
|
config = authProvider.getUserConfiguration(credentials);
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Error retrieving configuration for user {}.", username);
|
logger.error("Error retrieving configuration for user {}.", username);
|
||||||
|
@@ -140,6 +140,12 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If only one connection, redirect to that.
|
||||||
|
if (configs.length == 1) {
|
||||||
|
window.location.href = "client.xhtml?" + encodeURIComponent(configs[0].id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove all rows from connections list
|
// Remove all rows from connections list
|
||||||
var tbody = document.getElementById("connections-tbody");
|
var tbody = document.getElementById("connections-tbody");
|
||||||
tbody.innerHTML = "";
|
tbody.innerHTML = "";
|
||||||
|
Reference in New Issue
Block a user