mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-38: Break userInfo parsing into its own function, and properly decode username and password.
This commit is contained in:
@@ -136,18 +136,18 @@ public class QCParser {
|
|||||||
// Look for the username and password and parse them out.
|
// Look for the username and password and parse them out.
|
||||||
if (userInfo != null && !userInfo.isEmpty()) {
|
if (userInfo != null && !userInfo.isEmpty()) {
|
||||||
|
|
||||||
Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
|
try {
|
||||||
if (userinfoMatcher.matches()) {
|
Map<String, String> userInfoParams = parseUserInfo(userInfo);
|
||||||
String username = userinfoMatcher.group(USERNAME_GROUP);
|
|
||||||
String password = userinfoMatcher.group(PASSWORD_GROUP);
|
|
||||||
|
|
||||||
if (username != null && !username.isEmpty())
|
if (userInfoParams.containsKey("username"))
|
||||||
qcConfig.setParameter("username", username);
|
qcConfig.setParameter("username", userInfoParams.get("username"));
|
||||||
|
|
||||||
if (password != null && !password.isEmpty())
|
if (userInfoParams.containsKey("password"))
|
||||||
qcConfig.setParameter("password", password);
|
qcConfig.setParameter("password", userInfoParams.get("password"));
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
throw new GuacamoleServerException("Unexpected lack of UTF-8 encoding support.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return qcConfig;
|
return qcConfig;
|
||||||
@@ -184,6 +184,43 @@ public class QCParser {
|
|||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the given string for username and password values,
|
||||||
|
* and return a map containing the username, password
|
||||||
|
* or both.
|
||||||
|
*
|
||||||
|
* @param userInfo
|
||||||
|
* The string to parse for username/password values.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A map with the username, password, or both.
|
||||||
|
*
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
* If Java lacks UTF-8 support.
|
||||||
|
*/
|
||||||
|
public static Map<String, String> parseUserInfo(String userInfo)
|
||||||
|
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");
|
||||||
|
|
||||||
|
if (username != null && !username.isEmpty())
|
||||||
|
userInfoMap.put("username", username);
|
||||||
|
|
||||||
|
if (password != null && !password.isEmpty())
|
||||||
|
userInfoMap.put("password", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
return userInfoMap;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a GuacamoleConfiguration object, generate a name
|
* Given a GuacamoleConfiguration object, generate a name
|
||||||
* for the configuration based on the protocol, host, user
|
* for the configuration based on the protocol, host, user
|
||||||
|
Reference in New Issue
Block a user