-
Using this ReadOnlyIdentityProvider implementation can we make rest api call to fetch users/groups from external systems?
-
How to configure the custom ReadOnlyIdentityProvider implementation to the process engine to query the external systems?
Hi @aravindhrs, you can check this out: https://github.com/hashlash/example-camunda-custom-identity-service,my custom identity is based on this and it’s working fine.You can change UserService/GroupService to call your rest api.
Cheers.
@manda091x i saw the code, you are storing both groups and users into camunda database. In my case, i don’t want to store any users/groups in the database. At runtime i will query for users/groups and assign tasks to the groups/users.
Is it required to perform below step?
public Group save(Group group) {
return repository.save(group);
}
public User save(User user) {
return repository.save(user);
}
Hi @aravindhrs, you can delete spring repository and change user/group service to retrieve data from your rest api, this is just custom identity.To assign task to user/group dynamically in runtime you can implement tasklistener.
Here is some of my code
@Service
//@Transactional
public class UserService {
@Autowired
private RestService restService;
public User findById(String id) {
return restService.findUserById(id);
}
public Collection<User> findAll() {
return restService.findUserAll();
}
// public User save(User user) {
// return repository.save(user);
// }
}
@Service
//@Transactional
public class GroupService {
@Autowired
private RestService restService;
public Group findById(String id) {
return restService.findGroupById(id);
}
public Collection<Group> findAll() {
return (Collection<Group>) restService.findGroupAll();
}
// public Group save(Group group) {
// return repository.save(group);
// }
}
@Service
public class RestService {
@Autowired
private Client<User> userClient;
@Autowired
private Client<Group> groupClient;
@Autowired
private Client<GroupMember> memberClient;
@SuppressWarnings("finally")
@GetMapping("findUserById")
public User findUserById(String id) {
URI uri = null;
try {
uri = new URI(BowmanConfig.GET_USER_URL + "/"+ id);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(uri == null)
return null;
else {
User user = userClient.get(uri);
return user;
}
}
}
@GetMapping("findUserAll")
public Collection<User> findUserAll() {
return CollectionUtils.iterableToCollection(userClient.getAll());
}
@SuppressWarnings("finally")
@GetMapping("findGroupById")
public Group findGroupById(String id) {
URI uri = null;
try {
uri = new URI(BowmanConfig.GET_ROLE_URL + "/"+ id);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(uri == null)
return null;
else {
Group group = groupClient.get(uri);
return group;
}
}
}
@GetMapping("findGroupAll")
public Collection<Group> findGroupAll() {
return CollectionUtils.iterableToCollection(groupClient.getAll());
}
@SuppressWarnings("finally")
public Iterable<GroupMember> findMembers(String groupId, String tenantId){
URI uri = null;
try {
uri = new URI(BowmanConfig.GET_ROLE_USER_URL + "?roleId="+ groupId+"&tenantId="+tenantId);
} catch (URISyntaxException e) {
e.printStackTrace();
} finally {
if(uri == null)
return null;
else {
Iterable<GroupMember> groups = memberClient.getAll(uri);
return groups;
}
}
}
}
RestService retrieves data from my spring data rest api.
In my TaskListener:
Iterable<GroupMember> members = restService.findMembers(groupId, user.getTenantId());
for(GroupMember member:members){
delegateTask.setAssignee(member.getUserId());
// delegateTask.addCandidateUser(member.getUserId());
}