4.15. User Task calls
TaskClient class. The API is intended for developers to allow direct managing of the lifecycle of User Tasks. End users are advised to use the Business Central web application for User Task management.
taskId: ID of the target Task instance usually extracted from the currently selected User Task in the user task list in the user interfaceuserId: ID of the user that is executing the action called by the method; usually the ID of the user that is logged in
org.kie.api.task.TaskService class:
void start(long taskId, String userId); void stop(long taskId, String userId); void release(long taskId, String userId); void suspend(long taskId, String userId); void resume(long taskId, String userId); void skip(long taskId, String userId); void delegate(long taskId, String userId, String targetUserId); void complete(long taskId, String userId, Map<String, Object> results);
Example 4.13. Starting and completing a simple user task
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.manager.RuntimeManager;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.api.task.TaskService;
import org.kie.api.task.model.TaskSummary;
....
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
// John is assigned a task and he completes it
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
TaskSummary task = list.get(0);
logger.info("John is executing task {}", task.getName());
taskService.start(task.getId(), "john");
taskService.complete(task.getId(), "john", null);
...
4.15.1. Actor assignment calls
ActorID or the GroupID parameter, which define the users who can or should execute the User Tasks. It is in the Task List of these users the Task appears.
Example 4.14. Adding user Kris and group Developers on taskSession
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task");
TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
TaskServiceSession taskSession = taskService.createSession();
// registering new user and group:
taskSession.addUser(new User("Kris"));
taskSession.addGroup(new Group("Developers"));admin roles as well as your custom roles.
Example 4.15. Requesting the list of tasks the user is a potential owner of
List<String> groups = new ArrayList<String>();
groups.add("sales");
taskClient.getTasksAssignedAsPotentialOwner("sales-rep", groups, "en-UK", taskSummaryHandler);Important
Administrator is the administrator of each Task. It is therefore recommended to always define at least user Administrator when registering the list of valid users with the User Task service.
4.15.2. Connecting to custom directory information services
- Create an implementation of the UserGroupInfoProducer interface and provide your own custom callback (see Section 4.15.3.1, “Connecting to LDAP”) and user info implementations according to the needs from the producer.This implementation must be annotated with the @Selectable qualifier for it to be found by Business Central. The listing below shows an example LDAP implementation:
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Alternative; import javax.enterprise.inject.Produces; import org.jbpm.services.task.identity.LDAPUserGroupCallbackImpl; import org.jbpm.services.task.identity.LDAPUserInfoImpl; import org.jbpm.shared.services.cdi.Selectable; import org.kie.api.task.UserGroupCallback; import org.kie.internal.task.api.UserInfo; @ApplicationScoped @Alternative @Selectable public class LDAPUserGroupInfoProducer implements UserGroupInfoProducer { private UserGroupCallback callback = new LDAPUserGroupCallbackImpl(true); private UserInfo userInfo = new LDAPUserInfoImpl(true); @Override @Produces public UserGroupCallback produceCallback() { return callback; } @Override @Produces public UserInfo produceUserInfo() { return userInfo; } } - Package your custom implementations (the
LDAPUserGroupInfoProducer, theLDAPUserGroupCallbackImpland theLDAPUserInfoImplclasses from the example above) into a bean archive (jar with META-INF/beans.xml so it can be found by CDI container). Add this jar file tobusiness-central.war/WEB-INF/lib. - Modify
business-central.war/WEB-INF/beans.xmland add the implementation (LDAPUserGroupInfoProducerfrom the example above) as an alternative to be used by Business Central.<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"> <alternatives> <class>com.test.services.producer.LDAPUserGroupInfoProducer</class> </alternatives> <interceptors> <class>org.uberfire.security.server.authz.cdi.RolesInterceptor</class> <class>org.uberfire.security.server.authz.cdi.TraitInterceptor</class> </interceptors> </beans> - Restart your server and your custom callback implementation should now be used by Business Central.
4.15.3. LDAP connection
- ldap.bind.user: username used to connect to the LDAP server (optional if LDAP server accepts anonymous access)
- ldap.bind.pwd: password used to connect to the LDAP server (optional if LDAP server accepts anonymous access)
- ldap.user.ctx: context in LDAP with user information (mandatory)
- ldap.role.ctx: context in LDAP with group and role information (mandatory)
- ldap.user.roles.ctx: context in LDAP with user group and role membership information (optional; if not specified, ldap.role.ctx is used)
- ldap.user.filter: filter used to search for user information; usually contains substitution keys {0}, which are replaced with parameters (mandatory)
- ldap.role.filter: filter used to search for group and role information, usually contains substitution keys {0}, which are replaced with parameters (mandatory)
- ldap.user.roles.filter: filter used to search for user group and role membership information, usually contains substitution keys {0}, which are replaced with parameters (mandatory)
- ldap.user.attr.id: attribute name of the user ID in LDAP (optional; if not specified,
uidis used) - ldap.roles.attr.id: attribute name of the group and role ID in LDAP (optional; if not specified
cnis used) - ldap.user.id.dn: user ID in a DN, instructs the callback to query for user DN before searching for roles (optional, by default
false) - java.naming.factory.initial: initial conntext factory class name (by default
com.sun.jndi.ldap.LdapCtxFactory) - java.naming.security.authentication: authentication type (possible values are
none,simple,strong; by defaultsimple) - java.naming.security.protocol: security protocol to be used; for instance
ssl - java.naming.provider.url: LDAP url (by default
ldap://localhost:389; if the protocol is set tosslthenldap://localhost:636)
4.15.3.1. Connecting to LDAP
- programatically: build a
Propertiesobject with the respective LDAPUserGroupCallbackImpl properties and createLDAPUserGroupCallbackImplwith thePropertiesobject as its parameter.Example 4.16.
import org.kie.api.PropertiesConfiguration; import org.kie.api.task.UserGroupCallback; ... Properties properties = new Properties(); properties.setProperty(LDAPUserGroupCallbackImpl.USER_CTX, "ou=People,dc=my-domain,dc=com"); properties.setProperty(LDAPUserGroupCallbackImpl.ROLE_CTX, "ou=Roles,dc=my-domain,dc=com"); properties.setProperty(LDAPUserGroupCallbackImpl.USER_ROLES_CTX, "ou=Roles,dc=my-domain,dc=com"); properties.setProperty(LDAPUserGroupCallbackImpl.USER_FILTER, "(uid={0})"); properties.setProperty(LDAPUserGroupCallbackImpl.ROLE_FILTER, "(cn={0})"); properties.setProperty(LDAPUserGroupCallbackImpl.USER_ROLES_FILTER, "(member={0})"); UserGroupCallback ldapUserGroupCallback = new LDAPUserGroupCallbackImpl(properties); UserGroupCallbackManager.getInstance().setCallback(ldapUserGroupCallback); - declaratively: create the
jbpm.usergroup.callback.propertiesfile in the root of your application or specify the file location as a system property:-Djbpm.usergroup.callback.properties=FILE_LOCATION_ON_CLASSPATHMake sure to register the LDAP callback when starting the User Task server.#ldap.bind.user= #ldap.bind.pwd= ldap.user.ctx=ou\=People,dc\=my-domain,dc\=com ldap.role.ctx=ou\=Roles,dc\=my-domain,dc\=com ldap.user.roles.ctx=ou\=Roles,dc\=my-domain,dc\=com ldap.user.filter=(uid\={0}) ldap.role.filter=(cn\={0}) ldap.user.roles.filter=(member\={0}) #ldap.user.attr.id= #ldap.roles.attr.id=

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.