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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178438303
  
--- 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();
+};
+
+/**
+ * When the prompt 

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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178082252
  
--- 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();
+};
+
+/**
+ * When the prompt 

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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178081985
  
--- 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 --

Slight change here - I had encoded everything, including parameter name, 
which obviously didn't work.  Instead I should do the encoding where you 
suggested it :-).  Should be fixed and working, now.


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178056624
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java
 ---
@@ -98,6 +99,10 @@ public void setAttributes(Map 
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 --

Okay, I'm now copying the config in this method, so that the values are 
placed into that non-persistent config, which will then get discarded after the 
connection finishes.


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178056419
  
--- 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 --

Should be encoded, now, in the `getConnectString()` method.


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178052016
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java
 ---
@@ -98,6 +99,10 @@ public void setAttributes(Map 
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 thought about that, and one of my earlier implementation attempts 
actually did function this way.  The reason I opted for this sort of inline 
processing method was to be consistent with the way other tokens are processed, 
which is done at connection time rather than being done ahead of time.  I think 
this is probably mostly due to the fact that the GUAC_DATE and GUAC_TIME tokens 
are expected to be processed in real-time so that their values are current.

That said, the prompts don't necessarily have to work the same as the other 
tokens if there's a compelling reason to do something else.  I went back and 
forth on this a lot, and eventually ended up at this point.

I think for this particular issue you raise I'll just make a copy of the 
config object and filter that one for prompts, and it can get discarded after 
the connection is finished.


---


[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 
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 necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/194#discussion_r178045959
  
--- 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();
+};
+
+/**
+ * When the prompt 

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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178045884
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java
 ---
@@ -98,6 +99,10 @@ public void setAttributes(Map 
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 --

Yeah, I think I see your point, here.  Will see what options there are to 
take care of this.


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r178039519
  
--- 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 --

Yep, you're right - will add that in.


---


[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();
+};
+
+/**
+ * When the prompt object 

[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 
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 


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r174090051
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java ---
@@ -50,6 +50,16 @@
  */
 public static final String CLIENT_ADDRESS_TOKEN = 
"GUAC_CLIENT_ADDRESS";
 
+/**
+ * The token that triggers prompts for numeric fields.
+ */
+public static final String PROMPT_TOKEN_NUMERIC = "-1";
+
+/**
+ * The token that triggers prompts for string fields.
+ */
+public static final String PROMPT_TOKEN_STRING = "GUAC_PROMPT";
--- End diff --

If the whole string needs to be prompted, then you just put 
```${GUAC_PROMPT}``` in for the whole string.  In Guacamole null or empty 
values indicate the absence of a parameter and delete that parameter from the 
underlying database table (in the JDBC modules, anyway), so prompting for an 
empty value would not be practical and would interfere with some of the basic 
ways in which parameters are evaluated, aside from which it isn't really 
necessary.


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r161638782
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/token/PromptEntry.java ---
@@ -0,0 +1,124 @@
+/*
+ * 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.token;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.form.Field;
+
+/**
+ * A class that collects all of the information required to
+ * to display a prompt to the user during client connection.
+ */
+public class PromptEntry {
--- End diff --

> As an example, let's say I want to prompt the user for a folder within 
their home directory that they want to pass through to a RDP connection - the 
text in the connection configuration might be:
>
> /home/${GUAC_USERNAME}/${GUAC_PROMPT}

If a malicious user entered "../../" for that, they would gain access to 
the root directory.

> Thus, the user would not be allowed to override everything about that 
parameter, just provide some input within a scope that the administrator has 
defined.

This may not actually end up being what happens, depending on the semantics 
of the parameter.

I'm still unclear as to why `positions` is necessary, or what its values 
are intended to be. Can you describe how `positions` would be used in the 
examples you provided?


---


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

2018-01-15 Thread necouchman
Github user necouchman commented on a diff in the pull request:

https://github.com/apache/guacamole-client/pull/194#discussion_r161610676
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/token/PromptEntry.java ---
@@ -0,0 +1,124 @@
+/*
+ * 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.token;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.form.Field;
+
+/**
+ * A class that collects all of the information required to
+ * to display a prompt to the user during client connection.
+ */
+public class PromptEntry {
--- End diff --

So, the main point is to provide a data structure that can then be 
presented by the REST API such that the front-end application can provide a 
list of fields where prompts are necessary.  The `Field` is tracked so that we 
know both the name and the type of entry this should be (text vs. password vs. 
number, etc.), and the `positions` is so that you can cope with the following 
possible scenarios:
- The entire field (e.g. username) is being prompted.
- One or more positions within a field are being prompted.  The idea here 
is that there may be some text within a parameter, such as a filesystem 
location or directory path, that I want to hard-code as the administrator, 
while I want the user to be able to provide some sort of input to the field.  
As an example, let's say I want to prompt the user for a folder within their 
home directory that they want to pass through to a RDP connection - the text in 
the connection configuration might be:

`/home/${GUAC_USERNAME}/${GUAC_PROMPT}`

Or, perhaps you want to allow them to enter a hostname for a server, but 
within a defined range of servers.  You might do:

`vdi-${GUAC_PROMPT}.example.com`

or:

`${GUAC_PROMPT}.vdi.example.com`

Thus, the user would not be allowed to override everything about that 
parameter, just provide some input within a scope that the administrator has 
defined.


---


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

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

https://github.com/apache/guacamole-client/pull/194#discussion_r161386520
  
--- Diff: 
guacamole-ext/src/main/java/org/apache/guacamole/token/PromptEntry.java ---
@@ -0,0 +1,124 @@
+/*
+ * 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.token;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.guacamole.form.Field;
+
+/**
+ * A class that collects all of the information required to
+ * to display a prompt to the user during client connection.
+ */
+public class PromptEntry {
--- End diff --

So, I'm confused by the overall purpose of the `PromptEntry` class? What 
does it represent? What are these mysterious string positions?


---