Fixes #2388
authorn.hoffmann <n.hoffmann@localhost>
Mon, 23 May 2011 15:41:50 +0000 (15:41 +0000)
committern.hoffmann <n.hoffmann@localhost>
Mon, 23 May 2011 15:41:50 +0000 (15:41 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/LoginManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialogs/LoginDialog.java

index 43d703e49f925c2c898745238254876baf4612e3..b1f7f11339fb6004c9c720fab6903782ddb14e56 100644 (file)
@@ -39,7 +39,7 @@ public class LoginManager extends Observable implements IConversationEnabled{
         *
         * @param token a {@link org.springframework.security.authentication.UsernamePasswordAuthenticationToken} object.
         */
-       public void authenticate(String username, String password){             
+       public boolean authenticate(String username, String password){          
                try{
                        getConversationHolder().bind();
                        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); 
@@ -47,6 +47,9 @@ public class LoginManager extends Observable implements IConversationEnabled{
                        SecurityContextHolder.clearContext();
                        Authentication authentication = CdmStore.getAuthenticationManager().authenticate(token);                
                        SecurityContextHolder.getContext().setAuthentication(authentication);
+                       this.setChanged();
+                       this.notifyObservers();
+                       return true;
                }
                catch(BadCredentialsException e){
                        StoreUtil.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Bad Credentials.");
@@ -57,10 +60,7 @@ public class LoginManager extends Observable implements IConversationEnabled{
                catch(IllegalArgumentException e){
                        StoreUtil.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Username and/or Password empty.");
                }
-               finally{
-                       this.setChanged();
-                       this.notifyObservers();
-               }
+               return false;
        }
        
        /**
index c228d38574bda7f1475c10fbf3341d89a8246fb5..5af54cabb4db93f5f9595126a37ae9b5bfec5836 100644 (file)
@@ -11,6 +11,7 @@
 package eu.etaxonomy.taxeditor.ui.dialogs;
 
 import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CLabel;
 import org.eclipse.swt.layout.GridData;
@@ -20,6 +21,7 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 
 /**
  * TODO wrap in a LoginModule
@@ -100,13 +102,24 @@ public class LoginDialog extends Dialog {
        /** {@inheritDoc} */
        @Override
        protected void okPressed() {
-               String username = text_username.getText().trim();
-               String password = text_password.getText().trim();
+               String username = text_username.getText();
+               String password = text_password.getText();
+               
+               boolean result = CdmStore.getLoginManager().authenticate(username, password);
+               
+               if(result){
+                       super.okPressed();
+               }
                
-               CdmStore.getLoginManager().authenticate(username, password);                    
-                               
-               super.okPressed();
        }       
        
-       
+       @Override
+       protected void cancelPressed() {                
+               boolean result = MessageDialog.openConfirm(getShell(), "Do you really want to cancel", "Aborting the login procedure will close the database.");
+               
+               if(result){
+                       CdmStore.close(StoreUtil.getMonitor());
+                       super.cancelPressed();
+               }
+       }
 }