changeset 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 977eb37f31cb
children f90d4f666cc7
files m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m src/ConnectionManager/src/connectionmanager/CredentialsDialog.java
diffstat 2 files changed, 20 insertions(+), 6 deletions(-) [+]
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'));
--- a/src/ConnectionManager/src/connectionmanager/CredentialsDialog.java	Mon Dec 05 18:04:03 2011 +0100
+++ b/src/ConnectionManager/src/connectionmanager/CredentialsDialog.java	Mon Dec 05 18:04:34 2011 +0100
@@ -20,7 +20,7 @@
     super.getRootPane().setDefaultButton(okButton);
   }
   
-  public CredentialsDialog(java.awt.Frame parent, String hostname, String database, String[] usernames, int cache) {
+  public CredentialsDialog(java.awt.Frame parent, String hostname, String database, String[] usernames, int cache, String msg) {
     super(parent, true);
     initComponents();
     super.setLocationRelativeTo(parent);
@@ -40,7 +40,11 @@
         break;
     }
 
-    titleLabel.setText(String.format("Credentials for mysql://%s/%s/", hostname, database));
+    if (msg != null) {
+      titleLabel.setText(String.format("%s mysql://%s/%s/", msg, hostname, database));
+    } else {
+      titleLabel.setText(String.format("Credentials for mysql://%s/%s/", hostname, database));
+    }
     if ((usernames != null) && (usernames.length > 0)) {
       usernameField.setModel(new javax.swing.DefaultComboBoxModel(usernames));
       passwordField.requestFocus();