Search in sources :

Example 1 with User

use of com.centurylink.mdw.plugin.User in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method handleLazyUserAuth.

private void handleLazyUserAuth() throws AuthenticationException {
    if (project.isFilePersist() && !project.isRemote()) {
        // authentication not needed
        project.setUser(new User(System.getProperty("user.name")));
    } else {
        // user authentication
        Boolean authenticated = project.isAuthenticated();
        if (authenticated == null)
            throw new AuthenticationException("Not authorized for project: " + project.getName());
        if (!authenticated) {
            LoginDialog loginDialog = new LoginDialog(MdwPlugin.getShell(), project);
            int res = loginDialog.open();
            if (res == Dialog.CANCEL || !project.isAuthenticated())
                throw new AuthenticationException("Not authorized for project: " + project.getName());
        }
    }
}
Also used : User(com.centurylink.mdw.plugin.User) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) LoginDialog(com.centurylink.mdw.plugin.designer.dialogs.LoginDialog)

Example 2 with User

use of com.centurylink.mdw.plugin.User in project mdw-designer by CenturyLinkCloud.

the class ProcessExplorerView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    treeViewer = new TreeViewer(parent) {

        protected void handleTreeExpand(TreeEvent event) {
            if (event.item.getData() instanceof WorkflowProject) {
                final WorkflowProject project = (WorkflowProject) event.item.getData();
                if (project.isFilePersist() && !project.isRemote()) {
                    // authentication not needed
                    project.setUser(new User(System.getProperty("user.name")));
                } else {
                    // user authentication
                    Boolean authenticated = project.isAuthenticated();
                    if (authenticated == null) {
                        // has to be in a separate
                        // thread to take effect
                        event.item.getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                treeViewer.collapseToLevel(project, TreeViewer.ALL_LEVELS);
                            }
                        });
                        return;
                    }
                    if (!authenticated) {
                        LoginDialog loginDialog = new LoginDialog(MdwPlugin.getShell(), project);
                        int res = loginDialog.open();
                        if (res == Dialog.CANCEL || !project.isAuthenticated()) {
                            // has
                            // to
                            // be
                            // in
                            // a
                            // separate
                            // thread
                            // to
                            // take
                            // effect
                            event.item.getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    treeViewer.collapseToLevel(project, TreeViewer.ALL_LEVELS);
                                }
                            });
                            return;
                        }
                    }
                    super.handleTreeExpand(event);
                    return;
                }
            }
            super.handleTreeExpand(event);
        }
    };
    ProcessExplorerContentProvider contentProvider = new ProcessExplorerContentProvider();
    // for
    WorkflowProjectManager.getInstance().addElementChangeListener(contentProvider);
    // project
    // adds/deletes
    treeViewer.setContentProvider(contentProvider);
    treeViewer.setLabelProvider(new ProcessExplorerLabelProvider());
    treeViewer.setInput(WorkflowProjectManager.getInstance().getWorkflowProjects());
    treeViewer.collapseAll();
    clipboard = new Clipboard(parent.getDisplay());
    // action group
    actionGroup = new ProcessExplorerActionGroup(this);
    actionGroup.fillActionBars(getViewSite().getActionBars());
    // context menu
    MenuManager menuMgr = new MdwMenuManager("Process Explorer");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(this);
    contextMenu = menuMgr.createContextMenu(treeViewer.getTree());
    treeViewer.getTree().setMenu(contextMenu);
    getSite().registerContextMenu(menuMgr, treeViewer);
    treeViewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent event) {
            for (Object item : getSelection().toList()) {
                if (!actionGroup.getActionHandler().open((WorkflowElement) item))
                    expand(item);
            }
        }
    });
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            handleSelectionChanged((IStructuredSelection) event.getSelection());
        }
    });
    // drag and drop support
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
    dragSource = new ProcessExplorerDragSource(treeViewer);
    treeViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, transfers, dragSource);
    dropTarget = new ProcessExplorerDropTarget(treeViewer);
    treeViewer.addDropSupport(DND.DROP_MOVE | DND.DROP_COPY, transfers, dropTarget);
    contextListener = new ProcessExplorerContextListener();
    getSite().getPage().addPartListener(contextListener);
    MdwPlugin.getPluginWorkbench().getHelpSystem().setHelp(parent, MdwPlugin.getPluginId() + ".process_explorer_help");
}
Also used : MdwMenuManager(com.centurylink.mdw.plugin.actions.MdwMenuManager) User(com.centurylink.mdw.plugin.User) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeEvent(org.eclipse.swt.events.TreeEvent) IOpenListener(org.eclipse.jface.viewers.IOpenListener) MdwMenuManager(com.centurylink.mdw.plugin.actions.MdwMenuManager) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) LoginDialog(com.centurylink.mdw.plugin.designer.dialogs.LoginDialog) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 3 with User

use of com.centurylink.mdw.plugin.User 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 4 with User

use of com.centurylink.mdw.plugin.User 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 5 with User

use of com.centurylink.mdw.plugin.User 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

User (com.centurylink.mdw.plugin.User)5 MdwAuthenticator (com.centurylink.mdw.designer.auth.MdwAuthenticator)3 XmlException (org.apache.xmlbeans.XmlException)3 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)2 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)2 DiscoveryException (com.centurylink.mdw.plugin.designer.DiscoveryException)2 LoginDialog (com.centurylink.mdw.plugin.designer.dialogs.LoginDialog)2 ResourceException (org.eclipse.core.internal.resources.ResourceException)2 CoreException (org.eclipse.core.runtime.CoreException)2 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 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 VersionControlGit (com.centurylink.mdw.dataaccess.file.VersionControlGit)1 MainFrame (com.centurylink.mdw.designer.MainFrame)1 AppSummary (com.centurylink.mdw.designer.model.AppSummary)1 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)1