Skip to content

Commit

Permalink
[JBPM-10029] Add username and password as parameters to the Webservic…
Browse files Browse the repository at this point in the history
…eWorkItemHandler
  • Loading branch information
abhijithumbe committed Mar 1, 2022
1 parent c6f0191 commit 0810f6c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
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() throws Exception {

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

0 comments on commit 0810f6c

Please sign in to comment.