mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-38: Switch to regex for parsing username and password.
This commit is contained in:
@@ -23,6 +23,8 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.guacamole.GuacamoleClientException;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.protocol.GuacamoleConfiguration;
|
||||
@@ -44,6 +46,21 @@ public class QCParser {
|
||||
*/
|
||||
public static final String DEFAULT_URI_HOST = "localhost";
|
||||
|
||||
/**
|
||||
* The regex to use to split username and password.
|
||||
*/
|
||||
private static final Pattern userinfoPattern = Pattern.compile("(^[^:]+):(.*)");
|
||||
|
||||
/**
|
||||
* The regex group of the username.
|
||||
*/
|
||||
private static final int USERNAME_GROUP = 1;
|
||||
|
||||
/**
|
||||
* THe regex group of the password.
|
||||
*/
|
||||
private static final int PASSWORD_GROUP = 2;
|
||||
|
||||
/**
|
||||
* Parse out a URI string and get a connection from that string,
|
||||
* or an exception if the parsing fails.
|
||||
@@ -88,11 +105,11 @@ public class QCParser {
|
||||
paramList = Arrays.asList(query.split("&"));
|
||||
|
||||
if (userInfo != null && !userInfo.equals("")) {
|
||||
String[] authenticators = userInfo.split(":");
|
||||
if (authenticators.length > 0 && authenticators[0] != null)
|
||||
username = authenticators[0];
|
||||
if (authenticators.length > 1 && authenticators[1] != null)
|
||||
password = authenticators[1];
|
||||
|
||||
Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
|
||||
username = userinfoMatcher.group(USERNAME_GROUP);
|
||||
password = userinfoMatcher.group(PASSWORD_GROUP);
|
||||
|
||||
}
|
||||
|
||||
GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
|
||||
@@ -102,10 +119,10 @@ public class QCParser {
|
||||
if (port > 0)
|
||||
qcConfig.setParameter("port", Integer.toString(port));
|
||||
|
||||
if (username != null)
|
||||
if (username != null && username.length() > 0)
|
||||
qcConfig.setParameter("username", username);
|
||||
|
||||
if (password != null)
|
||||
if (password != null && password.length() > 0)
|
||||
qcConfig.setParameter("password", password);
|
||||
|
||||
if (paramList != null) {
|
||||
|
Reference in New Issue
Block a user