Search in sources :

Example 1 with Credentials

use of org.knime.core.node.workflow.Credentials in project knime-core by knime.

the class OpenCredentialVariablesDialogAction method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    super.run();
    // get workflow
    final WorkflowManager wf = getWorkflow();
    // open the dialog
    final Display d = Display.getDefault();
    // run in UI thread
    d.asyncExec(new Runnable() {

        @Override
        public void run() {
            CredentialsStore store = wf.getCredentialsStore();
            CredentialVariablesDialog dialog = new CredentialVariablesDialog(d.getActiveShell(), store, wf.getName());
            if (dialog.open() == Window.OK) {
                for (String name : store.listNames()) {
                    store.remove(name);
                }
                List<Credentials> credentials = dialog.getCredentials();
                for (Credentials cred : credentials) {
                    store.add(cred);
                }
            }
        }
    });
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) List(java.util.List) Credentials(org.knime.core.node.workflow.Credentials) Display(org.eclipse.swt.widgets.Display)

Example 2 with Credentials

use of org.knime.core.node.workflow.Credentials in project knime-core by knime.

the class WorkflowConfigArtifactsGenerator method extractWorkflowCredentials.

private static void extractWorkflowCredentials(final WorkflowManager wfm, final JsonObjectBuilder builder) {
    Iterable<Credentials> credentials = wfm.getCredentialsStore().getCredentials();
    for (Credentials c : credentials) {
        JsonObjectBuilder val = Json.createObjectBuilder();
        val.add("type", "object");
        JsonObjectBuilder login = Json.createObjectBuilder();
        login.add("type", "string");
        login.add("default", c.getLogin());
        val.add("login", login);
        JsonObjectBuilder pwd = Json.createObjectBuilder();
        pwd.add("type", "string");
        pwd.addNull("default");
        val.add("password", pwd);
        builder.add(CoreConstants.WORKFLOW_CREDENTIALS + c.getName(), val);
    }
}
Also used : JsonObjectBuilder(javax.json.JsonObjectBuilder) Credentials(org.knime.core.node.workflow.Credentials)

Example 3 with Credentials

use of org.knime.core.node.workflow.Credentials in project knime-core by knime.

the class GUIWorkflowLoadHelper method loadCredentials.

/**
 * {@inheritDoc}
 */
@Override
public List<Credentials> loadCredentials(final List<Credentials> credentialsList) {
    // set the ones that were already prompted for into the result list ... don't prompt them again
    final List<Credentials> newCredentialsList = new ArrayList<Credentials>();
    final List<Credentials> credentialsToBePromptedList = new ArrayList<Credentials>();
    for (Credentials c : credentialsList) {
        Credentials updatedCredentials = m_promptedCredentials.get(c.getName());
        if (updatedCredentials != null) {
            newCredentialsList.add(updatedCredentials);
        } else {
            credentialsToBePromptedList.add(c);
        }
    }
    // prompt for details for the credentials that haven't been prompted for
    if (!credentialsToBePromptedList.isEmpty()) {
        // run sync'ly in UI thread
        m_display.syncExec(new Runnable() {

            @Override
            public void run() {
                CredentialVariablesDialog dialog = new CredentialVariablesDialog(m_display.getActiveShell(), credentialsToBePromptedList, m_workflowName);
                if (dialog.open() == Window.OK) {
                    List<Credentials> updateCredentialsList = dialog.getCredentials();
                    newCredentialsList.addAll(updateCredentialsList);
                    updateCredentialsList.stream().filter(c -> StringUtils.isNotEmpty(c.getPassword())).forEach(c -> m_promptedCredentials.put(c.getName(), c));
                } else {
                    newCredentialsList.addAll(credentialsToBePromptedList);
                }
            }
        });
    }
    return newCredentialsList;
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) KNIMEConstants(org.knime.core.node.KNIMEConstants) LoadVersion(org.knime.core.node.workflow.FileWorkflowPersistor.LoadVersion) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) HashMap(java.util.HashMap) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) Display(org.eclipse.swt.widgets.Display) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) AtomicReference(java.util.concurrent.atomic.AtomicReference) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) PreferenceConstants(org.knime.workbench.ui.preferences.PreferenceConstants) ArrayList(java.util.ArrayList) Version(org.knime.core.util.Version) List(java.util.List) Window(org.eclipse.jface.window.Window) Map(java.util.Map) SWT(org.eclipse.swt.SWT) Credentials(org.knime.core.node.workflow.Credentials) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) KNIMEUIPlugin(org.knime.workbench.ui.KNIMEUIPlugin) URI(java.net.URI) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) WorkflowLoadHelper(org.knime.core.node.workflow.WorkflowLoadHelper) ArrayList(java.util.ArrayList) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) ArrayList(java.util.ArrayList) List(java.util.List) Credentials(org.knime.core.node.workflow.Credentials)

Example 4 with Credentials

use of org.knime.core.node.workflow.Credentials in project knime-core by knime.

the class CredentialVariablesDialog method editCredentials.

private void editCredentials(final Credentials cred, final int selectionIdx) {
    CredentialVariablesEditDialog dlg = new CredentialVariablesEditDialog();
    dlg.create();
    dlg.loadFrom(cred);
    if (dlg.open() == Dialog.OK) {
        Credentials var = dlg.getCredential();
        if (var != null) {
            m_table.replace(selectionIdx, var);
            m_table.getViewer().refresh();
        }
    }
}
Also used : Credentials(org.knime.core.node.workflow.Credentials)

Example 5 with Credentials

use of org.knime.core.node.workflow.Credentials in project knime-core by knime.

the class CredentialVariablesDialog method addCredential.

private void addCredential() {
    CredentialVariablesEditDialog dialog = new CredentialVariablesEditDialog();
    if (dialog.open() == Dialog.CANCEL) {
        // if the user has canceled the dialog there is nothing left to do
        return;
    }
    Credentials var = dialog.getCredential();
    if (var == null) {
        // variables was not created
        return;
    }
    // do not add it do WFM directly -> this is done when closing the dialog
    if (!m_table.add(var)) {
        MessageDialog.openWarning(getShell(), "Credential already exists", " A credential with the same name and type already exists. " + "Edit this one if you want to change the value.");
    } else {
        m_table.getViewer().refresh();
    }
    getShell().forceFocus();
}
Also used : Credentials(org.knime.core.node.workflow.Credentials)

Aggregations

Credentials (org.knime.core.node.workflow.Credentials)8 List (java.util.List)2 Display (org.eclipse.swt.widgets.Display)2 CredentialVariablesDialog (org.knime.workbench.ui.masterkey.CredentialVariablesDialog)2 File (java.io.File)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 StringUtils (org.apache.commons.lang3.StringUtils)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1