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<String> 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`?
---