Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-10029] Add username and password as parameters to the Webservic… #2116

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
@WidParameter(name = "Endpoint"),
@WidParameter(name = "Parameter"),
@WidParameter(name = "Mode"),
@WidParameter(name = "Wrapped")
@WidParameter(name = "Wrapped"),
@WidParameter(name = "Username"),
@WidParameter(name = "Password")
},
results = {
@WidResult(name = "Result", runtimeType = "java.lang.Object")
Expand Down Expand Up @@ -369,7 +371,13 @@ public void executeWorkItem(WorkItem workItem,
}

// apply authorization if needed
applyAuthorization(username, password, client);
String u = (String) workItem.getParameter("Username");
String p = (String) workItem.getParameter("Password");
if (u == null || p == null) {
u = this.username;
p = this.password;
}
applyAuthorization(u, p, client);

//Remove interceptors if using wrapped mode
if (wrapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,50 @@ public void testExecuteSyncOperationWithBasicAuth() throws Exception {
authorizationPolicy.getPassword());
}

@Test
public void testExecuteSyncOperationWithBasicAuthWithParameter() {

HTTPConduit http = Mockito.mock(HTTPConduit.class,
Mockito.CALLS_REAL_METHODS);

when(client.getConduit()).thenReturn(http);

TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Interface",
"someInterface");
workItem.setParameter("Operation",
"someOperation");
workItem.setParameter("Parameter",
"myParam");
workItem.setParameter("Mode",
"SYNC");
workItem.setParameter("Username",
"testusername");
workItem.setParameter("Password",
"testpassword");

WebServiceWorkItemHandler handler = new WebServiceWorkItemHandler(kieSession);

handler.setClients(clients);

handler.executeWorkItem(workItem,
manager);
assertNotNull(manager.getResults());
assertEquals(1,
manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));

assertNotNull(http.getAuthorization());
AuthorizationPolicy authorizationPolicy = http.getAuthorization();
assertEquals("Basic",
authorizationPolicy.getAuthorizationType());
assertEquals("testusername",
authorizationPolicy.getUserName());
assertEquals("testpassword",
authorizationPolicy.getPassword());
}

@Test
public void testExecuteSyncOperationHandlingException() throws Exception {
when(clients.computeIfAbsent(any(), any())).thenReturn(null);
Expand Down