if (isUserInRole) {
return true;
}
//Find the group for the role, if not found return false
IGroupMember groupForRole = GroupService.findGroup(role);
if (groupForRole == null) {
final EntityIdentifier[] results = GroupService.searchForGroups(role, GroupService.IS, IPerson.class);
if (results == null || results.length == 0) {
return false;
}
if (results.length > 1) {
this.logger.warn(results.length + " groups were found for role '" + role + "'. The first result will be used.");
}
groupForRole = GroupService.getGroupMember(results[0]);
}
//Load the group information about the current user
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(this.getWrappedRequest());
final IPerson person = userInstance.getPerson();
final EntityIdentifier personEntityId = person.getEntityIdentifier();
final IGroupMember personGroupMember = GroupService.getGroupMember(personEntityId);
return personGroupMember.isDeepMemberOf(groupForRole);
}