You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2018/06/03 19:06:38 UTC
[22/50] guacamole-client git commit: GUACAMOLE-38: Switch to regex
for parsing username and password.
GUACAMOLE-38: Switch to regex for parsing username and password.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/16130b32
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/16130b32
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/16130b32
Branch: refs/heads/master
Commit: 16130b32fef8a26a54af2d02015bf843a1b6266e
Parents: 9ab50a2
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Mar 25 09:09:34 2018 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Fri Jun 1 13:40:51 2018 -0400
----------------------------------------------------------------------
.../auth/quickconnect/utility/QCParser.java | 31 +++++++++++++++-----
1 file changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/16130b32/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
index 30121df..6bd0435 100644
--- a/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
+++ b/extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
@@ -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;
@@ -45,6 +47,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) {