use of com.centurylink.mdw.designer.auth.MdwAuthenticator in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method getAuthenticator.
public Authenticator getAuthenticator() {
if (isGitVcs() && isRemote()) {
AppSummary appSummary = getRemoteAppSummary(true);
if (appSummary == null)
return null;
String oauthTokenUrl = appSummary.getOAuthTokenUrl();
if (oauthTokenUrl != null)
return new OAuthAuthenticator(oauthTokenUrl);
if ("mdw".equals(appSummary.getAuthMethod())) {
try {
return new MdwAuthenticator(appSummary.getAppId(), MdwPlugin.getSettings().getMdwCentralUrl() + "/services/com/centurylink/mdw/central/auth");
} catch (Exception ex) {
PluginMessages.uiError(ex, "Authentication", this);
}
}
}
// https://wiki.eclipse.org/Security:_KeyStore_support_for_Eclipse
return new ClearTrustAuthenticator();
}
use of com.centurylink.mdw.designer.auth.MdwAuthenticator in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method initialize.
public void initialize(ProgressMonitor progressMonitor) throws Exception {
mainFrame = new MainFrame("Not Displayed");
mainFrame.setOptionPane(new SwtDialogProvider(MdwPlugin.getDisplay()));
CodeTimer timer = new CodeTimer("initialize()");
Map<String, String> connProps = new HashMap<>();
try {
User user = project.getUser();
if (user != null && user.getJwtToken() != null)
user.setJwtToken(((MdwAuthenticator) project.getAuthenticator()).doAuthentication(user.getUsername(), user.getPassword()));
if (user == null)
handleLazyUserAuth();
if (project.getPersistType() == WorkflowProject.PersistType.Git) {
restfulServer = createRestfulServer(project.getMdwDataSource().getJdbcUrlWithCredentials(), project.getMdwMajorVersion() * 1000 + project.getMdwMinorVersion() * 100);
VcsRepository gitRepo = project.getMdwVcsRepository();
VersionControlGit versionControl = new VersionControlGit();
String gitUser = null;
String gitPassword = null;
if (MdwPlugin.getSettings().isUseDiscoveredVcsCredentials()) {
gitUser = gitRepo.getUser();
gitPassword = gitRepo.getPassword();
}
versionControl.connect(gitRepo.getRepositoryUrl(), gitUser, gitPassword, project.getProjectDir());
versionControl.setValidateVersions(!project.checkRequiredVersion(6) && MdwPlugin.getSettings().isValidateProcessVersions());
restfulServer.setVersionControl(versionControl);
restfulServer.setRootDirectory(project.getAssetDir());
if (project.isRemote()) {
File assetDir = project.getAssetDir();
boolean isGit = gitRepo.getRepositoryUrl() != null;
String pkgDownloadServicePath = null;
try {
if (isGit) {
// update branch from Git
if (progressMonitor != null)
progressMonitor.subTask("Retrieving Git status");
// avoid
Platform.getBundle("org.eclipse.egit.ui").start();
// Eclipse
// default
// Authenticator
// --
// otherwise
// login
// fails
AppSummary appSummary = restfulServer.getAppSummary();
if (appSummary.getRepository() == null)
throw new DataAccessOfflineException("Unable to confirm Git status on server (missing repository)");
String branch = appSummary.getRepository().getBranch();
if (branch == null || branch.isEmpty())
throw new DataAccessOfflineException("Unable to confirm Git status on server (missing branch)");
String oldBranch = gitRepo.getBranch();
if (!branch.equals(oldBranch))
gitRepo.setBranch(branch);
if (progressMonitor != null)
progressMonitor.subTask("Updating from branch: " + branch);
versionControl.hardReset();
// in case changed
versionControl.checkout(branch);
versionControl.pull(branch);
String serverCommit = appSummary.getRepository().getCommit();
String localCommit = versionControl.getCommit();
if (localCommit == null || !localCommit.equals(serverCommit)) {
project.setWarn(true);
PluginMessages.log("Server commit: " + serverCommit + " does not match Git repository for branch " + branch + ": " + versionControl.getCommit() + ".", IStatus.WARNING);
}
// save
WorkflowProjectManager.getInstance().save(project);
// branch
if (progressMonitor != null)
progressMonitor.progress(10);
if (project.checkRequiredVersion(5, 5, 34))
pkgDownloadServicePath = "Packages?format=json&nonVersioned=true";
} else {
// non-git -- delete existing asset dir
if (assetDir.exists())
PluginUtil.deleteDirectory(assetDir);
if (!assetDir.mkdirs())
throw new DiscoveryException("Unable to create asset directory: " + assetDir);
pkgDownloadServicePath = "Packages?format=json&topLevel=true";
}
if (pkgDownloadServicePath != null && progressMonitor != null) {
if (gitRepo.isSyncAssetArchive())
pkgDownloadServicePath += "&archive=true";
String json = restfulServer.invokeResourceService(pkgDownloadServicePath);
Download download = new Download(new JSONObject(json));
if (!StringHelper.isEmpty(download.getUrl())) {
URL url = new URL(download.getUrl() + "&recursive=true");
IFolder tempFolder = project.getTempFolder();
IFile tempFile = tempFolder.getFile("/pkgs" + StringHelper.filenameDateToString(new Date()) + ".zip");
IProgressMonitor subMonitor = new SubProgressMonitor(((SwtProgressMonitor) progressMonitor).getWrappedMonitor(), 5);
try {
PluginUtil.downloadIntoProject(project.getSourceProject(), url, tempFolder, tempFile, "Download Packages", subMonitor);
PluginUtil.unzipProjectResource(project.getSourceProject(), tempFile, null, project.getAssetFolder(), subMonitor);
} catch (FileNotFoundException ex) {
if (isGit)
PluginMessages.uiMessage("Extra/Archived packages not retrieved. Showing only assets from Git.", "Load Workflow Project", PluginMessages.INFO_MESSAGE);
else
throw ex;
}
}
}
} catch (ZipException ze) {
throw ze;
} catch (IOException ex) {
PluginMessages.uiMessage("Extra/Archived packages not retrieved. Showing only assets from Git.", "Load Workflow Project", PluginMessages.INFO_MESSAGE);
}
}
} else if (project.getPersistType() == WorkflowProject.PersistType.None) {
restfulServer = new RestfulServer(null, project.getUser().getUsername(), project.getServiceUrl());
VersionControl dummyVersionControl = new VersionControlDummy();
dummyVersionControl.connect(null, null, null, project.getProjectDir());
restfulServer.setVersionControl(dummyVersionControl);
restfulServer.setRootDirectory(project.getAssetDir());
} else {
String jdbcUrl = project.getMdwDataSource().getJdbcUrlWithCredentials();
if (jdbcUrl == null)
throw new DataAccessException("Please specify a valid JDBC URL in your MDW Project Settings");
if (project.getMdwDataSource().getSchemaOwner() == null)
// don't qualify queries
DBMappingUtil.setSchemaOwner("");
else
DBMappingUtil.setSchemaOwner(project.getMdwDataSource().getSchemaOwner());
restfulServer = new RestfulServer(jdbcUrl, project.getUser().getUsername(), project.getServiceUrl());
connProps.put("defaultRowPrefetch", String.valueOf(MdwPlugin.getSettings().getJdbcFetchSize()));
}
cacheRefresh = new CacheRefresh(project, restfulServer);
boolean oldNamespaces = project.isOldNamespaces();
boolean remoteRetrieve = project.isFilePersist() && project.checkRequiredVersion(5, 5, 19);
restfulServer.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
restfulServer.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
mainFrame.startSession(project.getUser().getUsername(), restfulServer, progressMonitor, connProps, oldNamespaces, remoteRetrieve);
restfulServer.setDataModel(mainFrame.getDataModel());
mainFrame.dao.setCurrentServer(restfulServer);
dataAccess = new PluginDataAccess(project, mainFrame.getDataModel(), mainFrame.dao);
// they've already been retrieved
dataAccess.organizeRuleSets();
// static supportedSchemaVersion has just been set, so save it at
// instance level
dataAccess.setSupportedSchemaVersion(DataAccess.supportedSchemaVersion);
if (project.getPersistType() == WorkflowProject.PersistType.Git && !project.isRemote()) {
try {
mainFrame.dao.checkServerOnline();
} catch (DataAccessOfflineException offlineEx) {
if (MdwPlugin.getSettings().isLogConnectErrors())
PluginMessages.log(offlineEx);
}
}
dataAccess.getVariableTypes(true);
try {
// override mainframe's settings for look-and-feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
PluginMessages.log(ex);
}
System.setProperty("awt.useSystemAAFontSettings", "on");
System.setProperty("swing.aatext", "true");
} finally {
timer.stopAndLog();
}
}
use of com.centurylink.mdw.designer.auth.MdwAuthenticator in project mdw-designer by CenturyLinkCloud.
the class WorkflowProjectManager method authenticate.
/**
* Authenticates using the designated authenticator impl.
*/
public void authenticate(Authenticator authenticator, String user, String password, boolean saveInSecureStore) throws MdwSecurityException {
String key = authenticator.getClass().getName() + "_" + authenticator.getKey();
authenticatedUsers.remove(key);
try {
authenticator.authenticate(user, password);
if (saveInSecureStore) {
try {
ISecurePreferences securePrefs = SecurePreferencesFactory.getDefault();
securePrefs.put(PreferenceConstants.PREFS_MDW_USER + "_" + key, user, false);
securePrefs.put(PreferenceConstants.PREFS_MDW_PASSWORD + "_" + key, password, true);
securePrefs.flush();
} catch (Exception ex) {
// don't prevent user from being authenticated because of
// this
PluginMessages.log(ex);
}
}
if (authenticator instanceof MdwAuthenticator)
authenticatedUsers.put(key, new User(user, password, ((MdwAuthenticator) authenticator).getJwtToken()));
else
authenticatedUsers.put(key, new User(user, password, null));
} catch (MdwSecurityException ex) {
PluginMessages.log(ex);
throw ex;
} catch (Exception ex) {
PluginMessages.log(ex);
throw new MdwSecurityException(ex.getMessage(), ex);
}
}
use of com.centurylink.mdw.designer.auth.MdwAuthenticator in project mdw-designer by CenturyLinkCloud.
the class WorkflowProjectManager method getAuthenticatedUser.
/**
* Triggers automatic authentication if credentials are in Eclipse secure
* store.
*/
public User getAuthenticatedUser(Authenticator authenticator) {
String key = authenticator.getClass().getName() + "_" + authenticator.getKey();
User authUser = authenticatedUsers.get(key);
if (authUser == null) {
try {
ISecurePreferences securePrefs = SecurePreferencesFactory.getDefault();
String user = securePrefs.get(PreferenceConstants.PREFS_MDW_USER + "_" + key, "");
if (user.length() > 0) {
String password = securePrefs.get(PreferenceConstants.PREFS_MDW_PASSWORD + "_" + key, "");
if (password.length() > 0) {
try {
authenticate(authenticator, user, password, false);
if (authenticator instanceof MdwAuthenticator)
authUser = new User(user, password, ((MdwAuthenticator) authenticator).getJwtToken());
else
authUser = new User(user, password, null);
} catch (MdwSecurityException ex) {
// prevent repeated attempts to auto-authenticate
securePrefs.put(PreferenceConstants.PREFS_MDW_USER + "_" + key, "", false);
securePrefs.flush();
}
}
}
} catch (Exception ex) {
// just log exception and force user to log in -- if pw expired
// they'll enter the new one
PluginMessages.log(ex);
}
}
return authUser;
}
Aggregations