return (IUserService) getService(IUserService.class, "/remoting-public/user.service", new CdmServiceRequestExecutor());\r
}\r
\r
+\r
+ public static IUserService getUserService(ICdmRemoteSource remoteSource) {\r
+ return (IUserService) getService(IUserService.class, "/remoting-public/user.service", remoteSource, new CommonsHttpInvokerRequestExecutor());\r
+ }\r
+\r
@Override\r
public IMetadataService getMetadataService() {\r
return (IMetadataService) getService(IMetadataService.class, "/remoting-public/metadata.service", new CommonsHttpInvokerRequestExecutor());\r
if(authenticationManager != null) {\r
return authenticationManager;\r
}\r
+\r
+ authenticationManager = getAuthenticationManager(getUserService());\r
+ return authenticationManager;\r
+ }\r
+\r
+ public static ProviderManager getAuthenticationManager(IUserService userService) {\r
Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();\r
ReflectionSaltSource saltSource = new ReflectionSaltSource();\r
saltSource.setUserPropertyToUse("getUsername");\r
\r
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();\r
- daoAuthenticationProvider.setUserDetailsService(getUserService());\r
+ daoAuthenticationProvider.setUserDetailsService(userService);\r
daoAuthenticationProvider.setSaltSource(saltSource);\r
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder);\r
\r
- authenticationManager = new ProviderManager(Arrays.asList((AuthenticationProvider)daoAuthenticationProvider));\r
- return authenticationManager;\r
+ return new ProviderManager(Arrays.asList((AuthenticationProvider)daoAuthenticationProvider));\r
}\r
\r
\r
private ConversationHolder conversation;
+ public static final String INCORRECT_CREDENTIALS_MESSAGE = "Login and/or Password incorrect";
+ public static final String ACCOUNT_LOCKED_MESSAGE = "Account is locked";
+ public static final String EMPTY_CREDENTIALS_MESSAGE = "Login and/or Password empty";
+
public LoginManager(){
- CdmStore.getContextManager().addContextListener(this);
+ CdmStore.getContextManager().addContextListener(this);
}
/**
this.notifyObservers();
}
} catch(BadCredentialsException e){
- throw new CdmAuthenticationException("Login and/or Password incorrect", e);
+ throw new CdmAuthenticationException(INCORRECT_CREDENTIALS_MESSAGE, e);
} catch(LockedException e){
- throw new CdmAuthenticationException("Account is locked", e);
+ throw new CdmAuthenticationException(ACCOUNT_LOCKED_MESSAGE, e);
} catch(IllegalArgumentException e){
- throw new CdmAuthenticationException("Login and/or Password empty", e);
+ throw new CdmAuthenticationException(EMPTY_CREDENTIALS_MESSAGE, e);
}
}
+
private void _logGrantedAuthotities(StringBuilder gaText, String indent,
Set<GrantedAuthority> gaSet) {
for(GrantedAuthority ga : gaSet){
import org.eclipse.wb.swt.SWTResourceManager;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.LockedException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.service.IUserService;
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.LoginManager;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
import eu.etaxonomy.taxeditor.webapp.CDMServer;
private void refreshCdmServer() {
+ txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
+ clearOnServerChange();
+ emptyCredentials();
+ updateSelectedCdmServer();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
- updateSelectedCdmServer();
checkSelectedCdmServer();
- updatePort();
}
});
+
}
private void updateSelectedCdmServer() {
}
private void checkSelectedCdmServer() {
-
- clearOnServerChange();
- emptyCredentials();
-
if(selectedCsii != null) {
if(selectedCsii.isLocalhost()) {
txtPort.setEditable(true);
disableCdmInstanceControls("", "");
}
}
+ updatePort();
}
ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
- if(!validateLogin()) {
+ if(!validateLogin(source)) {
return;
}
return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
}
- private boolean validateLogin() {
+ private boolean validateLogin(ICdmRemoteSource remoteSource) {
if(getUsername() == null || getUsername().isEmpty()) {
setMessage("User login cannot be empty");
return false;
setMessage("Password cannot be empty");
return false;
}
+
+
+ try {
+ IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
+ UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
+ CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
+ } catch(BadCredentialsException e){
+ setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
+ return false;
+ } catch(LockedException e){
+ setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
+ return false;
+ } catch(IllegalArgumentException e){
+ setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
+ return false;
+ }
return true;
}
+
public String getUsername() {
return txtLogin.getText();
}
txtServerVersion.setText("");
txtServerVersion.setToolTipText("");
txtServerCDMVersion.setText("");
+ comboCdmInstance.removeAll();
+ txtCdmInstanceStatus.setText("");
txtPort.setEditable(false);
txtPort.setEnabled(false);
}