*
* @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);
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.");
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;
}
/**
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;
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
/**
* TODO wrap in a LoginModule
/** {@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();
+ }
+ }
}