use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogResource method deleteUser.
@DELETE
@Path("/users/{id}")
@Timed
public Response deleteUser(@PathParam("id") Long userId, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
User user = catalogService.removeUser(userId);
if (user != null) {
return WSUtils.respondEntity(user, OK);
}
throw EntityNotFoundException.byId(userId.toString());
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogResource method addOrUpdateUser.
@PUT
@Path("/users/{id}")
@Timed
public Response addOrUpdateUser(@PathParam("id") Long userId, User user, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
User newUser = catalogService.addOrUpdateUser(userId, user);
return WSUtils.respondEntity(newUser, OK);
}
use of com.hortonworks.streamline.streams.security.catalog.User 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.User 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();
}
use of com.hortonworks.streamline.streams.security.catalog.User in project streamline by hortonworks.
the class SecurityCatalogServiceTest method checkUserPermissions.
@Test
public void checkUserPermissions() throws Exception {
SecurityCatalogService catalogService = new SecurityCatalogService(null);
AclEntry userAclEntry = new AclEntry();
userAclEntry.setSidType(AclEntry.SidType.USER);
userAclEntry.setSidId(1L);
userAclEntry.setObjectId(1L);
userAclEntry.setObjectNamespace("topology");
userAclEntry.setPermissions(EnumSet.of(Permission.WRITE));
AclEntry roleAclEntry = new AclEntry();
roleAclEntry.setSidType(AclEntry.SidType.ROLE);
roleAclEntry.setSidId(1L);
roleAclEntry.setObjectId(1L);
roleAclEntry.setObjectNamespace("topology");
roleAclEntry.setPermissions(EnumSet.of(Permission.READ));
Role role = new Role();
role.setId(1L);
role.setName("ROLE_FOO");
List<QueryParam> qps1 = QueryParam.params(AclEntry.OBJECT_NAMESPACE, "topology", AclEntry.OBJECT_ID, "1", AclEntry.SID_TYPE, USER.toString(), AclEntry.SID_ID, "1");
List<QueryParam> qps2 = QueryParam.params(AclEntry.OBJECT_NAMESPACE, "topology", AclEntry.OBJECT_ID, "1", AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
User user = new User();
user.setRoles(Sets.newHashSet("ROLE_FOO"));
new Expectations(catalogService) {
{
catalogService.getUser(anyLong);
result = user;
catalogService.listAcls(qps1);
result = Arrays.asList(userAclEntry);
catalogService.getAllUserRoles(user);
result = Sets.newHashSet(role);
catalogService.listAcls(qps2);
result = Arrays.asList(roleAclEntry);
catalogService.getRole(1L);
result = role;
}
};
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.READ)));
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE)));
assertTrue(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.READ)));
assertFalse(catalogService.checkUserPermissions("topology", 1L, 1L, EnumSet.of(Permission.WRITE, Permission.DELETE)));
}
Aggregations