[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
Github user asfgit closed the pull request at: https://github.com/apache/guacamole-client/pull/181 ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r189082084 --- 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 -- Under what circumstances will `username` or `password` be null? `URLDecoder.decode()` is not documented as returning null. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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 a
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r186860269 --- 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 -- I believe I've done this as you suggested. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r186860162 --- 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 -- Done. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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 to expose it within `QuickConnectUserConte
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r186851977 --- 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 -- So, do I need to inject or pass in the `UserContext` object, here?
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r186839091 --- 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 -- The `QuickConnectUserContext` uses `DEFAULT_ROOT_CONNECTION_GROUP`,
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r186841819 --- 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 -- Though older code within Guacamole does this, it's bad practice to invoke overridable functions of the class being instantiated within its own constructor. If the setters belong to the superclass, `super` should be used explicitly. Some IDEs will warn of this. https://stackoverflow.com/questions/3404301/whats-wrong-with-overridable-method-calls-in-constructors ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r186838600 --- 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 -- This is not threadsafe, and may behave unexpectedly if multiple requests to add a new connection are serviced for the same user at the same time. I recommend switching from `HashMap` to `ConcurrentHashMap`. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r182696319 --- 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) +qcConfig.setParameter("use
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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) +qcConfig.setParameter("use
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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) +qcConfig.setParameter("use
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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) +qcConfig.setParameter("use
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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) +qcConfig.setParameter("use
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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) +qcConfig.setParameter("use
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
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...
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...
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...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r182205125 --- 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 -- As a single instance of each `AuthenticationProvider` is maintained for all users, maintaining a reference to a single `UserContext` at the `AuthenticationProvider` level will mean that all users share the same data. In this case, this seems odd since the `UserContext` is being explicitly initialized for the current `AuthenticatedUser`. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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) +qcConfig.setParameter("us
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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) +qcConfig.setParameter("us
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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) +qcConfig.setParameter("us
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r182213191 --- 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 -- I hate to ask, but what if a parameter needs to contain a literal "&" or "="? Is there any provision here for handling values which are properly URL-encoded? ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
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) +qcConfig.setParameter("us
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176926902 --- 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 -- Added `public` just to make it consistent. Several classes could probably be package-private if we want to go that route at some point, but we should do it consistently across the code and establish some guidelines for that if we choose to. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176926804 --- 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 -- Fixed. I think I was originally avoiding implementing my own connection directory and trying to use one of the provided ones, and that didn't pan out and I forgot to go back and fix stuff. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176926499 --- 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 -- Certainly should not. Removed. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176926320 --- 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 -- Ah, okay, that makes sense. I guess I'll just switch it over to `implements AuthenticationProvider` for now - I think it would probably make sense at some point in the future to create the `AbstractAuthenticationProvider` and `AbstractUserContext` implementations, but it seems like that might be more appropriate in a separate change. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176924354 --- 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 -- Removed. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
Github user necouchman commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176924283 --- 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 -- Good question, to which I do not have an answer. Removed. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176924143 --- 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 -- I get where you're coming from, and reducing duplication is good, but what you need is an actual base implementation of `AuthenticationProvider` which guarantees the default behavior you're looking for. `SimpleAuthenticationProvider` is not guaranteed or intended to provide this, and is only defined with respect to `getAuthorizedConfigurations()`. A base, empty implementation of `AuthenticationProvider` would probably be a good thing (similar to `AbstractUser` and others). If you're looking to avoid duplication, perhaps we should: * Write an `AbstractAuthenticationProvider` (perhaps also `AbstractUserContext` if it helps) * Refactor `SimpleAuthenticationProvider` to build off that if appropriate. * Avoid using `SimpleAuthenticationProvider` here ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
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...
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...
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...
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...
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...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176920036 --- 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 -- What if `authenticators` is something like "myusername:myPassword:That:Has:Colons"? Rather than manually parse everything with `split()`, I suggest defining (and pre-compiling) regular expressions. It would avoid recompiling the pattern each time `split()` is invoked, and may be more robust. Alternatively, though I haven't looked into this, there may be a better class for parsing URIs which handles all of this. It doesn't look like anything we're doing here is non-standard with respect to URI format. ---
[GitHub] guacamole-client pull request #181: GUACAMOLE-38: Implement on-demand connec...
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...
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...
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...
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...
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...
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...
Github user mike-jumper commented on a diff in the pull request: https://github.com/apache/guacamole-client/pull/181#discussion_r176919913 --- 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 -- Under what circumstances would a `String` within the `String[]` returned by `split()` be `null`? ---