Hi,
i am currently trying to develop a special database connector and would like to offer the user the option to use workflow credentials instead of username/password.
I wanted to follow the example of the DatabaseConnector, but cannot find its source code anywhere (including the NodePit).
The basic problem I am facing is that the credentials-provider is not set in the dialog. Could someone please provide a code snippet that shows how to define a widget that uses credentials?
Thanks,
Dietrich
Hi,
you could use the DialogComponentAuthentication and the SettingsModelAuthentication which can be both found in knime-core.
Hope that helps.
Cheers,
Moritz
That is what I am using, but the credentials provider in the dialog component is always null and therefore the ‘credentials’ option is disabled. The workflow does have credentials.
I thought I am missing some config option or setting and that’s why I wanted to look at a working code example.
Hi,
since I’ve only used it in closed source code, I’ve hacked down a small and dirty example on how to you it using the NumberFormatterNode example project.
org.knime.examples.credentials.zip (17.6 KB)
The node simply takes the credentials and outputs is as a string. The important part is that you have to provide a CredentialsProvider when you access the username and the password from the SettingsModel itself.
I hope this helps.
Cheers,
Moritz
Yes, many thanks - that helped a lot.
For others, here is what was missing:
Our code for the dialog component extends DefaultNodeSettingsPane and we use
m_authenticationModel = OurNodeModel.settingsModelAuthentication();
m_authenticationPanel = new DialogComponentAuthentication(m_authenticationModel, null,
AuthenticationType.USER_PWD, AuthenticationType.CREDENTIALS);
addDialogComponent(m_authenticationPanel);
to add the credentials part of the node configuration. What was missing was that we needed to overwrite the 2 methods save/loadAdditionalSettingsFrom/To:
@Override
public void saveAdditionalSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
m_authenticationModel.saveSettingsTo(settings);
}
@Override
public void loadAdditionalSettingsFrom(final NodeSettingsRO settings,
final DataTableSpec[] specs) throws NotConfigurableException {
try {
m_authenticationModel.loadSettingsFrom(settings);
m_authenticationPanel.loadSettingsFrom(settings, specs, getCredentialsProvider());
} catch (InvalidSettingsException e) {
throw new NotConfigurableException(e.getMessage(), e);
}
}
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.