Search in sources :

Example 1 with MdwAuthenticator

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();
}
Also used : ClearTrustAuthenticator(com.centurylink.mdw.auth.ClearTrustAuthenticator) OAuthAuthenticator(com.centurylink.mdw.auth.OAuthAuthenticator) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) AppSummary(com.centurylink.mdw.designer.model.AppSummary) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) MalformedURLException(java.net.MalformedURLException)

Example 2 with MdwAuthenticator

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();
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) User(com.centurylink.mdw.plugin.User) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) FileNotFoundException(java.io.FileNotFoundException) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) MainFrame(com.centurylink.mdw.designer.MainFrame) URL(java.net.URL) VersionControlDummy(com.centurylink.mdw.dataaccess.VersionControlDummy) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) Download(com.centurylink.mdw.model.Download) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) Date(java.util.Date) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JSONObject(org.json.JSONObject) SwtDialogProvider(com.centurylink.mdw.plugin.designer.dialogs.SwtDialogProvider) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) AppSummary(com.centurylink.mdw.designer.model.AppSummary) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with MdwAuthenticator

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);
    }
}
Also used : User(com.centurylink.mdw.plugin.User) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException)

Example 4 with MdwAuthenticator

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;
}
Also used : User(com.centurylink.mdw.plugin.User) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException)

Aggregations

MdwAuthenticator (com.centurylink.mdw.designer.auth.MdwAuthenticator)4 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)3 User (com.centurylink.mdw.plugin.User)3 XmlException (org.apache.xmlbeans.XmlException)3 CoreException (org.eclipse.core.runtime.CoreException)3 AppSummary (com.centurylink.mdw.designer.model.AppSummary)2 DiscoveryException (com.centurylink.mdw.plugin.designer.DiscoveryException)2 IOException (java.io.IOException)2 ResourceException (org.eclipse.core.internal.resources.ResourceException)2 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 JSONException (org.json.JSONException)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 ClearTrustAuthenticator (com.centurylink.mdw.auth.ClearTrustAuthenticator)1 OAuthAuthenticator (com.centurylink.mdw.auth.OAuthAuthenticator)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 TranslationException (com.centurylink.mdw.common.exception.TranslationException)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 VersionControl (com.centurylink.mdw.dataaccess.VersionControl)1 VersionControlDummy (com.centurylink.mdw.dataaccess.VersionControlDummy)1