Search in sources :

Example 1 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectLoginContentProvider method run.

/**
 * @see org.eclipse.ui.intro.config.IIntroAction#run(org.eclipse.ui.intro.IIntroSite,
 *      java.util.Properties)
 */
@Override
public void run(IIntroSite site, Properties params) {
    String username = params.getProperty("username", "");
    String password = params.getProperty("password", "");
    String savecreds = params.getProperty("savecreds", "");
    if (username.trim().isEmpty() || password.trim().isEmpty()) {
        // Using MessageDialog to prevent this from cluttering up the logs
        MessageDialog.openWarning(site.getShell(), "Login to hale connect", "You must provide both user name and password to login to hale connect.");
        return;
    }
    HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    try {
        if (hcs.login(username, password)) {
            if ("true".equalsIgnoreCase(savecreds)) {
                try {
                    HaleConnectUIPlugin.storeUsername(username);
                    HaleConnectUIPlugin.storePassword(password);
                } catch (StorageException e) {
                    log.error("hale connect credentials could not be saved.", e);
                }
            }
            log.userInfo("Login to hale connect successful.");
            // Close and reopen the intro to update the displayed message
            IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro();
            if (introPart != null) {
                PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart);
                PlatformUI.getWorkbench().getIntroManager().showIntro(site.getWorkbenchWindow(), false);
            }
        } else {
            log.userWarn("Login to hale connect failed, please check the credentials.");
        }
    } catch (HaleConnectException e) {
        log.userError("An error occurred while trying to login to hale connect", e);
    }
}
Also used : HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) IIntroPart(org.eclipse.ui.intro.IIntroPart) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 2 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectLoginHandler method createLoginDialog.

/**
 * Create a hale connect login dialog using the given {@link Shell}.
 *
 * @param parent parent shell
 * @return the login dialog
 */
public static HaleConnectLoginDialog createLoginDialog(Shell parent) {
    HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    String username = "";
    String password = "";
    try {
        username = HaleConnectUIPlugin.getStoredUsername();
        password = HaleConnectUIPlugin.getStoredPassword();
    } catch (StorageException e) {
        log.error("Failed to retrieve hale connect credentials from preferences store", e);
    }
    if (hcs.isLoggedIn()) {
        if (!MessageDialog.openQuestion(parent, "Login to hale connect", MessageFormat.format("You are currently logged in as \"{0}\". Do you wish to log in again?", hcs.getSession().getUsername()))) {
            return null;
        } else if (hcs.getSession().getUsername().equals(username)) {
            // Don't fill in from preferences if stored user name was used
            // to login before
            username = "";
            password = "";
        }
    }
    HaleConnectLoginDialog loginDialog = new HaleConnectLoginDialog(parent);
    loginDialog.setTitleAreaColor(new RGB(168, 208, 244));
    loginDialog.setTitleImage(HaleConnectImages.getImageRegistry().get(HaleConnectImages.IMG_HCLOGO_DIALOG));
    loginDialog.setUsername(username);
    loginDialog.setPassword(password);
    return loginDialog;
}
Also used : HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) RGB(org.eclipse.swt.graphics.RGB) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 3 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectLogoutHandler method execute.

/**
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell parent = HandlerUtil.getActiveShell(event);
    if (!MessageDialog.openConfirm(parent, "Clear hale connect credentials", "This will invalidate your current hale connect session and remove all stored credentials.")) {
        return null;
    }
    HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    hcs.clearSession();
    try {
        HaleConnectUIPlugin.storeUsername("");
        HaleConnectUIPlugin.storePassword("");
        log.userInfo("hale connect credentials cleared");
    } catch (StorageException e) {
        log.userError("Error clearing credentials", e);
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 4 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectSourceProvider method dispose.

/**
 * @see org.eclipse.ui.ISourceProvider#dispose()
 */
@Override
public void dispose() {
    final HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    hcs.removeListener(listener);
}
Also used : HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)

Example 5 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectExtendedPreferencePage method updateBasepaths.

private void updateBasepaths() {
    HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    if (defaults.getBooleanValue()) {
        // Force default values
        hcs.getBasePathManager().setBasePath(HaleConnectServices.USER_SERVICE, PreferenceInitializer.HALE_CONNECT_BASEPATH_USERS_DEFAULT);
        hcs.getBasePathManager().setBasePath(HaleConnectServices.BUCKET_SERVICE, PreferenceInitializer.HALE_CONNECT_BASEPATH_DATA_DEFAULT);
        hcs.getBasePathManager().setBasePath(HaleConnectServices.PROJECT_STORE, PreferenceInitializer.HALE_CONNECT_BASEPATH_PROJECTS_DEFAULT);
        hcs.getBasePathManager().setBasePath(HaleConnectServices.WEB_CLIENT, PreferenceInitializer.HALE_CONNECT_BASEPATH_CLIENT_DEFAULT);
    } else {
        // Use individually configured values
        hcs.getBasePathManager().setBasePath(HaleConnectServices.USER_SERVICE, usersBasepath.getStringValue());
        hcs.getBasePathManager().setBasePath(HaleConnectServices.BUCKET_SERVICE, dataBasepath.getStringValue());
        hcs.getBasePathManager().setBasePath(HaleConnectServices.PROJECT_STORE, projectsBasepath.getStringValue());
        hcs.getBasePathManager().setBasePath(HaleConnectServices.WEB_CLIENT, clientBasepath.getStringValue());
    }
    if (hcs.isLoggedIn()) {
        hcs.clearSession();
        MessageDialog.openInformation(getShell(), "hale connect preferences", "You have been logged out from hale connect.");
    }
}
Also used : HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)

Aggregations

HaleConnectService (eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)13 StorageException (org.eclipse.equinox.security.storage.StorageException)6 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)5 GridData (org.eclipse.swt.layout.GridData)4 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Label (org.eclipse.swt.widgets.Label)2 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 HaleConnectOrganisationInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo)1 HaleConnectLoginDialog (eu.esdihumboldt.hale.io.haleconnect.ui.HaleConnectLoginDialog)1 PasswordFieldEditor (eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 VelocityContext (org.apache.velocity.VelocityContext)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1