import java.util.List;
import java.util.UUID;
-import javax.security.auth.spi.LoginModule;
-
import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.Status;
import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.providers.ProviderManager;
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
import eu.etaxonomy.cdm.persistence.query.MatchMode;
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
-import eu.etaxonomy.taxeditor.model.TaxeditorLoginModule;
-import eu.etaxonomy.taxeditor.user.AuthenticatedUserBar;
+import eu.etaxonomy.taxeditor.datasource.ChooseDatasourceDialog;
/**
* This implementation of ICdmDataRepository depends on hibernate sessions to store the data correctly
private static DbSchemaValidation dbSchemaValidation;
- private static LoginModule loginModule;
+ private static LoginManager loginManager;
/**
*
public static CdmStore getDefault(String applicationContextBean){
if(instance == null){
logger.info("Initializing application context ...");
- ICdmDataSource cdmDatasource = CdmDataSourceRepository.getDefault().
- getCurrentDataSource();
-
- instance = new CdmStore(cdmDatasource, getDbSchemaValidation(), applicationContextBean);
- logger.info("Application context initialized.");
+ // Prompt user for datasource if there are more than one
+ if(CdmDataSourceRepository.getDefault().getAll().size() > 1){
+ ChooseDatasourceDialog chooseDataSource = new ChooseDatasourceDialog(StoreUtil.getShell());
+ if(chooseDataSource.open() == Status.OK){
+ initialize(applicationContextBean);
+
+ }else{
+ // no datasource chosen.
+ logger.warn("No datasource chosen. Exiting now.");
+ System.exit(1);
+ }
+ }else{
+ // Start default cdm database
+ initialize(applicationContextBean);
+ }
+
}
return instance;
}
+
+ private static CdmStore initialize(String applicationContextBean){
+
+ ICdmDataSource cdmDatasource = CdmDataSourceRepository.getDefault().getCurrentDataSource();
+
+ CdmStore instance = new CdmStore(cdmDatasource, getDbSchemaValidation(), applicationContextBean);
+
+ logger.info("Application context initialized.");
+
+ return instance;
+ }
/**
* @return
return nomReferenceTypeMap;
}
-
- /**
- * TODO implement LoginModule to handle the whole login stuff
- *
- * @param token
- */
- public static void authenticate(UsernamePasswordAuthenticationToken token){
- Authentication authentication = CdmStore.getAuthenticationManager().authenticate(token);
- SecurityContextHolder.getContext().setAuthentication(authentication);
-
- // TODO register a listener on LoginModule instead of calling a set method here
-// AuthenticatedUserBar.setAuthenticatedUser(getAuthenticatedUser().getUsername());
- }
-
- public static User getAuthenticatedUser(){
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
-
- if(authentication != null
- && authentication.getPrincipal() != null
- && authentication.getPrincipal() instanceof User){
- return (User)authentication.getPrincipal();
- }
- return null;
- }
/**
* incomplete! do note use!
*/
- public static LoginModule getLoginModule(){
- if(loginModule == null){
- loginModule = new TaxeditorLoginModule();
+ public static LoginManager getLoginManager(){
+ if(loginManager == null){
+ loginManager = new LoginManager();
}
- return loginModule;
+ return loginManager;
}
}