[GitHub] guacamole-client pull request #194: GUACAMOLE-221: Support for Connection Pr...

2018-03-29 Thread uvtrip
Github user uvtrip commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/194#discussion_r178046477
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java
 ---
@@ -98,6 +99,10 @@ public void setAttributes(Map<String, String> 
attributes) {
 public GuacamoleTunnel connect(GuacamoleClientInformation info)
 throws GuacamoleException {
 
+// Filter in connection-time information
+TokenFilter tokenFilter = new TokenFilter();
+
tokenFilter.filterPrompts(config.getParameters(),info.getParameters());
--- End diff --

i think you should save the prompts per each configuration, and maybe 
calculate them in advance


---


[GitHub] guacamole-client pull request #194: GUACAMOLE-221: Support for Connection Pr...

2018-03-29 Thread uvtrip
Github user uvtrip commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/194#discussion_r174723573
  
--- Diff: guacamole/src/main/webapp/app/client/types/ManagedClient.js ---
@@ -503,27 +504,70 @@ angular.module('client').factory('ManagedClient', 
['$rootScope', '$injector',
 // Parse connection details from ID
 var clientIdentifier = ClientIdentifier.fromString(id);
 
-// Connect the Guacamole client
-getConnectString(clientIdentifier, connectionParameters)
-.then(function connectClient(connectString) {
-client.connect(connectString);
-});
-
+var gettingConnectionData = $q.defer();
 // If using a connection, pull connection name
-if (clientIdentifier.type === ClientIdentifier.Types.CONNECTION) {
-connectionService.getConnection(clientIdentifier.dataSource, 
clientIdentifier.id)
-.success(function connectionRetrieved(connection) {
-managedClient.name = managedClient.title = connection.name;
-});
-}
-
+if (clientIdentifier.type === ClientIdentifier.Types.CONNECTION)
+gettingConnectionData = 
connectionService.getConnection(clientIdentifier.dataSource, 
clientIdentifier.id);
+
 // If using a connection group, pull connection name
-else if (clientIdentifier.type === 
ClientIdentifier.Types.CONNECTION_GROUP) {
-
connectionGroupService.getConnectionGroup(clientIdentifier.dataSource, 
clientIdentifier.id)
-.success(function connectionGroupRetrieved(group) {
-managedClient.name = managedClient.title = group.name;
+else if (clientIdentifier.type === 
ClientIdentifier.Types.CONNECTION_GROUP)
+gettingConnectionData = 
connectionGroupService.getConnectionGroup(clientIdentifier.dataSource, 
clientIdentifier.id);
+
+else
+gettingConnectionData.reject('Invalid connection type.');
+
+// Get Connection Prompts
+var gettingConnectionPrompts = 
connectionService.getConnectionPrompts(clientIdentifier.dataSource, 
clientIdentifier.id);
+
+// When we've received connection data and prompts, display 
prompts to user.
+$q.all([gettingConnectionData,gettingConnectionPrompts])
+.then(function connectClient(clientData) {
+
+var connData = clientData[0].data;
+var connPrompts = clientData[1].data;
+
+// Display the prompts, then process them
+guacPrompt.getUserInput(connPrompts,connData)
+.then(function receivedUserInput(data) {
+
+// Create a parameter string from the received data
+var userData = '';
+for (var key in data) {
+var param = data[key];
+for (var idx in param) {
+var inst = param[idx];
+if (userData != '')
+userData += '&';
+userData += key + '[' + idx + ']=' + inst;
--- End diff --

you need to URI encode the parameters - otherwise it wont work with WS


---


[GitHub] guacamole-client pull request #194: GUACAMOLE-221: Support for Connection Pr...

2018-03-29 Thread uvtrip
Github user uvtrip commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/194#discussion_r174737727
  
--- Diff: guacamole/src/main/webapp/app/prompt/services/guacPrompt.js ---
@@ -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.
+ */
+
+/**
+ * Service for displaying prompts as modal dialogs.
+ */
+angular.module('prompt').factory('guacPrompt', ['$injector',
+function guacPrompt($injector) {
+
+// Required services
+var $location = $injector.get('$location');
+var $q= $injector.get('$q');
+var $rootScope= $injector.get('$rootScope');
+var $window   = $injector.get('$window');
+var sessionStorageFactory = $injector.get('sessionStorageFactory');
+
+var service = {};
+
+/**
+ * Object which retrieves or sets the current prompts,
+ * or false if no prompt is currently shown.
+ * 
+ * @type Function
+ */
+var storedPrompt = sessionStorageFactory.create(false);
+
+/**
+ * Retrieves the current prompt, or false if no prompt
+ * is currently shown.
+ * 
+ * @type Prompt|Boolean
+ */
+service.getPrompt = function getPrompt() {
+return storedPrompt();
+};
+
+/**
+ * Shows or hides the given prompt as a modal dialog.  Only one
+ * prompt dialog will be shown at a time.
+ *
+ * @param {Prompt|Boolean|Object} status
+ * The prompt object to show.
+ */
+service.showPrompt = function showPrompt(status) {
+if (!storedPrompt() || !status)
+storedPrompt(status);
+};
+
+/**
+ * Taking a list of prompts and a connection, display the prompt
+ * dialog for the user to fill out, and return a promise that
+ * responses will be provided.
+ *
+ * @param prompts
+ * The list of prompts to display to the user.
+ *
+ * @param connection
+ * The connection that the prompts are being used for.
+ *
+ * @returns
+ * A promise for responses that the user will fill in.
+ */
+service.getUserInput = function getUserInput(prompts,connection) {
+
+var deferred = $q.defer();
+var responses = {};
+var homeUrl = '/';
+
+if (prompts.length < 1)
+deferred.resolve();
+
+else {
+service.showPrompt({
+'title' : 'Connection Parameters for ' + 
connection.name,
+'connection' : connection,
+'text'  : {
+key : 'Please provide the following parameters to 
complete the connection:'
+},
+'prompts'   : prompts,
+'actions'   : [{
+'name'  : 'Connect',
+'callback' : function() {
+deferred.resolve(responses);
+service.showPrompt(false);
+},
+},
+{
+'name'  : 'Cancel',
+'callback' : function() {
+deferred.reject();
+service.showPrompt(false);
+$location.url(homeUrl);
+},
+}],
+'responses' : responses
+});
+}
+
+return deferred.promise;
+
+};
+
+/**
+ * Method to stop propagation of events.
+ *
+ * @param event
+ * The event to stop.
+ */
+var preventEvent = function(event) {
+if (service.getPrompt())
+event.stopPropagation();
+};
+
+/**
+ *

[GitHub] guacamole-client pull request #194: GUACAMOLE-221: Support for Connection Pr...

2018-03-29 Thread uvtrip
Github user uvtrip commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/194#discussion_r174724059
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java
 ---
@@ -98,6 +99,10 @@ public void setAttributes(Map<String, String> 
attributes) {
 public GuacamoleTunnel connect(GuacamoleClientInformation info)
 throws GuacamoleException {
 
+// Filter in connection-time information
+TokenFilter tokenFilter = new TokenFilter();
+
tokenFilter.filterPrompts(config.getParameters(),info.getParameters());
--- End diff --

this will only work in the 1st time, on all other times as the field in 
config already exists with the values, it will not replace it with the latest 
user input 


---