Search in sources :

Example 16 with Role

use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.

the class SecurityCatalogResource method shouldAllowAclAddOrUpdate.

private boolean shouldAllowAclAddOrUpdate(AclEntry aclEntry, SecurityContext securityContext) {
    if (SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN)) {
        return true;
    }
    User currentUser = getCurrentUser(securityContext);
    // check if the current user is the owner or can grant permission on the specific object
    EnumSet<Permission> remaining = aclEntry.getPermissions();
    Collection<AclEntry> userAcls = catalogService.listUserAcls(currentUser.getId(), aclEntry.getObjectNamespace(), aclEntry.getObjectId());
    for (AclEntry userAcl : userAcls) {
        if (userAcl.isOwner()) {
            return true;
        } else if (userAcl.isGrant()) {
            remaining.removeAll(userAcl.getPermissions());
            if (remaining.isEmpty()) {
                return true;
            }
        }
    }
    // check if any roles that the current user belongs to is the owner or can grant
    Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser);
    for (Role role : currentUserRoles) {
        Collection<AclEntry> roleAcls = catalogService.listRoleAcls(role.getId(), aclEntry.getObjectNamespace(), aclEntry.getObjectId());
        for (AclEntry roleAcl : roleAcls) {
            if (roleAcl.isOwner()) {
                return true;
            } else if (roleAcl.isGrant()) {
                remaining.removeAll(roleAcl.getPermissions());
                if (remaining.isEmpty()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) Role(com.hortonworks.streamline.streams.security.catalog.Role) User(com.hortonworks.streamline.streams.security.catalog.User) Permission(com.hortonworks.streamline.streams.security.Permission) AclEntry(com.hortonworks.streamline.streams.security.catalog.AclEntry)

Example 17 with Role

use of com.hortonworks.streamline.streams.security.catalog.Role in project streamline by hortonworks.

the class SecurityCatalogResource method addChildRole.

@POST
@Path("/roles/{parentRoleName}/children/{childRoleName}")
@Timed
public Response addChildRole(@PathParam("parentRoleName") String parentRoleName, @PathParam("childRoleName") String childRoleName, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
    if (childRoleName.equals(parentRoleName)) {
        throw new IllegalArgumentException("Child role is same as parent role");
    }
    Long parentId = getIdFromRoleName(parentRoleName);
    Long childId = getIdFromRoleName(childRoleName);
    Role childRole = catalogService.getRole(childId);
    if (childRole != null) {
        RoleHierarchy roleHierarchy = catalogService.addChildRole(parentId, childId);
        return WSUtils.respondEntity(roleHierarchy, OK);
    }
    throw EntityNotFoundException.byId(childId.toString());
}
Also used : UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) Role(com.hortonworks.streamline.streams.security.catalog.Role) RoleHierarchy(com.hortonworks.streamline.streams.security.catalog.RoleHierarchy) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Role (com.hortonworks.streamline.streams.security.catalog.Role)17 UserRole (com.hortonworks.streamline.streams.security.catalog.UserRole)14 User (com.hortonworks.streamline.streams.security.catalog.User)9 Timed (com.codahale.metrics.annotation.Timed)6 QueryParam (com.hortonworks.registries.common.QueryParam)6 AclEntry (com.hortonworks.streamline.streams.security.catalog.AclEntry)6 Path (javax.ws.rs.Path)6 Permission (com.hortonworks.streamline.streams.security.Permission)5 RoleHierarchy (com.hortonworks.streamline.streams.security.catalog.RoleHierarchy)4 POST (javax.ws.rs.POST)4 StorableKey (com.hortonworks.registries.storage.StorableKey)3 AuthenticationContext (com.hortonworks.streamline.streams.security.AuthenticationContext)3 Roles (com.hortonworks.streamline.streams.security.Roles)3 SecurityUtil (com.hortonworks.streamline.streams.security.SecurityUtil)3 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)3 ArrayList (java.util.ArrayList)3 EnumSet (java.util.EnumSet)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 DELETE (javax.ws.rs.DELETE)3