diff m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m @ 41:6def6533cb16 database-connection-manager

Report authentication errors to user
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 18:04:34 +0100
parents 5e7477b94d94
children f90d4f666cc7
line wrap: on
line diff
--- a/m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m	Mon Dec 05 18:04:03 2011 +0100
+++ b/m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m	Mon Dec 05 18:04:34 2011 +0100
@@ -4,6 +4,7 @@
 
     connections = {};
     credentials = {};
+    userMessage = [];
 
   end % private properties
 
@@ -84,6 +85,9 @@
         end
         cm.add(utils.credentials(repo{:}));
       end
+
+      % reset user message
+      cm.userMessage = [];
     end
 
 
@@ -349,8 +353,8 @@
           cache = false;
           if (numel(cred) > 1) || ~cred.complete
             % ask for password
-            [username, password, cache] = cm.inputCredentials(cred);
-
+            [username, password, cache] = cm.inputCredentials(cred, cm.userMessage);
+            
             % cache credentials
             cred = utils.credentials(varargin{1}, varargin{2}, username);
             cm.cacheCredentials(cred);
@@ -367,6 +371,7 @@
             if strcmp(ex.identifier, 'utils:mysql:connect:AccessDenied')
               % ask for new new credentials
               utils.helper.msg(msg.IMPORTANT, ex.message);
+              cm.userMessage = 'Authentication error!';
               conn = cm.getConnection(varargin{1}, varargin{2}, varargin{3});
             else
               % error out
@@ -470,9 +475,14 @@
     end
 
 
-    function [username, password, cache] = inputCredentials(cm, cred)
+    function [username, password, cache] = inputCredentials(cm, cred, msg)
     % INPUTCREDENTIALS Queries the user for database username and password.
 
+      % msg is an optional argument
+      if nargin < 3
+        msg = [];
+      end
+
       % build a cell array of usernames
       users = {};
       for id = 1:numel(cred)
@@ -484,7 +494,7 @@
 
       parent = com.mathworks.mde.desk.MLDesktop.getInstance().getMainFrame();
       dialog = javaObjectEDT('connectionmanager.CredentialsDialog', ...
-          parent, cred(1).hostname, cred(1).database, users, cm.cachePassword);
+          parent, cred(1).hostname, cred(1).database, users, cm.cachePassword, msg);
       dialog.show();
       if dialog.cancelled
         throw(MException('utils:mysql:connect:UserCancelled', '### user cancelled'));