[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r189133734
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -184,6 +184,43 @@ public static GuacamoleConfiguration 
getConfiguration(String uri)
 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 parseUserInfo(String userInfo)
+throws UnsupportedEncodingException {
+
+Map userInfoMap = new HashMap();
+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);
--- End diff --

Okay, passed the config object through to the method and just set it 
directly.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r189133551
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -184,6 +184,43 @@ public static GuacamoleConfiguration 
getConfiguration(String uri)
 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 parseUserInfo(String userInfo)
+throws UnsupportedEncodingException {
+
+Map userInfoMap = new HashMap();
+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())
--- End diff --

Okay, moved the null check to prior to decoding it, so that should be 
solved.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r189082729
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -184,6 +184,43 @@ public static GuacamoleConfiguration 
getConfiguration(String uri)
 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 parseUserInfo(String userInfo)
+throws UnsupportedEncodingException {
+
+Map userInfoMap = new HashMap();
+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);
--- End diff --

We shouldn't be using a `Map` as a sort of poor man's object. If we need to 
return a username/password pair, then we should either have an object which 
represents a username/password pair, or this function should just set the 
username/password on the `GuacamoleConfiguration` directly (might be easier).


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-14 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187981053
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/test/java/org/apache/guacamole/auth/quickconnect/utility/QCParserTest.java
 ---
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Class to test methods in the QCParser utility class.
+ */
+public class QCParserTest {
+
+/**
+ * Verify that the parseQueryString() method functions as designed.
+ */
+@Test
+public void testParseQueryString() throws UnsupportedEncodingException 
{
--- End diff --

Tests should be implemented.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-14 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187968051
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/test/java/org/apache/guacamole/auth/quickconnect/utility/QCParserTest.java
 ---
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Class to test methods in the QCParser utility class.
+ */
+public class QCParserTest {
+
+/**
+ * Verify that the parseQueryString() method functions as designed.
+ */
+@Test
+public void testParseQueryString() throws UnsupportedEncodingException 
{
--- End diff --

Will work this up, and will also add a unit test for the new 
`parseUserInfo()` method.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-14 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187967894
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to generate a GuacamoleConfiguration object.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to use if one is not provided in
+ * the incoming URI.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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 GuacamoleConfiguration
+ * from that string, or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+// Parse the URI object from provided string.
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+
+// Break out individual components of the URI.
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+
+// Generate a new GuacamoleConfiguration
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+
+// Check for provided protocol or use default
+if (protocol != null && !protocol.isEmpty())
+qcConfig.setProtocol(protocol);
+else
+qcConfig.setProtocol(DEFAULT_URI_PROTOCOL);
+
+// Check for provided port number
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+// Check for provided host or use default
+if (host != null && !host.isEmpty())
+qcConfig.setParameter("hostname", host);
+else
+qcConfig.setParameter("hostname", DEFAULT_URI_HOST);
+
+// Look for extra query parameters 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-14 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187868053
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/test/java/org/apache/guacamole/auth/quickconnect/utility/QCParserTest.java
 ---
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Class to test methods in the QCParser utility class.
+ */
+public class QCParserTest {
+
+/**
+ * Verify that the parseQueryString() method functions as designed.
+ */
+@Test
+public void testParseQueryString() throws UnsupportedEncodingException 
{
--- End diff --

I suggest adding a unit test for the overall URI parsing performed by 
`QCParser.getConfiguration()`, which is decently complex. The parsing of query 
string parameters is only one piece of that pie.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-14 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187867376
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to generate a GuacamoleConfiguration object.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to use if one is not provided in
+ * the incoming URI.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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 GuacamoleConfiguration
+ * from that string, or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+// Parse the URI object from provided string.
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+
+// Break out individual components of the URI.
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+
+// Generate a new GuacamoleConfiguration
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+
+// Check for provided protocol or use default
+if (protocol != null && !protocol.isEmpty())
+qcConfig.setProtocol(protocol);
+else
+qcConfig.setProtocol(DEFAULT_URI_PROTOCOL);
+
+// Check for provided port number
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+// Check for provided host or use default
+if (host != null && !host.isEmpty())
+qcConfig.setParameter("hostname", host);
+else
+qcConfig.setParameter("hostname", DEFAULT_URI_HOST);
+
+// Look for extra query parameters 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-12 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187771304
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectionGroup.java
 ---
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnectionGroup;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+
+/**
+ * Provides a simple, single-level connection group used for
+ * temporarily storing the Connection objects created by users.
+ */
+public class QuickConnectionGroup extends AbstractConnectionGroup {
+
+/**
+ * A set that will store the Connection identifiers for this group.
+ */
+private Set connectionIdentifiers =
+new HashSet(Collections.emptyList());
+
+/**
+ * Set up a QuickConnectionGroup with the provided name and
+ * identifier.
+ *
+ * @param name
+ * The name of the QuickConnectionGroup.
+ *
+ * @param identifier
+ * The identifier of the QuickConnectionGroup.
+ */
+public QuickConnectionGroup(String name, String identifier) {
+
+setName(name);
+setIdentifier(identifier);
+setType(ConnectionGroup.Type.ORGANIZATIONAL);
--- End diff --

Done.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-11 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187763295
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectionGroup.java
 ---
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnectionGroup;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+
+/**
+ * Provides a simple, single-level connection group used for
+ * temporarily storing the Connection objects created by users.
+ */
+public class QuickConnectionGroup extends AbstractConnectionGroup {
+
+/**
+ * A set that will store the Connection identifiers for this group.
+ */
+private Set connectionIdentifiers =
+new HashSet(Collections.emptyList());
+
+/**
+ * Set up a QuickConnectionGroup with the provided name and
+ * identifier.
+ *
+ * @param name
+ * The name of the QuickConnectionGroup.
+ *
+ * @param identifier
+ * The identifier of the QuickConnectionGroup.
+ */
+public QuickConnectionGroup(String name, String identifier) {
+
+setName(name);
+setIdentifier(identifier);
+setType(ConnectionGroup.Type.ORGANIZATIONAL);
--- End diff --

We probably should provide a constructor, but you can get around this for 
the time being by using `super.setName()`, `super.setIdentifier()`, etc., as 
that will invoke a function against the superclass which is definitely 
initialized at this point.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-09 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r187026140
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to generate a GuacamoleConfiguration object.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to use if one is not provided in
+ * the incoming URI.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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 GuacamoleConfiguration
+ * from that string, or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+
+// Break out individual components of the URI.
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+
+String username = null;
+String password = null;
+Map queryParams = null;
--- End diff --

Untangled.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-08 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r186860117
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnection;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of a directory to stored Connection objects
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The connections to store.
+ */
+private final Map connections =
+new HashMap();
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private AtomicInteger connectionId;
+
+/**
+ * Creates a new QuickConnectDirectory with the default
+ * empty Map for Connection objects, and the specified
+ * ConnectionGroup at the root of the directory.
+ *
+ * @param rootGroup
+ * A group that should be at the root of this directory.
+ */
+public QuickConnectDirectory(ConnectionGroup rootGroup) {
+this.rootGroup = (QuickConnectionGroup)rootGroup;
+this.connectionId = new AtomicInteger();
+super.setObjects(this.connections);
+}
+
+/**
+ * Returns the current connection identifier counter and
+ * then increments it.
+ *
+ * @return
+ * An int representing the next available connection
+ * identifier to be used when adding connections.
+ */
+private int getNextConnectionID() {
+return connectionId.getAndIncrement();
+}
+
+@Override
+public void add(Connection connection) throws GuacamoleException {
+connections.put(connection.getIdentifier(), connection);
--- End diff --

Switched.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-08 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r186859701
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to generate a GuacamoleConfiguration object.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to use if one is not provided in
+ * the incoming URI.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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 GuacamoleConfiguration
+ * from that string, or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+
+// Break out individual components of the URI.
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+
+String username = null;
+String password = null;
+Map queryParams = null;
--- End diff --

Okay, I'll take a look at this section and try to untangle it.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-08 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r186857930
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectionGroup.java
 ---
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnectionGroup;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+
+/**
+ * Provides a simple, single-level connection group used for
+ * temporarily storing the Connection objects created by users.
+ */
+public class QuickConnectionGroup extends AbstractConnectionGroup {
+
+/**
+ * A set that will store the Connection identifiers for this group.
+ */
+private Set connectionIdentifiers =
+new HashSet(Collections.emptyList());
+
+/**
+ * Set up a QuickConnectionGroup with the provided name and
+ * identifier.
+ *
+ * @param name
+ * The name of the QuickConnectionGroup.
+ *
+ * @param identifier
+ * The identifier of the QuickConnectionGroup.
+ */
+public QuickConnectionGroup(String name, String identifier) {
+
+setName(name);
+setIdentifier(identifier);
+setType(ConnectionGroup.Type.ORGANIZATIONAL);
--- End diff --

Okay, but if the superclass doesn't have a constructor that calls these, 
how should I handle that?  Override the individual methods inside the class 
itself and then call them?  I'm looking at `AbstractConnectionGroup` and 
`ConnectionGroup` and `Identifiable` and not seeing a constructor that actually 
takes these arguments and initializes the various objects?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-08 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r186855115
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnection;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of a directory to stored Connection objects
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The connections to store.
+ */
+private final Map connections =
+new HashMap();
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private AtomicInteger connectionId;
+
+/**
+ * Creates a new QuickConnectDirectory with the default
+ * empty Map for Connection objects, and the specified
+ * ConnectionGroup at the root of the directory.
+ *
+ * @param rootGroup
+ * A group that should be at the root of this directory.
+ */
+public QuickConnectDirectory(ConnectionGroup rootGroup) {
+this.rootGroup = (QuickConnectionGroup)rootGroup;
+this.connectionId = new AtomicInteger();
+super.setObjects(this.connections);
+}
+
+/**
+ * Returns the current connection identifier counter and
+ * then increments it.
+ *
+ * @return
+ * An int representing the next available connection
+ * identifier to be used when adding connections.
+ */
+private int getNextConnectionID() {
+return connectionId.getAndIncrement();
+}
+
+@Override
+public void add(Connection connection) throws GuacamoleException {
+connections.put(connection.getIdentifier(), connection);
+}
+
+/**
+ * Create a SimpleConnection object from a GuacamoleConfiguration,
+ * obtain an identifier, and place it on the tree, returning the
+ * identifier value of the new connection.
+ *
+ * @param config
+ * The GuacamoleConfiguration to use to create the
+ * SimpleConnection object.
+ *
+ * @return
+ * The identifier of the connection created in the directory.
+ *
+ * @throws GuacamoleException
+ * If an error occurs adding the object to the tree.
+ */
+public String create(GuacamoleConfiguration config) throws 
GuacamoleException {
+
+// Get the next connection identifier.
+String connectionId = Integer.toString(getNextConnectionID());
+
+// Generate a name for the configuration.
+String name = QCParser.getName(config);
+
+// Create a new connection and set the parent identifier.
+Connection connection = new SimpleConnection(name, connectionId, 
config);
+connection.setParentIdentifier(ROOT_IDENTIFIER);
--- End diff --

You could manually elect 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-08 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r186844828
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to generate a GuacamoleConfiguration object.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to use if one is not provided in
+ * the incoming URI.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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 GuacamoleConfiguration
+ * from that string, or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+
+// Break out individual components of the URI.
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+
+String username = null;
+String password = null;
+Map queryParams = null;
--- End diff --

There are a few cases here of the general form:

```java
String foo = null;

if (someCondition) {
foo = somethingThatNeverReturnsNull();
}

if (foo != null) {
doMoreThings(foo);
}
```

This is really taking what is effectively one condition and splitting it 
across two separate `if` blocks. The unnecessary initialization and unnecessary 
split can both be removed by collapsing into:

```java
if (someCondition) {
String foo = somethingThatNeverReturnsNull();
doMoreThings(foo);
}
```

The logic is a bit tangled otherwise.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-05-08 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r186840042
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
 ---
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AbstractUserContext;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.Directory;
+import org.apache.guacamole.net.auth.User;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
+import org.apache.guacamole.net.auth.simple.SimpleUser;
+
+/**
+ * A simple implementation of UserContext to support the QuickConnect
+ * extension, used for storing connections the user has created
+ * with the QuickConnect bar in the webapp.
+ */
+public class QuickConnectUserContext extends AbstractUserContext {
+
+/**
+ * The AuthenticationProvider that created this UserContext.
+ */
+private final AuthenticationProvider authProvider;
+
+/**
+ * Reference to the user whose permissions dictate the configurations
+ * accessible within this UserContext.
+ */
+private final User self;
+
+/**
+ * The Directory with access to all connections within the root group
+ * associated with this UserContext.
+ */
+private final QuickConnectDirectory connectionDirectory;
+
+/**
+ * The root connection group.
+ */
+private final ConnectionGroup rootGroup;
+
+/**
+ * Construct a QuickConnectUserContext using the authProvider and
+ * the username.
+ *
+ * @param authProvider
+ * The authentication provider module instantiating this
+ * this class.
+ *
+ * @param username
+ * The name of the user logging in and using this class.
+ */
+public QuickConnectUserContext(AuthenticationProvider authProvider,
+String username) {
+
+// Initialize the rootGroup to a basic connection group with a
+// single root identifier.
+this.rootGroup = new QuickConnectionGroup(
+DEFAULT_ROOT_CONNECTION_GROUP,
+DEFAULT_ROOT_CONNECTION_GROUP
+);
+
+// Initialize the user to a SimpleUser with the provided username,
+// no connections, and the single root group.
+this.self = new SimpleUser(username,
+Collections.emptyList(),
--- End diff --

This will only be correct when no connections exist. Once at least one 
connection is added, the permissions stored within this `SimpleUser` will not 
match up with the connections they are supposed to be able to read.

I'd recommend instead returning a new `SimpleUser` from `self()`, using 
`connectionDirectory.getIdentifiers()` to pull the set of readable connections.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-29 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r184894709
  
--- Diff: extensions/guacamole-auth-quickconnect/src/licenses/LICENSE ---
@@ -0,0 +1,221 @@
+
+ Apache License
+   Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+  "License" shall mean the terms and conditions for use, reproduction,
+  and distribution as defined by Sections 1 through 9 of this document.
+
+  "Licensor" shall mean the copyright owner or entity authorized by
+  the copyright owner that is granting the License.
+
+  "Legal Entity" shall mean the union of the acting entity and all
+  other entities that control, are controlled by, or are under common
+  control with that entity. For the purposes of this definition,
+  "control" means (i) the power, direct or indirect, to cause the
+  direction or management of such entity, whether by contract or
+  otherwise, or (ii) ownership of fifty percent (50%) or more of the
+  outstanding shares, or (iii) beneficial ownership of such entity.
+
+  "You" (or "Your") shall mean an individual or Legal Entity
+  exercising permissions granted by this License.
+
+  "Source" form shall mean the preferred form for making modifications,
+  including but not limited to software source code, documentation
+  source, and configuration files.
+
+  "Object" form shall mean any form resulting from mechanical
+  transformation or translation of a Source form, including but
+  not limited to compiled object code, generated documentation,
+  and conversions to other media types.
+
+  "Work" shall mean the work of authorship, whether in Source or
+  Object form, made available under the License, as indicated by a
+  copyright notice that is included in or attached to the work
+  (an example is provided in the Appendix below).
+
+  "Derivative Works" shall mean any work, whether in Source or Object
+  form, that is based on (or derived from) the Work and for which the
+  editorial revisions, annotations, elaborations, or other 
modifications
+  represent, as a whole, an original work of authorship. For the 
purposes
+  of this License, Derivative Works shall not include works that remain
+  separable from, or merely link (or bind by name) to the interfaces 
of,
+  the Work and Derivative Works thereof.
+
+  "Contribution" shall mean any work of authorship, including
+  the original version of the Work and any modifications or additions
+  to that Work or Derivative Works thereof, that is intentionally
+  submitted to Licensor for inclusion in the Work by the copyright 
owner
+  or by an individual or Legal Entity authorized to submit on behalf of
+  the copyright owner. For the purposes of this definition, "submitted"
+  means any form of electronic, verbal, or written communication sent
+  to the Licensor or its representatives, including but not limited to
+  communication on electronic mailing lists, source code control 
systems,
+  and issue tracking systems that are managed by, or on behalf of, the
+  Licensor for the purpose of discussing and improving the Work, but
+  excluding communication that is conspicuously marked or otherwise
+  designated in writing by the copyright owner as "Not a Contribution."
+
+  "Contributor" shall mean Licensor and any individual or Legal Entity
+  on behalf of whom a Contribution has been received by Licensor and
+  subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+  this License, each Contributor hereby grants to You a perpetual,
+  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+  copyright license to reproduce, prepare Derivative Works of,
+  publicly display, publicly perform, sublicense, and distribute the
+  Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+  this License, each Contributor hereby grants to You a perpetual,
+  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+  (except as stated in this section) patent license to make, have made,
+  use, offer to sell, sell, import, and otherwise transfer the Work,
+  where such license applies only to those patent claims licensable
  

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-29 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r184893989
  
--- Diff: extensions/guacamole-auth-quickconnect/src/licenses/LICENSE ---
@@ -0,0 +1,221 @@
+
+ Apache License
+   Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+  "License" shall mean the terms and conditions for use, reproduction,
+  and distribution as defined by Sections 1 through 9 of this document.
+
+  "Licensor" shall mean the copyright owner or entity authorized by
+  the copyright owner that is granting the License.
+
+  "Legal Entity" shall mean the union of the acting entity and all
+  other entities that control, are controlled by, or are under common
+  control with that entity. For the purposes of this definition,
+  "control" means (i) the power, direct or indirect, to cause the
+  direction or management of such entity, whether by contract or
+  otherwise, or (ii) ownership of fifty percent (50%) or more of the
+  outstanding shares, or (iii) beneficial ownership of such entity.
+
+  "You" (or "Your") shall mean an individual or Legal Entity
+  exercising permissions granted by this License.
+
+  "Source" form shall mean the preferred form for making modifications,
+  including but not limited to software source code, documentation
+  source, and configuration files.
+
+  "Object" form shall mean any form resulting from mechanical
+  transformation or translation of a Source form, including but
+  not limited to compiled object code, generated documentation,
+  and conversions to other media types.
+
+  "Work" shall mean the work of authorship, whether in Source or
+  Object form, made available under the License, as indicated by a
+  copyright notice that is included in or attached to the work
+  (an example is provided in the Appendix below).
+
+  "Derivative Works" shall mean any work, whether in Source or Object
+  form, that is based on (or derived from) the Work and for which the
+  editorial revisions, annotations, elaborations, or other 
modifications
+  represent, as a whole, an original work of authorship. For the 
purposes
+  of this License, Derivative Works shall not include works that remain
+  separable from, or merely link (or bind by name) to the interfaces 
of,
+  the Work and Derivative Works thereof.
+
+  "Contribution" shall mean any work of authorship, including
+  the original version of the Work and any modifications or additions
+  to that Work or Derivative Works thereof, that is intentionally
+  submitted to Licensor for inclusion in the Work by the copyright 
owner
+  or by an individual or Legal Entity authorized to submit on behalf of
+  the copyright owner. For the purposes of this definition, "submitted"
+  means any form of electronic, verbal, or written communication sent
+  to the Licensor or its representatives, including but not limited to
+  communication on electronic mailing lists, source code control 
systems,
+  and issue tracking systems that are managed by, or on behalf of, the
+  Licensor for the purpose of discussing and improving the Work, but
+  excluding communication that is conspicuously marked or otherwise
+  designated in writing by the copyright owner as "Not a Contribution."
+
+  "Contributor" shall mean Licensor and any individual or Legal Entity
+  on behalf of whom a Contribution has been received by Licensor and
+  subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+  this License, each Contributor hereby grants to You a perpetual,
+  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+  copyright license to reproduce, prepare Derivative Works of,
+  publicly display, publicly perform, sublicense, and distribute the
+  Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+  this License, each Contributor hereby grants to You a perpetual,
+  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+  (except as stated in this section) patent license to make, have made,
+  use, offer to sell, sell, import, and otherwise transfer the Work,
+  where such license applies only to those patent claims licensable
 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-28 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r184853372
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/licenses/bundled/aopalliance-1.0/LICENSE
 ---
@@ -0,0 +1,4 @@
+From http://aopalliance.sourceforge.net/:
--- End diff --

Removed.  Added the license for JUnit, since I'm doing tests with that.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-27 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r184813371
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/licenses/bundled/aopalliance-1.0/LICENSE
 ---
@@ -0,0 +1,4 @@
+From http://aopalliance.sourceforge.net/:
--- End diff --

Is this still bundled? Looking at the `pom.xml`, I no longer see any 
dependencies that are not marked as provided.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182735738
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+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.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * Logger for this class.
+ */
+private final static Logger logger = 
LoggerFactory.getLogger(QCParser.class);
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.isEmpty())
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.isEmpty())
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.isEmpty())
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.isEmpty()) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182714041
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -131,7 +141,14 @@ public static GuacamoleConfiguration 
getConfiguration(String uri)
 if (paramList != null) {
 for (String parameter : paramList) {
 String[] paramArray = parameter.split("=", 2);
-qcConfig.setParameter(paramArray[0],paramArray[1]);
+try {
+qcConfig.setParameter(URLDecoder.decode(paramArray[0], 
"UTF-8"),
--- End diff --

If I do that, though, don't I lose the ability to tell the difference 
between the "&" characters that separate the various parameters from one 
another and the ones that might be encoded in a parameter name or value?  Same 
with the "=" characters - seems like I would lose the ability to tell the 
difference between a "=" that separates a parameter name from a value and one 
that's encoded as part of the parameter name or value?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182713552
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -164,23 +165,23 @@ public static String getName(GuacamoleConfiguration 
config)
 String port = config.getParameter("port");
 String user = config.getParameter("username");
 
-String name = "";
+StringBuilder name = new StringBuilder("");
--- End diff --

Tweaked.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182713621
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+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.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * Logger for this class.
+ */
+private final static Logger logger = 
LoggerFactory.getLogger(QCParser.class);
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.isEmpty())
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.isEmpty())
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.isEmpty())
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.isEmpty()) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread ceharris
Github user ceharris commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182706319
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -131,7 +141,14 @@ public static GuacamoleConfiguration 
getConfiguration(String uri)
 if (paramList != null) {
 for (String parameter : paramList) {
 String[] paramArray = parameter.split("=", 2);
-qcConfig.setParameter(paramArray[0],paramArray[1]);
+try {
+qcConfig.setParameter(URLDecoder.decode(paramArray[0], 
"UTF-8"),
--- End diff --

Might make sense to apply `URLDecoder.decode` to the entire query string 
once.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182706233
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+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.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * Logger for this class.
+ */
+private final static Logger logger = 
LoggerFactory.getLogger(QCParser.class);
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.isEmpty())
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.isEmpty())
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.isEmpty())
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.isEmpty()) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread ceharris
Github user ceharris commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182705944
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -164,23 +165,23 @@ public static String getName(GuacamoleConfiguration 
config)
 String port = config.getParameter("port");
 String user = config.getParameter("username");
 
-String name = "";
+StringBuilder name = new StringBuilder("");
--- End diff --

Just a minor nit, but `new StringBuilder()` starts out empty.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread ceharris
Github user ceharris commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182705248
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.StringBuilder;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+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.GuacamoleServerException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * Logger for this class.
+ */
+private final static Logger logger = 
LoggerFactory.getLogger(QCParser.class);
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.isEmpty())
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.isEmpty())
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.isEmpty())
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.isEmpty()) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182695572
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
--- End diff --

Okay, I took a stab at handling encoded parameters.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-19 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182687363
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182294534
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
--- End diff --

Yeah, good point.  Any pointers for how to handle this?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182294077
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182293749
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182293830
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182292287
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/services/quickConnectService.js
 ---
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Service for managing quickConnect extension.
+ */
+angular.module('guacQuickConnect').factory('quickConnectService', 
['$injector',
+function quickConnectService($injector) {
+
+// Required services
+var $http = $injector.get('$http');
+var authenticationService = $injector.get('authenticationService');
+var cacheService  = $injector.get('cacheService');
+
+var service = {};
+
+/**
+ * Makes a request to the REST API to create a connection, returning a
+ * promise that can be used for processing the results of the call.
+ * 
+ * @param {uri} The URI of the connection to create.
+ *  
+ * @returns {Promise}
+ * A promise for the HTTP call which will succeed if and only if 
the
+ * save operation is successful.
+ */
+service.createConnection = function createConnection(uri) {
+
+// Build HTTP parameters set
+var httpParameters = {
+token : authenticationService.getCurrentToken()
+};
+
+return $http({
+method  : 'POST',
+url : 'api/session/ext/quickconnect/create',
+params  : httpParameters,
+data: $.param({uri: uri }),
--- End diff --

For some reason, it doesn't seem to be working for me.  Not sure if it's 
how the REST class is picking it up or what, but if I try to just put `data : 
uri` there, I get a `NullPointerException` when it posts to that endpoint.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291582
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291541
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/controllers/quickconnectController.js
 ---
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The controller for making ad-hoc (quick) connections
+ */
+angular.module('guacQuickConnect').controller('quickconnectController', 
['$scope', '$injector', '$log',
+function manageConnectionController($scope, $injector, $log) {
+
+// Required types
+var ClientIdentifier= $injector.get('ClientIdentifier');
+
+// Required services
+var $location= $injector.get('$location');
+var guacNotification = $injector.get('guacNotification');
+var quickConnectService  = $injector.get('quickConnectService');
+
+/**
+ * An action to be provided along with the object sent to showStatus 
which
+ * closes the currently-shown status dialog.
+ */
+var ACKNOWLEDGE_ACTION = {
+name: "MANAGE_CONNECTION.ACTION_ACKNOWLEDGE",
+// Handle action
+callback: function acknowledgeCallback() {
+guacNotification.showStatus(false);
+}
+};
+
+$scope.uri = null;
--- End diff --

Documented.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291437
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnection.java
 ---
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.simple.SimpleConnection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A type of Connection specific to this authentication extension.
+ */
+public class QuickConnection extends SimpleConnection {
+
+/**
+ * Number of active connections.
+ */
+private int activeConnections;
--- End diff --

If by "this" you mean `this` as in the entire class, then, yes.  Removed 
this and just using `SimpleConnection` class.  I was thinking about doing 
something with active connections in the QuickConnect extension once upon a 
time, but it doesn't seem like it has much value.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291353
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
 ---
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AbstractUserContext;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.Directory;
+import org.apache.guacamole.net.auth.User;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
+import org.apache.guacamole.net.auth.simple.SimpleUser;
+
+/**
+ * A simple implementation of UserContext to support the QuickConnect
+ * extension, primarily used for storing connections the user has
+ * created using the QuickConnect bar in the webapp.
+ */
+public class QuickConnectUserContext extends AbstractUserContext {
+
+/**
+ * The AuthenticationProvider that created this UserContext.
+ */
+private final AuthenticationProvider authProvider;
+
+/**
+ * Reference to the user whose permissions dictate the configurations
+ * accessible within this UserContext.
+ */
+private final User self;
+
+/**
+ * The Directory with access only to the User associated with this
+ * UserContext.
+ */
+private final Directory userDirectory;
+
+/**
+ * The Directory with access only to the root group associated with 
this
+ * UserContext.
+ */
+private final Directory connectionGroupDirectory;
+
+/**
+ * The Directory with access to all connections within the root group
+ * associated with this UserContext.
+ */
+private final QuickConnectDirectory connectionDirectory;
+
+/**
+ * The root connection group.
+ */
+private final ConnectionGroup rootGroup;
+
+/**
+ * Construct a QuickConnectUserContext using the authProvider and
+ * the username.
+ *
+ * @param authProvider
+ * The authentication provider module instantiating this
+ * this class.
+ *
+ * @param username
+ * The name of the user logging in and using this class.
+ */
+public QuickConnectUserContext(AuthenticationProvider authProvider,
+String username) {
+
+// Initialize the rootGroup to a basic connection group with a
+// single root identifier.
+this.rootGroup = new QuickConnectConnectionGroup(
+DEFAULT_ROOT_CONNECTION_GROUP,
+DEFAULT_ROOT_CONNECTION_GROUP
+);
+
+// Initialize the user to a SimpleUser with the username, no
+// preexisting connections, and the single root group.
+this.self = new SimpleUser(username,
+Collections.emptyList(),
+Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
+);
+
+// Initialize each of the directories associated with the 
userContext.
+this.userDirectory = new SimpleDirectory(self);
+this.connectionDirectory = new 
QuickConnectDirectory(this.rootGroup);
+this.connectionGroupDirectory = new 
SimpleDirectory(Collections.singleton(this.rootGroup));
--- End diff --

Well we should probably not bother doing that, then.  Removed.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291064
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
 ---
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.AbstractAuthenticationProvider;
+import org.apache.guacamole.net.auth.UserContext;
+
+/**
+ * Class providing the necessary hooks into the Guacamole Client 
authentication
+ * process so that the QuickConnect functionality can be initialized and 
be used
+ * throughout the web client.
+ */
+public class QuickConnectAuthenticationProvider extends 
AbstractAuthenticationProvider {
+
+/**
+ * userContext for this authentication provider.
+ */
+private UserContext userContext;
+
+@Override
+public String getIdentifier() {
+return "quickconnect";
+}
+
+@Override
+public UserContext getUserContext(AuthenticatedUser authenticatedUser)
+throws GuacamoleException {
+
+if (userContext == null)
+userContext = new QuickConnectUserContext(this,
+authenticatedUser.getIdentifier());
--- End diff --

Should be good, now.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291087
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProviderModule.java
 ---
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import com.google.inject.AbstractModule;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+
+/**
+ * Guice module to do QuickConnect injections.
+ */
+public class QuickConnectAuthenticationProviderModule extends 
AbstractModule {
+
+/**
+ * Guacamole server environment.
+ */
+private final Environment environment;
+
+/**
+ * QuickConnect authentication provider.
+ */
+private final AuthenticationProvider authProvider;
+
+/**
+ * Create a new instance of the authentication provider module
+ * which configures injection for the 
QuickConnectAuthenticationProvider
+ * class.
+ *
+ * @param authProvider
+ * The authentication provider for which injection is being
+ * configured.
+ *
+ * @throws GuacamoleException
+ * If an error occurs while retrieving the server environment.
+ */
+public QuickConnectAuthenticationProviderModule(AuthenticationProvider 
authProvider)
--- End diff --

Removed the whole class.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182291039
  
--- Diff: extensions/guacamole-auth-quickconnect/src/licenses/NOTICE ---
@@ -0,0 +1,5 @@
+Apache Guacamole
+Copyright 2017 The Apache Software Foundation
--- End diff --

Just reliving the glory days.  Fixed.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182214035
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProviderModule.java
 ---
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import com.google.inject.AbstractModule;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+
+/**
+ * Guice module to do QuickConnect injections.
+ */
+public class QuickConnectAuthenticationProviderModule extends 
AbstractModule {
+
+/**
+ * Guacamole server environment.
+ */
+private final Environment environment;
+
+/**
+ * QuickConnect authentication provider.
+ */
+private final AuthenticationProvider authProvider;
+
+/**
+ * Create a new instance of the authentication provider module
+ * which configures injection for the 
QuickConnectAuthenticationProvider
+ * class.
+ *
+ * @param authProvider
+ * The authentication provider for which injection is being
+ * configured.
+ *
+ * @throws GuacamoleException
+ * If an error occurs while retrieving the server environment.
+ */
+public QuickConnectAuthenticationProviderModule(AuthenticationProvider 
authProvider)
--- End diff --

Actually, I also don't see `@Inject` anywhere. Is Guice being used here at 
all? Perhaps this is unneeded.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182208615
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182206171
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnection.java
 ---
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.simple.SimpleConnection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A type of Connection specific to this authentication extension.
+ */
+public class QuickConnection extends SimpleConnection {
+
+/**
+ * Number of active connections.
+ */
+private int activeConnections;
--- End diff --

Is this unused?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182212844
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182208675
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/controllers/quickconnectController.js
 ---
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The controller for making ad-hoc (quick) connections
+ */
+angular.module('guacQuickConnect').controller('quickconnectController', 
['$scope', '$injector', '$log',
+function manageConnectionController($scope, $injector, $log) {
+
+// Required types
+var ClientIdentifier= $injector.get('ClientIdentifier');
+
+// Required services
+var $location= $injector.get('$location');
+var guacNotification = $injector.get('guacNotification');
+var quickConnectService  = $injector.get('quickConnectService');
+
+/**
+ * An action to be provided along with the object sent to showStatus 
which
+ * closes the currently-shown status dialog.
+ */
+var ACKNOWLEDGE_ACTION = {
+name: "MANAGE_CONNECTION.ACTION_ACKNOWLEDGE",
+// Handle action
+callback: function acknowledgeCallback() {
+guacNotification.showStatus(false);
+}
+};
+
+$scope.uri = null;
--- End diff --

Document please.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182206999
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182202689
  
--- Diff: extensions/guacamole-auth-quickconnect/src/licenses/NOTICE ---
@@ -0,0 +1,5 @@
+Apache Guacamole
+Copyright 2017 The Apache Software Foundation
--- End diff --

2018. ;)


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182206011
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectUserContext.java
 ---
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import org.apache.guacamole.auth.quickconnect.rest.QuickConnectREST;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AbstractUserContext;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.Directory;
+import org.apache.guacamole.net.auth.User;
+import org.apache.guacamole.net.auth.simple.SimpleDirectory;
+import org.apache.guacamole.net.auth.simple.SimpleUser;
+
+/**
+ * A simple implementation of UserContext to support the QuickConnect
+ * extension, primarily used for storing connections the user has
+ * created using the QuickConnect bar in the webapp.
+ */
+public class QuickConnectUserContext extends AbstractUserContext {
+
+/**
+ * The AuthenticationProvider that created this UserContext.
+ */
+private final AuthenticationProvider authProvider;
+
+/**
+ * Reference to the user whose permissions dictate the configurations
+ * accessible within this UserContext.
+ */
+private final User self;
+
+/**
+ * The Directory with access only to the User associated with this
+ * UserContext.
+ */
+private final Directory userDirectory;
+
+/**
+ * The Directory with access only to the root group associated with 
this
+ * UserContext.
+ */
+private final Directory connectionGroupDirectory;
+
+/**
+ * The Directory with access to all connections within the root group
+ * associated with this UserContext.
+ */
+private final QuickConnectDirectory connectionDirectory;
+
+/**
+ * The root connection group.
+ */
+private final ConnectionGroup rootGroup;
+
+/**
+ * Construct a QuickConnectUserContext using the authProvider and
+ * the username.
+ *
+ * @param authProvider
+ * The authentication provider module instantiating this
+ * this class.
+ *
+ * @param username
+ * The name of the user logging in and using this class.
+ */
+public QuickConnectUserContext(AuthenticationProvider authProvider,
+String username) {
+
+// Initialize the rootGroup to a basic connection group with a
+// single root identifier.
+this.rootGroup = new QuickConnectConnectionGroup(
+DEFAULT_ROOT_CONNECTION_GROUP,
+DEFAULT_ROOT_CONNECTION_GROUP
+);
+
+// Initialize the user to a SimpleUser with the username, no
+// preexisting connections, and the single root group.
+this.self = new SimpleUser(username,
+Collections.emptyList(),
+Collections.singleton(DEFAULT_ROOT_CONNECTION_GROUP)
+);
+
+// Initialize each of the directories associated with the 
userContext.
+this.userDirectory = new SimpleDirectory(self);
+this.connectionDirectory = new 
QuickConnectDirectory(this.rootGroup);
+this.connectionGroupDirectory = new 
SimpleDirectory(Collections.singleton(this.rootGroup));
--- End diff --

This is actually the default behavior of `AbstractUserContext`. If not 
overridden, the `getConnectionGroup()` function returns a directory containing 
only the root group.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182205689
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProviderModule.java
 ---
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import com.google.inject.AbstractModule;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+import org.apache.guacamole.net.auth.AuthenticationProvider;
+
+/**
+ * Guice module to do QuickConnect injections.
+ */
+public class QuickConnectAuthenticationProviderModule extends 
AbstractModule {
+
+/**
+ * Guacamole server environment.
+ */
+private final Environment environment;
+
+/**
+ * QuickConnect authentication provider.
+ */
+private final AuthenticationProvider authProvider;
+
+/**
+ * Create a new instance of the authentication provider module
+ * which configures injection for the 
QuickConnectAuthenticationProvider
+ * class.
+ *
+ * @param authProvider
+ * The authentication provider for which injection is being
+ * configured.
+ *
+ * @throws GuacamoleException
+ * If an error occurs while retrieving the server environment.
+ */
+public QuickConnectAuthenticationProviderModule(AuthenticationProvider 
authProvider)
--- End diff --

Where is this being used? It looks like the extension depends on this, but 
I don't see this constructor invoked anywhere.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182210966
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+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;
+
+/**
+ * A utility class to parse out a URI into the settings necessary
+ * to create and establish a Guacamole connection.
+ */
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is provided in
+ * the incoming URI..
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+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.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+int port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+
+Matcher userinfoMatcher = userinfoPattern.matcher(userInfo);
+if (userinfoMatcher.matches()) {
+username = userinfoMatcher.group(USERNAME_GROUP);
+password = userinfoMatcher.group(PASSWORD_GROUP);
+}
+
+}
+
+GuacamoleConfiguration qcConfig = new GuacamoleConfiguration();
+qcConfig.setProtocol(protocol);
+qcConfig.setParameter("hostname",host);
+
+if (port > 0)
+qcConfig.setParameter("port", Integer.toString(port));
+
+if (username != null && username.length() > 0)
+

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-04-17 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r182210507
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/services/quickConnectService.js
 ---
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Service for managing quickConnect extension.
+ */
+angular.module('guacQuickConnect').factory('quickConnectService', 
['$injector',
+function quickConnectService($injector) {
+
+// Required services
+var $http = $injector.get('$http');
+var authenticationService = $injector.get('authenticationService');
+var cacheService  = $injector.get('cacheService');
+
+var service = {};
+
+/**
+ * Makes a request to the REST API to create a connection, returning a
+ * promise that can be used for processing the results of the call.
+ * 
+ * @param {uri} The URI of the connection to create.
+ *  
+ * @returns {Promise}
+ * A promise for the HTTP call which will succeed if and only if 
the
+ * save operation is successful.
+ */
+service.createConnection = function createConnection(uri) {
+
+// Build HTTP parameters set
+var httpParameters = {
+token : authenticationService.getCurrentToken()
+};
+
+return $http({
+method  : 'POST',
+url : 'api/session/ext/quickconnect/create',
+params  : httpParameters,
+data: $.param({uri: uri }),
--- End diff --

I believe this will happen automatically - no need to explicitly serialize 
with `$.param()`. For example:


https://github.com/apache/guacamole-client/blob/aac9d8795cb257b259259097fff8c540439d746b/guacamole/src/main/webapp/app/rest/services/userService.js#L168-L179


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-25 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176950410
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (port == -1 || port < 1)
+port = DEFAULT_URI_PORT;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+String[] authenticators = userInfo.split(":");
--- End diff --

Switched to RegEx.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-25 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176950390
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (port == -1 || port < 1)
+port = DEFAULT_URI_PORT;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+String[] authenticators = userInfo.split(":");
+if (authenticators.length > 0 && authenticators[0] != null)
--- End diff --

Should be cleaned up, now, with move to regex.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-25 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176950360
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (port == -1 || port < 1)
+port = DEFAULT_URI_PORT;
+
+if (query != null && !query.equals(""))
+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)
--- End diff --

Okay, implemented regex and Pattern/Matcher for this.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176926882
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
--- End diff --

Switched to int.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176926889
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/styles/quickconnect.css
 ---
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+.quickconnect-container {
+margin: 0.5em 0;
+width: 100%;
+}
+
+.quickconnect-container .quickconnect-field {
+background-image: url('images/protocol-icons/guac-text.png');
+background-repeat: no-repeat;
+background-size: 1.75em;
+background-position: 0.25em center;
+background-color: transparent;
+padding: 0.5em;
+padding-left: 2.25em;
+width: 100%;
+max-width: none;
+border: 0;
+border-left: 1px solid rgba(0,0,0,0.125);
+box-sizing: border-box;
+}
+
+.quickconnect-field input[type="submit"] {
--- End diff --

Nope.  Removed.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176926671
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/templates/quickconnectField.html
 ---
@@ -0,0 +1,9 @@
+
+
+
+
+
--- End diff --

Done.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176926472
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
 ---
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
+import 
org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
+import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Class providing the necessary hooks into the Guacamole Client 
authentication
+ * process so that the QuickConnect functionality can be initialized and 
be used
+ * throughout the web client.
+ */
+public class QuickConnectAuthenticationProvider extends 
SimpleAuthenticationProvider {
--- End diff --

Implemented.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176924407
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (port == -1 || port < 1)
+port = DEFAULT_URI_PORT;
+
+if (query != null && !query.equals(""))
+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)
--- End diff --

I haven't found a class that parses the username and password into separate 
components - even the URI and URL classes that have methods for grabbing the 
"user-info" part of the string (including both username and password) don't 
seem to have methods for splitting it out to individual components.  I'll work 
on the regex route.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176924286
  
--- Diff: extensions/guacamole-auth-quickconnect/pom.xml ---
@@ -0,0 +1,209 @@
+
+
+http://maven.apache.org/POM/4.0.0;
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+http://maven.apache.org/maven-v4_0_0.xsd;>
+
+4.0.0
+org.apache.guacamole
+guacamole-auth-quickconnect
+jar
+0.9.14
+guacamole-auth-quickconnect
+http://guacamole.apache.org/
+
+
+UTF-8
+
+
+
+
+
+
+
+org.apache.maven.plugins
+maven-compiler-plugin
+3.3
+
+1.6
+1.6
+
+-Xlint:all
+-Werror
+
+true
+
+
+
+
+
+org.apache.maven.plugins
+maven-dependency-plugin
+2.10
+
+
+unpack-dependencies
+prepare-package
+
+unpack-dependencies
+
+
+runtime
+
${project.build.directory}/classes
+
+
+
+
+
+
+
+maven-assembly-plugin
+2.5.3
+
+
${project.artifactId}-${project.version}
+false
+
+src/main/assembly/dist.xml
+
+
+
+
+make-dist-archive
+package
+
+single
+
+
+
+
+
+
+
+com.samaxes.maven
+minify-maven-plugin
+1.7.5
+
+
+default-cli
+
+UTF-8
+
+
${basedir}/src/main/resources
+
${project.build.directory}/classes
+
+/
+/
+quickconnect.css
+
+
+
**/*.css
+
+
+/
+/
+quickconnect.js
+
+
+**/*.js
+
+
+
+
+
**/*.test.js
+
+CLOSURE
+
+
+
+
OFF
+OFF
+
+
+
+
+minify
+
+
+
+
+
+
+
+org.apache.rat
+apache-rat-plugin
+0.12
+
+
+
+**/*.json
+src/licenses/**/*
+
src/main/resources/templates/*.html
+
+
+
+
+
+
+validate
+validate
+
+check
+
+
+
+
+
+
+
+
+
+
+
+
+
+org.apache.guacamole
+guacamole-ext
+0.9.14
+provided
+
+
+
+
+  

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176924294
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
--- End diff --

Documented.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176924292
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
--- End diff --

Cleaned this up.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176921682
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
 ---
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
+import 
org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
+import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Class providing the necessary hooks into the Guacamole Client 
authentication
+ * process so that the QuickConnect functionality can be initialized and 
be used
+ * throughout the web client.
+ */
+public class QuickConnectAuthenticationProvider extends 
SimpleAuthenticationProvider {
--- End diff --

...even though doing so greatly reduces the amount of code I have to write 
to overwrite methods that are doing exactly the same thing as 
`SimpleAuthenticationProvider` - like `shutdown()` and `decorate()` and 
`redecorate()` and probably a couple of others that I would basically just be 
copying/pasting code out of `SimpleAuthenticationProvider` to duplicate that 
functionality?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176921492
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectConnectionGroup.java
 ---
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnectionGroup;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+
+/**
+ * Provides a very simple, single-level connection group used
+ * for temporarily storing the QuickConnections created by
+ * users.
+ */
+class QuickConnectConnectionGroup extends AbstractConnectionGroup {
--- End diff --

Well, it's never expected to be used outside this package, but neither are 
a bunch of the other classes, so I should probably be consistent about it...


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920446
  
--- Diff: extensions/guacamole-auth-quickconnect/pom.xml ---
@@ -0,0 +1,209 @@
+
+
+http://maven.apache.org/POM/4.0.0;
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+http://maven.apache.org/maven-v4_0_0.xsd;>
+
+4.0.0
+org.apache.guacamole
+guacamole-auth-quickconnect
+jar
+0.9.14
+guacamole-auth-quickconnect
+http://guacamole.apache.org/
+
+
+UTF-8
+
+
+
+
+
+
+
+org.apache.maven.plugins
+maven-compiler-plugin
+3.3
+
+1.6
+1.6
+
+-Xlint:all
+-Werror
+
+true
+
+
+
+
+
+org.apache.maven.plugins
+maven-dependency-plugin
+2.10
+
+
+unpack-dependencies
+prepare-package
+
+unpack-dependencies
+
+
+runtime
+
${project.build.directory}/classes
+
+
+
+
+
+
+
+maven-assembly-plugin
+2.5.3
+
+
${project.artifactId}-${project.version}
+false
+
+src/main/assembly/dist.xml
+
+
+
+
+make-dist-archive
+package
+
+single
+
+
+
+
+
+
+
+com.samaxes.maven
+minify-maven-plugin
+1.7.5
+
+
+default-cli
+
+UTF-8
+
+
${basedir}/src/main/resources
+
${project.build.directory}/classes
+
+/
+/
+quickconnect.css
+
+
+
**/*.css
+
+
+/
+/
+quickconnect.js
+
+
+**/*.js
+
+
+
+
+
**/*.test.js
+
+CLOSURE
+
+
+
+
OFF
+OFF
+
+
+
+
+minify
+
+
+
+
+
+
+
+org.apache.rat
+apache-rat-plugin
+0.12
+
+
+
+**/*.json
+src/licenses/**/*
+
src/main/resources/templates/*.html
+
+
+
+
+
+
+validate
+validate
+
+check
+
+
+
+
+
+
+
+
+
+
+
+
+
+org.apache.guacamole
+guacamole-ext
+0.9.14
+provided
+
+
+
+
+ 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920168
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/templates/quickconnectField.html
 ---
@@ -0,0 +1,9 @@
+
+
+
+
+
--- End diff --

Strings which will be displayed to the user need to be defined as 
translation strings, rather than hard-coded in the HTML.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176919853
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
--- End diff --

With the exception of VNC, the various protocol implementations already 
have defined default ports which are used if the `port` parameter is unset. 
Forcing this to 22 for all protocols will result in confusion if SSH is not 
used.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920497
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
 ---
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
+import 
org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
+import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Class providing the necessary hooks into the Guacamole Client 
authentication
+ * process so that the QuickConnect functionality can be initialized and 
be used
+ * throughout the web client.
+ */
+public class QuickConnectAuthenticationProvider extends 
SimpleAuthenticationProvider {
--- End diff --

As you have your own underlying `UserContext` implementation (a good 
thing), you should not be extending `SimpleAuthenticationProvider` here.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920363
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/rest/QuickConnectREST.java
 ---
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.rest;
+
+import com.google.inject.Inject;
+import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.POST;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.apache.guacamole.auth.quickconnect.QuickConnection;
+import org.apache.guacamole.auth.quickconnect.QuickConnectDirectory;
+import org.apache.guacamole.auth.quickconnect.QuickConnectUserContext;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.Directory;
+
+/**
+ * A class to create and manage REST endpoints for the
+ * QuickConnect extension.
+ */
+@Produces(MediaType.APPLICATION_JSON)
+public class QuickConnectREST {
+
+/**
+ * The connection directory for this REST endpoint.
+ */
+private QuickConnectDirectory directory;
+
+/**
+ * The UserContext object for this REST endpoint.
+ */
+private QuickConnectUserContext userContext;
+
+/**
+ * Construct a new QuickConnectREST class, taking in the UserContext
+ * object that calls this constructor.
+ *
+ * @param userContext
+ * The UserContext object associated with this REST endpoint
+ *
+ * @throws GuacamoleException
+ * If the UserContext is unavailable or the directory object
+ * cannot be retrieved.
+ */
+public QuickConnectREST(QuickConnectUserContext userContext)
+throws GuacamoleException {
+this.userContext = userContext;
+this.directory = 
(QuickConnectDirectory)this.userContext.getConnectionDirectory();
+}
+
+/**
+ * Parse the URI read from the POST input, add the connection
+ * to the directory, and return the ID of the newly-created
+ * connection.
+ *
+ * @param uri
+ * The URI to parse into a connection.
+ *
+ * @return
+ * The ID of the connection in the directory.
+ *
+ * @throws GuacamoleException
+ * If an error is encountered parsing the URI.
+ */
+@POST
+@Path("create")
+public String create(@FormParam("uri") String uri) 
+throws GuacamoleException {
+
+if (directory == null)
--- End diff --

Will this ever be the case?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176919957
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
+String userInfo = qcUri.getUserInfo();
+String query = qcUri.getQuery();
+String username = null;
+String password = null;
+List paramList = null;
+
+if (protocol == null || protocol.equals(""))
+protocol = DEFAULT_URI_PROTOCOL;
+
+if (host == null || host.equals(""))
+host = DEFAULT_URI_HOST;
+
+if (port == -1 || port < 1)
+port = DEFAULT_URI_PORT;
+
+if (query != null && !query.equals(""))
+paramList = Arrays.asList(query.split("&"));
+
+if (userInfo != null && !userInfo.equals("")) {
+String[] authenticators = userInfo.split(":");
--- End diff --

Using `split(":")` will actually compile `":"` as a regular expression each 
time this is called.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920476
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectAuthenticationProvider.java
 ---
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.net.auth.AuthenticatedUser;
+import org.apache.guacamole.net.auth.Credentials;
+import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
+import 
org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
+import org.apache.guacamole.net.auth.simple.SimpleAuthenticationProvider;
+import org.apache.guacamole.net.auth.UserContext;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Class providing the necessary hooks into the Guacamole Client 
authentication
+ * process so that the QuickConnect functionality can be initialized and 
be used
+ * throughout the web client.
+ */
+public class QuickConnectAuthenticationProvider extends 
SimpleAuthenticationProvider {
+
+/**
+ * userContext for this authentication provider.
+ */
+private UserContext userContext;
+
+@Override
+public String getIdentifier() {
+return "quickconnect";
+}
+
+/**
+ * For QuickConnect, authenticateUser simply returns null because this
+ * extension is designed to provide only a connection directory to 
users
+ * that are already authenticated and not any actual authentication.
+ *
+ * @param credentials
+ * Credentials object passed in from Guacamole login.
+ *
+ * @return
+ * Returns null, which causes the client to move on to the next
+ * module.
+ */
+@Override
+public AuthenticatedUser authenticateUser(Credentials credentials)
+throws GuacamoleException {
+
+String username = credentials.getUsername();
+if (username == null || username.isEmpty())
+throw new GuacamoleInvalidCredentialsException("You must 
login.", CredentialsInfo.USERNAME_PASSWORD);
--- End diff --

If this extension will not perform authentication, why does it request a 
username and password?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920091
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
+ */
+public static final String DEFAULT_URI_PROTOCOL = "ssh";
+
+/**
+ * The default host to use if one is not defined.
+ */
+public static final String DEFAULT_URI_HOST = "localhost";
+
+/**
+ * The default port to use if one is not defined.
+ */
+public static final Integer DEFAULT_URI_PORT = 22;
+
+/**
+ * Parse out a URI string and get a connection from that string,
+ * or an exception if the parsing fails.
+ *
+ * @param uri
+ * The string form of the URI to be parsed.
+ *
+ * @return
+ * A GuacamoleConfiguration using a combination of the parsed
+ * URI values and default values when not specified in the
+ * URI.
+ *
+ * @throws GuacamoleException
+ * When an error occurs parsing the URI.
+ */
+public static GuacamoleConfiguration getConfiguration(String uri)
+throws GuacamoleException {
+
+URI qcUri;
+try {
+qcUri = new URI(uri);
+}
+catch (URISyntaxException e) {
+throw new GuacamoleClientException("Invalid URI Syntax", e);
+}
+String protocol = qcUri.getScheme();
+String host = qcUri.getHost();
+Integer port = qcUri.getPort();
--- End diff --

You should avoid using wrapper classes like this unnecessarily.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920196
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/resources/styles/quickconnect.css
 ---
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+.quickconnect-container {
+margin: 0.5em 0;
+width: 100%;
+}
+
+.quickconnect-container .quickconnect-field {
+background-image: url('images/protocol-icons/guac-text.png');
+background-repeat: no-repeat;
+background-size: 1.75em;
+background-position: 0.25em center;
+background-color: transparent;
+padding: 0.5em;
+padding-left: 2.25em;
+width: 100%;
+max-width: none;
+border: 0;
+border-left: 1px solid rgba(0,0,0,0.125);
+box-sizing: border-box;
+}
+
+.quickconnect-field input[type="submit"] {
--- End diff --

Is there an ``? I don't see one in the HTML.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920341
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/rest/QuickConnectREST.java
 ---
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.rest;
+
+import com.google.inject.Inject;
+import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.POST;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+import org.apache.guacamole.auth.quickconnect.QuickConnection;
+import org.apache.guacamole.auth.quickconnect.QuickConnectDirectory;
+import org.apache.guacamole.auth.quickconnect.QuickConnectUserContext;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.Directory;
+
+/**
+ * A class to create and manage REST endpoints for the
+ * QuickConnect extension.
+ */
+@Produces(MediaType.APPLICATION_JSON)
+public class QuickConnectREST {
+
+/**
+ * The connection directory for this REST endpoint.
+ */
+private QuickConnectDirectory directory;
+
+/**
+ * The UserContext object for this REST endpoint.
+ */
+private QuickConnectUserContext userContext;
+
+/**
+ * Construct a new QuickConnectREST class, taking in the UserContext
+ * object that calls this constructor.
+ *
+ * @param userContext
+ * The UserContext object associated with this REST endpoint
+ *
+ * @throws GuacamoleException
+ * If the UserContext is unavailable or the directory object
+ * cannot be retrieved.
+ */
+public QuickConnectREST(QuickConnectUserContext userContext)
+throws GuacamoleException {
+this.userContext = userContext;
+this.directory = 
(QuickConnectDirectory)this.userContext.getConnectionDirectory();
--- End diff --

If usages of `QuickConnectUserContext` must rely on 
`getConnectionDirectory()` returning a `QuickConnectDirectory`, it would be 
better to avoid requiring typecasting and explicitly declare that as the return 
type.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176920563
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectConnectionGroup.java
 ---
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleSecurityException;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnectionGroup;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+
+/**
+ * Provides a very simple, single-level connection group used
+ * for temporarily storing the QuickConnections created by
+ * users.
+ */
+class QuickConnectConnectionGroup extends AbstractConnectionGroup {
--- End diff --

Not necessarily an issue, but to confirm: is this intentionally 
package-private?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176919808
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
+
+/**
+ * The default protocol to parse to if one is undefined.
--- End diff --

What do you mean by "if one is undefined"?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-24 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r176919814
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/utility/QCParser.java
 ---
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect.utility;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.guacamole.GuacamoleClientException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+public class QCParser {
--- End diff --

This class needs to be documented.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-18 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175312723
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
--- End diff --

Switched to `int`.  I think the reason I went `Integer` is because there 
were a couple of places where it gets converted to a `String`.  I've replaced 
those with `Integer.toString()` calls with the primitive, so accomplishes the 
same thing.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-18 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175312540
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
+return CONNECTION_ID++;
--- End diff --

Went the AtomicInteger route - having the connections persist in-memory is 
(to me) a desired functionality, so that accomplishes thread-safeness without 
losing that.  Also cleaned up the code (like my oddly-named all-caps 
CONNECTION_ID) a little.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-18 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175305271
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
+return CONNECTION_ID++;
--- End diff --

Not persisting connections at all, and instead dynamically generating the 
returned `Connection` within `get()` (using the URL as the identifier) would be 
another option, assuming that persisting the connections in memory is not an 
intended feature.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-18 Thread ceharris
Github user ceharris commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175302700
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
+return CONNECTION_ID++;
--- End diff --

You want to be careful with `UUID.randomUUID()`. The underlying 
implementation uses `SecureRandom` which can block indefinitely waiting for 
sufficient entropy (e.g. in the kernel implementation of `/dev/random`). On a 
system with low activity this can be significant concern. 

`AtomicInteger.getAndIncrement` will give the same semantics as your use of 
the post-increment operator with thread safety. Performance is generally better 
than what you can do with your own `ReentrantLock` or (not recommended) an 
approach using `synchronized`.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-18 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175278875
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
--- End diff --

Really should use `int` unless there is a reason a wrapper class like 
`Integer` is necessary.


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-18 Thread mike-jumper
Github user mike-jumper commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175278827
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
+return CONNECTION_ID++;
+}
+
+@Override
+public void add(Connection object) throws GuacamoleException {
+
+put(new QuickConnection(object));
--- End diff --

Out of curiosity, is it an intended feature that these connections persist 
in memory until the end of the session? Or is that a side effect of the 
implementation, with the only goal being to provide some way to connect in an 
ad hoc manner?


---


[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-16 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175185303
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnection.java
 ---
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+import org.apache.guacamole.net.GuacamoleSocket;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.InetGuacamoleSocket;
+import org.apache.guacamole.net.SSLGuacamoleSocket;
+import org.apache.guacamole.net.SimpleGuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnection;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.ConnectionRecord;
+import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
+import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A type of Connection specific to this authentication extension.
+ */
+public class QuickConnection extends AbstractConnection {
+
+/**
+ * Backing configuration, containing all sensitive information.
+ */
+private GuacamoleConfiguration config;
+
+/**
+ * Number of active connections.
+ */
+private int activeConnections;
+
+/**
+ * Empty connection constructor.
+ */
+public QuickConnection() {
+
+}
+
+/**
+ * Constructor that takes a name, identifier, and 
GuacamoleConfiguration
+ * and builds a QuickConnection from it.
+ *
+ * @param name
+ * The name of the connection.
+ *
+ * @param identifier
+ * The unique identifier of this connection within this
+ * authentication module.
+ *
+ * @param config
+ * The GuacamoleConfiguration object to store in this
+ * QuickConnection.
+ */
+public QuickConnection(String name, String identifier,
+GuacamoleConfiguration config) {
+
+setName(name);
+
+setIdentifier(identifier);
+
+setConfiguration(config);
+this.config = config;
+
+this.activeConnections = 0;
+
+}
+
+/**
+ * Constructs a QuickConnection from a generic Connection
+ * object, copying over the relevant data and initializing
+ * the rest.
+ *
+ * @param object
+ * The generic Connection object to be copied.
+ */
+public QuickConnection(Connection object) {
+
+setName(object.getName());
+setIdentifier(object.getIdentifier());
+setParentIdentifier(object.getParentIdentifier());
+setConfiguration(object.getConfiguration());
+this.config = object.getConfiguration();
+this.activeConnections = 0;
+
+}
+
+@Override
+public int getActiveConnections() {
+return activeConnections;
+}
+
+@Override
+public Map getAttributes() {
+return Collections.emptyMap();
+}
+
+@Override
+public void setAttributes(Map attributes) {
+// Do nothing - there are no attributes
+}
+
+@Override
+public GuacamoleTunnel connect(GuacamoleClientInformation info)
+throws 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-16 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175181207
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnection.java
 ---
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+import org.apache.guacamole.net.GuacamoleSocket;
+import org.apache.guacamole.net.GuacamoleTunnel;
+import org.apache.guacamole.net.InetGuacamoleSocket;
+import org.apache.guacamole.net.SSLGuacamoleSocket;
+import org.apache.guacamole.net.SimpleGuacamoleTunnel;
+import org.apache.guacamole.net.auth.AbstractConnection;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.net.auth.ConnectionRecord;
+import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
+import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
+import org.apache.guacamole.protocol.GuacamoleClientInformation;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * A type of Connection specific to this authentication extension.
+ */
+public class QuickConnection extends AbstractConnection {
+
+/**
+ * Backing configuration, containing all sensitive information.
+ */
+private GuacamoleConfiguration config;
+
+/**
+ * Number of active connections.
+ */
+private int activeConnections;
+
+/**
+ * Empty connection constructor.
+ */
+public QuickConnection() {
+
+}
+
+/**
+ * Constructor that takes a name, identifier, and 
GuacamoleConfiguration
+ * and builds a QuickConnection from it.
+ *
+ * @param name
+ * The name of the connection.
+ *
+ * @param identifier
+ * The unique identifier of this connection within this
+ * authentication module.
+ *
+ * @param config
+ * The GuacamoleConfiguration object to store in this
+ * QuickConnection.
+ */
+public QuickConnection(String name, String identifier,
+GuacamoleConfiguration config) {
+
+setName(name);
+
+setIdentifier(identifier);
+
+setConfiguration(config);
+this.config = config;
+
+this.activeConnections = 0;
+
+}
+
+/**
+ * Constructs a QuickConnection from a generic Connection
+ * object, copying over the relevant data and initializing
+ * the rest.
+ *
+ * @param object
+ * The generic Connection object to be copied.
+ */
+public QuickConnection(Connection object) {
+
+setName(object.getName());
+setIdentifier(object.getIdentifier());
+setParentIdentifier(object.getParentIdentifier());
+setConfiguration(object.getConfiguration());
+this.config = object.getConfiguration();
+this.activeConnections = 0;
+
+}
+
+@Override
+public int getActiveConnections() {
+return activeConnections;
+}
+
+@Override
+public Map getAttributes() {
+return Collections.emptyMap();
+}
+
+@Override
+public void setAttributes(Map attributes) {
+// Do nothing - there are no attributes
+}
+
+@Override
+public GuacamoleTunnel connect(GuacamoleClientInformation info)
+throws 

[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...

2018-03-16 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/181#discussion_r175180850
  
--- Diff: 
extensions/guacamole-auth-quickconnect/src/main/java/org/apache/guacamole/auth/quickconnect/QuickConnectDirectory.java
 ---
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.quickconnect;
+
+import java.util.Collection;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.auth.quickconnect.utility.QCParser;
+import org.apache.guacamole.net.auth.ConnectionGroup;
+import org.apache.guacamole.net.auth.simple.SimpleConnectionDirectory;
+import org.apache.guacamole.net.auth.Connection;
+import org.apache.guacamole.protocol.GuacamoleConfiguration;
+
+/**
+ * Implementation of the Connection Directory, stored
+ * completely in-memory.
+ */
+public class QuickConnectDirectory extends SimpleConnectionDirectory {
+
+/**
+ * The unique identifier of the root connection group.
+ */
+private static final String ROOT_IDENTIFIER = "ROOT";
+
+/**
+ * The root connection group for this directory.
+ */
+private final QuickConnectConnectionGroup rootGroup;
+
+/**
+ * The internal counter for connection IDs.
+ */
+private int CONNECTION_ID = 0;
+
+/**
+ * Creates a new QuickConnectDirectory which provides access to the
+ * connections contained within the given Map.
+ *
+ * @param connections
+ * A Collection of all connections that should be present in this
+ * connection directory.
+ * @param rootGroup
+ * A group that should be at the base of this directory.
+ */
+public QuickConnectDirectory(Collection connections, 
ConnectionGroup rootGroup) {
+super(connections);
+this.rootGroup = (QuickConnectConnectionGroup)rootGroup;
+}
+
+/**
+ * Returns the current counter and then increments it.
+ *
+ * @return
+ * An Integer representing the next available connection
+ * ID to get used when adding connections.
+ */
+private Integer getNextConnectionID() {
+return CONNECTION_ID++;
+}
+
+@Override
+public void add(Connection object) throws GuacamoleException {
+
+put(new QuickConnection(object));
+
+}
+
+/**
+ * Create a connection object on the tree using an existing
+ * QuickConnection connection, after setting the identifier
+ * and parent object.
+ *
+ * @param object
+ * The QuickConnection object to add to the tree.
+ *
+ * @return
+ * The connectionId of the object added to the directory.
+ *
+ * @throws GuacamoleException
+ * If an error is encountered adding the object to the
+ * directory.
+ */
+public String put(QuickConnection object) throws GuacamoleException {
--- End diff --

Yep, you/re right - this should be fixed, now.


---