Project

General

Profile

« Previous | Next » 

Revision 4ed38c9b

Added by Cherian Mathew over 8 years ago

#5207 Add validation of credentials on target server before starting application context

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
49 49
import org.eclipse.wb.swt.SWTResourceManager;
50 50
import org.osgi.service.prefs.BackingStoreException;
51 51
import org.osgi.service.prefs.Preferences;
52
import org.springframework.security.authentication.BadCredentialsException;
53
import org.springframework.security.authentication.LockedException;
54
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
52 55

  
56
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
53 57
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
58
import eu.etaxonomy.cdm.api.service.IUserService;
54 59
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
55 60
import eu.etaxonomy.taxeditor.model.MessagingUtils;
56 61
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
......
62 67
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
63 68
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
64 69
import eu.etaxonomy.taxeditor.store.CdmStore;
70
import eu.etaxonomy.taxeditor.store.LoginManager;
65 71
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
66 72
import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
67 73
import eu.etaxonomy.taxeditor.webapp.CDMServer;
......
507 513

  
508 514

  
509 515
    private void refreshCdmServer() {
516
        txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
517
        clearOnServerChange();
518
        emptyCredentials();
519
        updateSelectedCdmServer();
510 520
        Display.getDefault().asyncExec(new Runnable() {
511 521
            @Override
512 522
            public void run() {
513
                txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
514
                updateSelectedCdmServer();
515 523
                checkSelectedCdmServer();
516
                updatePort();
517 524
            }
518 525
        });
526

  
519 527
    }
520 528

  
521 529
    private void updateSelectedCdmServer() {
......
550 558
    }
551 559

  
552 560
    private void checkSelectedCdmServer() {
553

  
554
        clearOnServerChange();
555
        emptyCredentials();
556

  
557 561
        if(selectedCsii != null) {
558 562
            if(selectedCsii.isLocalhost()) {
559 563
                txtPort.setEditable(true);
......
570 574
                disableCdmInstanceControls("", "");
571 575
            }
572 576
        }
577
        updatePort();
573 578
    }
574 579

  
575 580

  
......
855 860

  
856 861
        ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
857 862

  
858
        if(!validateLogin()) {
863
        if(!validateLogin(source)) {
859 864
            return;
860 865
        }
861 866

  
......
934 939
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
935 940
    }
936 941

  
937
    private boolean validateLogin() {
942
    private boolean validateLogin(ICdmRemoteSource remoteSource) {
938 943
        if(getUsername() == null || getUsername().isEmpty()) {
939 944
            setMessage("User login cannot be empty");
940 945
            return false;
......
943 948
            setMessage("Password cannot be empty");
944 949
            return false;
945 950
        }
951

  
952

  
953
        try {
954
            IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
955
            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
956
            CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
957
        } catch(BadCredentialsException e){
958
            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
959
            return false;
960
        } catch(LockedException e){
961
            setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
962
            return false;
963
        } catch(IllegalArgumentException e){
964
            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
965
            return false;
966
        }
946 967
        return true;
947 968
    }
969

  
948 970
    public String getUsername() {
949 971
        return txtLogin.getText();
950 972
    }
......
1035 1057
        txtServerVersion.setText("");
1036 1058
        txtServerVersion.setToolTipText("");
1037 1059
        txtServerCDMVersion.setText("");
1060
        comboCdmInstance.removeAll();
1061
        txtCdmInstanceStatus.setText("");
1038 1062
        txtPort.setEditable(false);
1039 1063
        txtPort.setEnabled(false);
1040 1064
    }

Also available in: Unified diff