use of com.hortonworks.streamline.streams.security.catalog.UserRole in project streamline by hortonworks.
the class SecurityCatalogResource method addOrUpdateRoleUsers.
private Response addOrUpdateRoleUsers(Long roleId, Set<Long> userIds) {
List<UserRole> userRoles = new ArrayList<>();
Role roleToQuery = catalogService.getRole(roleId);
Set<Long> currentUserIds = catalogService.listUsers(roleToQuery).stream().map(User::getId).collect(Collectors.toSet());
Set<Long> userIdsToAdd = Sets.difference(userIds, currentUserIds);
Set<Long> userIdsToRemove = Sets.difference(currentUserIds, userIds);
Sets.intersection(currentUserIds, userIds).forEach(userId -> {
userRoles.add(new UserRole(userId, roleId));
});
userIdsToRemove.forEach(userId -> catalogService.removeUserRole(userId, roleId));
userIdsToAdd.forEach(userId -> {
userRoles.add(catalogService.addUserRole(userId, roleId));
});
return WSUtils.respondEntities(userRoles, OK);
}
use of com.hortonworks.streamline.streams.security.catalog.UserRole in project streamline by hortonworks.
the class SecurityCatalogService method addUserRole.
public UserRole addUserRole(Long userId, Long roleId) {
UserRole userRole = new UserRole();
userRole.setUserId(userId);
userRole.setRoleId(roleId);
dao.add(userRole);
return userRole;
}
use of com.hortonworks.streamline.streams.security.catalog.UserRole in project streamline by hortonworks.
the class SecurityCatalogService method removeUserRole.
public UserRole removeUserRole(Long userId, Long roleId) {
UserRole userRole = new UserRole();
userRole.setUserId(userId);
userRole.setRoleId(roleId);
return dao.remove(new StorableKey(UserRole.NAMESPACE, userRole.getPrimaryKey()));
}
use of com.hortonworks.streamline.streams.security.catalog.UserRole in project streamline by hortonworks.
the class SecurityCatalogService method removeRole.
public Role removeRole(Long roleId) {
// check if role is part of any parent roles, if so parent role should be deleted first.
Set<Role> parentRoles = getParentRoles(roleId);
if (!parentRoles.isEmpty()) {
throw new IllegalStateException("Role is a child role of the following parent role(s): " + parentRoles + ". Parent roles must be deleted first.");
}
// check if role has any users
List<QueryParam> qps = QueryParam.params(UserRole.ROLE_ID, String.valueOf(roleId));
Collection<UserRole> userRoles = listUserRoles(qps);
if (!userRoles.isEmpty()) {
throw new IllegalStateException("Role has users");
}
// remove child role associations
qps = QueryParam.params(RoleHierarchy.PARENT_ID, String.valueOf(roleId));
Collection<RoleHierarchy> roleHierarchies = dao.find(RoleHierarchy.NAMESPACE, qps);
LOG.info("Removing child role association for role id {}", roleId);
roleHierarchies.forEach(rh -> removeChildRole(roleId, rh.getChildId()));
// remove permissions assigned to role
qps = QueryParam.params(AclEntry.SID_ID, String.valueOf(roleId), AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
LOG.info("Removing ACL entries for role id {}", roleId);
listAcls(qps).forEach(aclEntry -> removeAcl(aclEntry.getId()));
Role role = new Role();
role.setId(roleId);
return dao.remove(new StorableKey(Role.NAMESPACE, role.getPrimaryKey()));
}
Aggregations