mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-38: Put userInfo directly into configuration.
This commit is contained in:
@@ -137,13 +137,7 @@ public class QCParser {
|
||||
if (userInfo != null && !userInfo.isEmpty()) {
|
||||
|
||||
try {
|
||||
Map<String, String> userInfoParams = parseUserInfo(userInfo);
|
||||
|
||||
if (userInfoParams.containsKey("username"))
|
||||
qcConfig.setParameter("username", userInfoParams.get("username"));
|
||||
|
||||
if (userInfoParams.containsKey("password"))
|
||||
qcConfig.setParameter("password", userInfoParams.get("password"));
|
||||
parseUserInfo(userInfo, qcConfig);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e);
|
||||
@@ -186,39 +180,38 @@ public class QCParser {
|
||||
|
||||
/**
|
||||
* Parse the given string for username and password values,
|
||||
* and return a map containing the username, password
|
||||
* or both.
|
||||
* and, if values are present, decode them and set them in
|
||||
* the provided GuacamoleConfiguration object.
|
||||
*
|
||||
* @param userInfo
|
||||
* The string to parse for username/password values.
|
||||
*
|
||||
* @return
|
||||
* A map with the username, password, or both.
|
||||
* @param config
|
||||
* The GuacamoleConfiguration object to store the username
|
||||
* and password in.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
* If Java lacks UTF-8 support.
|
||||
*/
|
||||
public static Map<String, String> parseUserInfo(String userInfo)
|
||||
public static void parseUserInfo(String userInfo,
|
||||
GuacamoleConfiguration config)
|
||||
throws UnsupportedEncodingException {
|
||||
|
||||
Map<String, String> userInfoMap = new HashMap<String, String>();
|
||||
Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
|
||||
|
||||
if (userinfoMatcher.matches()) {
|
||||
String username = URLDecoder.decode(
|
||||
userinfoMatcher.group(USERNAME_GROUP), "UTF-8");
|
||||
String password = URLDecoder.decode(
|
||||
userinfoMatcher.group(PASSWORD_GROUP), "UTF-8");
|
||||
String username = userinfoMatcher.group(USERNAME_GROUP);
|
||||
String password = userinfoMatcher.group(PASSWORD_GROUP);
|
||||
|
||||
if (username != null && !username.isEmpty())
|
||||
userInfoMap.put("username", username);
|
||||
config.setParameter("username",
|
||||
URLDecoder.decode(username, "UTF-8"));
|
||||
|
||||
if (password != null && !password.isEmpty())
|
||||
userInfoMap.put("password", password);
|
||||
config.setParameter("password",
|
||||
URLDecoder.decode(password, "UTF-8"));
|
||||
}
|
||||
|
||||
return userInfoMap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,7 @@ import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Class to test methods in the QCParser utility class.
|
||||
@@ -62,22 +62,25 @@ public class QCParserTest {
|
||||
|
||||
Map<String, String> userInfoMap;
|
||||
|
||||
userInfoMap = QCParser.parseUserInfo("guacuser:secretpw");
|
||||
assertEquals("guacuser", userInfoMap.get("username"));
|
||||
assertEquals("secretpw", userInfoMap.get("password"));
|
||||
GuacamoleConfiguration config1 = new GuacamoleConfiguration();
|
||||
QCParser.parseUserInfo("guacuser:secretpw", config1);
|
||||
assertEquals("guacuser", config1.getParameter("username"));
|
||||
assertEquals("secretpw", config1.getParameter("password"));
|
||||
|
||||
GuacamoleConfiguration config2 = new GuacamoleConfiguration();
|
||||
QCParser.parseUserInfo("guacuser", config2);
|
||||
assertEquals("guacuser", config2.getParameter("username"));
|
||||
assertNull(config2.getParameter("password"));
|
||||
|
||||
userInfoMap = QCParser.parseUserInfo("guacuser");
|
||||
assertEquals("guacuser", userInfoMap.get("username"));
|
||||
assertFalse(userInfoMap.containsKey("password"));
|
||||
GuacamoleConfiguration config3 = new GuacamoleConfiguration();
|
||||
QCParser.parseUserInfo("guacuser:P%40ssw0rd%21", config3);
|
||||
assertEquals("guacuser", config3.getParameter("username"));
|
||||
assertEquals("P@ssw0rd!", config3.getParameter("password"));
|
||||
|
||||
userInfoMap = QCParser.parseUserInfo("guacuser:P%40ssw0rd%21");
|
||||
assertEquals("guacuser", userInfoMap.get("username"));
|
||||
assertEquals("P@ssw0rd!", userInfoMap.get("password"));
|
||||
|
||||
userInfoMap = QCParser.parseUserInfo("domain%5cguacuser:domain%2fpassword");
|
||||
assertEquals("domain\\guacuser", userInfoMap.get("username"));
|
||||
assertEquals("domain/password", userInfoMap.get("password"));
|
||||
GuacamoleConfiguration config4 = new GuacamoleConfiguration();
|
||||
QCParser.parseUserInfo("domain%5cguacuser:domain%2fpassword", config4);
|
||||
assertEquals("domain\\guacuser", config4.getParameter("username"));
|
||||
assertEquals("domain/password", config4.getParameter("password"));
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user