use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class DefaultStreamlineAuthorizer method mayBeAssignAdminRole.
private void mayBeAssignAdminRole() {
LOG.info("Checking if admin users have admin role");
Role adminRole = catalogService.getRole(Roles.ROLE_ADMIN).orElseGet(() -> {
Role admin = new Role();
admin.setName("ROLE_ADMIN");
admin.setDisplayName("Admin");
admin.setDescription("Super user role that has all the system roles and privileges");
admin.setMetadata("{\"colorCode\":\"#8261be\",\"colorLabel\":\"purple\",\"icon\":\"gears\", \"menu\": [\"schemaRegistry\", \"modelRegistry\", \"udf\", \"dashboard\", \"topology\", \"authorizer\", \"notifier\", \"customprocessor\", \"servicepool\", \"environments\"], \"capabilities\": [{\"Applications\": \"Edit\"}, {\"Service Pool\": \"Edit\"}, {\"Environments\": \"Edit\"}, {\"Users\": \"Edit\"}, {\"Dashboard\": \"Edit\"}]}");
admin.setSystem(false);
return catalogService.addRole(admin);
});
adminUsers.stream().map(userName -> catalogService.getUser(userName)).filter(user -> {
if (userHasRole(user, Roles.ROLE_ADMIN)) {
LOG.info("user '{}' already has '{}'", user, Roles.ROLE_ADMIN);
return false;
} else {
return true;
}
}).forEach(user -> catalogService.addUserRole(user.getId(), adminRole.getId()));
}
use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogResource method deleteRole.
@DELETE
@Path("/roles/{id}")
@Timed
public Response deleteRole(@PathParam("id") Long roleId, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
Role role = catalogService.removeRole(roleId);
if (role != null) {
return WSUtils.respondEntity(role, OK);
}
throw EntityNotFoundException.byId(roleId.toString());
}
use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogResource method mayBeFillSidId.
// translate sid name to sid id if only name is provided
private void mayBeFillSidId(AclEntry aclEntry) {
if (aclEntry.getSidId() == null) {
if (!StringUtils.isEmpty(aclEntry.getSidName())) {
String name = aclEntry.getSidName();
if (aclEntry.getSidType() == AclEntry.SidType.USER) {
User user = catalogService.getUser(name);
if (user == null) {
throw EntityNotFoundException.byName("User name : " + name);
}
aclEntry.setSidId(user.getId());
} else {
Role role = catalogService.getRole(name).orElseThrow(() -> EntityNotFoundException.byName("Role name : " + name));
aclEntry.setSidId(role.getId());
}
} else {
throw new IllegalArgumentException("Sid id or Sid name must be provided");
}
}
}
use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogResource method addRole.
@POST
@Path("/roles")
@Timed
public Response addRole(Role role, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
Role createdRole = catalogService.addRole(role);
return WSUtils.respondEntity(createdRole, CREATED);
}
use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.
the class SecurityCatalogResource method shouldAllowAclGet.
private boolean shouldAllowAclGet(AclEntry aclEntry, SecurityContext securityContext) {
if (SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN)) {
return true;
}
User currentUser = getCurrentUser(securityContext);
Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser);
return matches(aclEntry, currentUser, currentUserRoles);
}
Aggregations