use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogResource method filter.
private Collection<AclEntry> filter(Collection<AclEntry> aclEntries, SecurityContext securityContext) {
User currentUser = getCurrentUser(securityContext);
Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser);
boolean isSecurityAdmin = SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
return aclEntries.stream().filter(aclEntry -> isSecurityAdmin || matches(aclEntry, currentUser, currentUserRoles)).collect(Collectors.toSet());
}
use of com.hortonworks.streamline.streams.security.catalog.Role 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.Role in project streamline by hortonworks.
the class SecurityCatalogResource method getRoleUsers.
private Response getRoleUsers(Long roleId) {
Role role = catalogService.getRole(roleId);
Set<Role> rolesToQuery = new HashSet<>();
if (role != null) {
rolesToQuery.add(role);
rolesToQuery.addAll(catalogService.getChildRoles(roleId));
Set<User> res = rolesToQuery.stream().flatMap(r -> catalogService.listUsers(r).stream()).collect(Collectors.toSet());
return WSUtils.respondEntities(res, OK);
}
throw EntityNotFoundException.byId(roleId.toString());
}
use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogResource method addOrUpdateRole.
@PUT
@Path("/roles/{id}")
@Timed
public Response addOrUpdateRole(@PathParam("id") Long roleId, Role role, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
Role newRole = catalogService.addOrUpdateRole(roleId, role);
return WSUtils.respondEntity(newRole, OK);
}
use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogService method checkUserPermissions.
public boolean checkUserPermissions(String objectNamespace, Long objectId, Long userId, EnumSet<Permission> required) {
User user = getUser(userId);
if (user == null) {
return false;
}
EnumSet<Permission> remaining = EnumSet.copyOf(required);
// try direct user acl entry first
List<QueryParam> qps = QueryParam.params(AclEntry.OBJECT_NAMESPACE, objectNamespace, AclEntry.OBJECT_ID, String.valueOf(objectId), AclEntry.SID_TYPE, USER.toString(), AclEntry.SID_ID, String.valueOf(userId));
Collection<AclEntry> acls = listAcls(qps);
if (acls.size() > 1) {
throw new IllegalStateException("More than one ACL entry for " + qps);
} else if (acls.size() == 1) {
AclEntry aclEntry = acls.iterator().next();
remaining.removeAll(aclEntry.getPermissions());
}
// try role based permissions next
if (!remaining.isEmpty() && user.getRoles() != null) {
qps = QueryParam.params(AclEntry.OBJECT_NAMESPACE, objectNamespace, AclEntry.OBJECT_ID, String.valueOf(objectId), AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
acls = listAcls(qps);
Set<Role> userRoles = getAllUserRoles(user);
Iterator<AclEntry> it = acls.iterator();
while (!remaining.isEmpty() && it.hasNext()) {
AclEntry roleEntry = it.next();
if (userRoles.contains(getRole(roleEntry.getSidId()))) {
remaining.removeAll(roleEntry.getPermissions());
}
}
}
return remaining.isEmpty();
}
Aggregations