Skip to content

Commit 023589d

Browse files
AP-23709: Fix deprecated box auth settings using CredentialsFlowVarChoicesProvider
AP-23709 (Support username and password fields instead of flow variables in OAuth2 Authenticator nodes)
1 parent 1e3c9c3 commit 023589d

File tree

3 files changed

+130
-39
lines changed

3 files changed

+130
-39
lines changed

org.knime.ext.box.authenticator.tests/files/test_snapshots/org.knime.ext.box.authenticator.node.BoxAuthenticatorSettingsTest.snap

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
22
"data" : {
33
"model" : {
4-
"boxApp" : { },
4+
"boxApp" : {
5+
"secret" : {
6+
"credentials" : {
7+
"isHiddenPassword" : false,
8+
"isHiddenSecondFactor" : false,
9+
"username" : ""
10+
}
11+
}
12+
},
513
"authType" : "OAUTH",
614
"redirectUrl" : "http://localhost:33749/"
715
}
@@ -27,13 +35,55 @@
2735
"boxApp" : {
2836
"type" : "object",
2937
"properties" : {
30-
"flowVariable" : {
31-
"type" : "string",
32-
"title" : "App ID and secret (flow variable)",
33-
"description" : "Specifies a credentials flow variable with the app/client ID and secret of the custom Box app.\nThese fields can be found in the configuration settings of your custom Box app.\n"
38+
"secret" : {
39+
"type" : "object",
40+
"properties" : {
41+
"credentials" : {
42+
"type" : "object",
43+
"properties" : {
44+
"password" : {
45+
"type" : "string",
46+
"default" : ""
47+
},
48+
"secondFactor" : {
49+
"type" : "string",
50+
"default" : ""
51+
},
52+
"username" : {
53+
"type" : "string",
54+
"default" : ""
55+
}
56+
},
57+
"default" : {
58+
"isHiddenPassword" : false,
59+
"isHiddenSecondFactor" : false,
60+
"username" : ""
61+
}
62+
},
63+
"flowVarName" : {
64+
"type" : "string"
65+
}
66+
},
67+
"title" : "App ID and secret",
68+
"description" : "Specifies the app/client ID and secret of the custom Box app.\nThese fields can be found in the configuration settings of your custom Box app.\n",
69+
"default" : {
70+
"credentials" : {
71+
"isHiddenPassword" : false,
72+
"isHiddenSecondFactor" : false,
73+
"username" : ""
74+
}
75+
}
3476
}
3577
},
36-
"default" : { }
78+
"default" : {
79+
"secret" : {
80+
"credentials" : {
81+
"isHiddenPassword" : false,
82+
"isHiddenSecondFactor" : false,
83+
"username" : ""
84+
}
85+
}
86+
}
3787
},
3888
"enterpriseId" : {
3989
"type" : "string",
@@ -62,11 +112,12 @@
62112
"type" : "Section",
63113
"elements" : [ {
64114
"type" : "Control",
65-
"scope" : "#/properties/model/properties/boxApp/properties/flowVariable",
115+
"scope" : "#/properties/model/properties/boxApp/properties/secret",
66116
"options" : {
67-
"format" : "dropDown"
68-
},
69-
"providedOptions" : [ "possibleValues" ]
117+
"passwordLabel" : "Secret",
118+
"usernameLabel" : "ID",
119+
"format" : "legacyCredentials"
120+
}
70121
} ]
71122
}, {
72123
"label" : "Authentication method",
@@ -131,10 +182,10 @@
131182
} ],
132183
"displayErrorMessage" : true,
133184
"showTitleAndDescription" : false,
134-
"dependencies" : [ "#/properties/model/properties/boxApp/properties/flowVariable", "#/properties/model/properties/authType", "#/properties/model/properties/enterpriseId", "#/properties/model/properties/redirectUrl" ],
185+
"dependencies" : [ "#/properties/model/properties/boxApp/properties/secret", "#/properties/model/properties/authType", "#/properties/model/properties/enterpriseId", "#/properties/model/properties/redirectUrl" ],
135186
"updateOptions" : {
136187
"updateHandler" : "org.knime.ext.box.authenticator.node.BoxAuthenticatorSettings$LoginUpdateHandler",
137-
"dependencies" : [ "#/properties/model/properties/boxApp/properties/flowVariable", "#/properties/model/properties/authType", "#/properties/model/properties/enterpriseId", "#/properties/model/properties/redirectUrl" ]
188+
"dependencies" : [ "#/properties/model/properties/boxApp/properties/secret", "#/properties/model/properties/authType", "#/properties/model/properties/enterpriseId", "#/properties/model/properties/redirectUrl" ]
138189
}
139190
},
140191
"rule" : {
@@ -160,7 +211,18 @@
160211
"boxApp" : {
161212
"type" : "object",
162213
"properties" : {
163-
"flowVariable" : { }
214+
"secret" : {
215+
"type" : "object",
216+
"properties" : {
217+
"credentials" : { },
218+
"flowVarName" : {
219+
"configPaths" : [ ]
220+
}
221+
},
222+
"deprecatedConfigKeys" : [ {
223+
"deprecated" : [ [ "flowVariable" ] ]
224+
} ]
225+
}
164226
}
165227
},
166228
"authType" : { },
@@ -173,12 +235,16 @@
173235
}
174236
}
175237
},
176-
"initialUpdates" : [ {
177-
"scope" : "#/properties/model/properties/boxApp/properties/flowVariable",
178-
"providedOptionName" : "possibleValues",
179-
"values" : [ {
180-
"indices" : [ ],
181-
"value" : [ ]
182-
} ]
238+
"globalUpdates" : [ {
239+
"trigger" : {
240+
"id" : "after-open-dialog"
241+
},
242+
"triggerInitially" : true,
243+
"dependencies" : [ "#/properties/model/properties/boxApp" ]
244+
}, {
245+
"trigger" : {
246+
"scope" : "#/properties/model/properties/boxApp"
247+
},
248+
"dependencies" : [ "#/properties/model/properties/boxApp" ]
183249
} ]
184250
}

org.knime.ext.box.authenticator/src-deprecated/org/knime/ext/box/authenticator/node/BoxAppSettings.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,46 +50,71 @@
5050

5151
import org.knime.core.node.InvalidSettingsException;
5252
import org.knime.core.node.workflow.CredentialsProvider;
53+
import org.knime.core.webui.node.dialog.defaultdialog.setting.credentials.LegacyCredentials;
54+
import org.knime.core.webui.node.dialog.defaultdialog.widget.validation.custom.CustomValidation;
55+
import org.knime.credentials.base.node.CredentialVariableMigration;
5356
import org.knime.credentials.base.node.CredentialsSettings;
5457
import org.knime.node.parameters.Widget;
55-
import org.knime.node.parameters.widget.choices.ChoicesProvider;
58+
import org.knime.node.parameters.migration.Migration;
59+
import org.knime.node.parameters.updates.ParameterReference;
60+
import org.knime.node.parameters.widget.credentials.Credentials;
61+
import org.knime.node.parameters.widget.credentials.CredentialsWidget;
5662

5763
/**
5864
* Implementation of {@link CredentialsSettings} to supply the ID and secret of
5965
* a confidential OAuth2 app.
6066
*
67+
* Any instance must be annotated with a {@code ValueReference} to {@link Ref}
68+
* for the validation to work.
69+
*
70+
*
6171
* @author Bjoern Lohrmann, KNIME GmbH
6272
*/
6373
@SuppressWarnings("restriction")
6474
public class BoxAppSettings implements CredentialsSettings {
6575

6676
/**
67-
* The name of the Credentials flow variable.
77+
* The credential
6878
*/
69-
@Widget(title = "App ID and secret (flow variable)", //
79+
@Widget(title = "App ID and secret", //
7080
description = """
71-
Specifies a credentials flow variable with the app/client ID and secret of the custom Box app.
81+
Specifies the app/client ID and secret of the custom Box app.
7282
These fields can be found in the configuration settings of your custom Box app.
7383
""")
74-
@ChoicesProvider(CredentialsFlowVarChoicesProvider.class)
75-
public String m_flowVariable;
84+
@Migration(CredentialVariableMigration.class)
85+
@CustomValidation(BoxCredentialValidator.class)
86+
@CredentialsWidget(usernameLabel = "ID", passwordLabel = "Secret") // NOSONAR not a password
87+
88+
public LegacyCredentials m_secret = new LegacyCredentials(new Credentials());
89+
90+
/**
91+
* Used to reference this class for the validation.
92+
*/
93+
public interface Ref extends ParameterReference<BoxAppSettings> {
94+
}
95+
96+
static final class BoxCredentialValidator extends AbstractCredentialsValidator<BoxAppSettings> {
97+
BoxCredentialValidator() {
98+
super(Ref.class);
99+
}
100+
}
76101

77102
@Override
78-
public String flowVariableName() {
79-
return m_flowVariable;
103+
public LegacyCredentials getCredential() {
104+
return m_secret;
80105
}
81106

82107
/**
83-
* If a flow variable has been specified, this method validates that a username
84-
* and password are present in the flow variable. This method should be used
85-
* during the configure phase, to reduce logspam if the credentials flow
86-
* variable is not there yet.
108+
* If a credential has been specified, this method validates that a username and
109+
* password are present. This method should be used during the configure phase,
110+
* to reduce logspam if the credential is not there yet.
87111
*
88112
* @param credsProvider
89-
* Used to access the flow variable.
113+
* Used to access the credential.
90114
* @throws InvalidSettingsException
91-
* when username or password was not present in the flow variable.
115+
* when username or password was not present in the credential.
92116
*/
117+
@Override
93118
public void validateOnConfigure(final CredentialsProvider credsProvider) throws InvalidSettingsException {
94119
if (retrieve(credsProvider).isPresent()) {
95120
validateLogin(credsProvider, "Client/App ID is required");
@@ -98,16 +123,15 @@ public void validateOnConfigure(final CredentialsProvider credsProvider) throws
98123
}
99124

100125
/**
101-
* This method validates both presence and validity of a credentials flow
102-
* variable. This method should be used during the execute phase.
126+
* This method validates both presence and validity of a credential. This method
127+
* should be used during the execute phase.
103128
*
104129
* @param credsProvider
105-
* Used to access the flow variable.
130+
* Used to access the credential.
106131
* @throws InvalidSettingsException
107-
* when flow variable was not present or invalid.
132+
* when credential was not present or invalid.
108133
*/
109134
public void validateOnExecute(final CredentialsProvider credsProvider) throws InvalidSettingsException {
110-
validateFlowVariable(credsProvider);
111135
validateLogin(credsProvider, "Client/App ID is required");
112136
validateSecret(credsProvider, "Client/App secret is required");
113137
}

org.knime.ext.box.authenticator/src-deprecated/org/knime/ext/box/authenticator/node/BoxAuthenticatorSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public EffectPredicate init(final PredicateInitializer i) {
136136
}
137137

138138
@Layout(BoxAppSection.class)
139+
@ValueReference(BoxAppSettings.Ref.class)
139140
BoxAppSettings m_boxApp = new BoxAppSettings();
140141

141142
@Widget(title = "Type", description = "Authentication method to use.")

0 commit comments

Comments
 (0)