Converted to generic credentials.

This commit is contained in:
Michael Jumper
2011-08-14 23:19:49 -07:00
parent c559f4ae33
commit ab90d1d846
5 changed files with 43 additions and 7 deletions

View File

@@ -3,8 +3,8 @@ package net.sourceforge.guacamole.net.auth;
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;
}

View File

@@ -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;
}
}

View File

@@ -29,6 +29,7 @@ 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;
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.XMLReaderFactory;
public class BasicFileAuthenticationProvider implements AuthenticationProvider {
public class BasicFileAuthenticationProvider implements AuthenticationProvider<UsernamePassword> {
private Logger logger = LoggerFactory.getLogger(BasicFileAuthenticationProvider.class);
@@ -86,7 +87,7 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
}
@Override
public UserConfiguration getUserConfiguration(String username, String password) throws GuacamoleException {
public UserConfiguration getUserConfiguration(UsernamePassword credentials) throws GuacamoleException {
// Check mapping file mod time
File userMappingFile = getUserMappingFile();
@@ -107,8 +108,8 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
throw new GuacamoleException("User mapping could not be read.");
// Validate and return info for given user and pass
AuthInfo info = mapping.get(username);
if (info != null && info.validate(username, password))
AuthInfo info = mapping.get(credentials.getUsername());
if (info != null && info.validate(credentials.getUsername(), credentials.getPassword()))
return info.getUserConfiguration();
return null;

View File

@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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 org.slf4j.Logger;
@@ -62,10 +63,14 @@ public class BasicLogin extends HttpServlet {
String username = request.getParameter("username");
String password = request.getParameter("password");
UsernamePassword credentials = new UsernamePassword();
credentials.setUsername(username);
credentials.setPassword(password);
// Get authorized configs
UserConfiguration config;
try {
config = authProvider.getUserConfiguration(username, password);
config = authProvider.getUserConfiguration(credentials);
}
catch (GuacamoleException e) {
logger.error("Error retrieving configuration for user {}.", username);

View File

@@ -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
var tbody = document.getElementById("connections-tbody");
tbody.innerHTML = "";