Search in sources :

Example 6 with Role

use of co.cask.cdap.proto.security.Role in project cdap by caskdata.

the class AuthorizationHandler method dropRole.

@Path("/roles/{role-name}")
@DELETE
public void dropRole(HttpRequest httpRequest, HttpResponder httpResponder, @PathParam("role-name") String roleName) throws Exception {
    ensureSecurityEnabled();
    authorizer.dropRole(new Role(roleName));
    httpResponder.sendStatus(HttpResponseStatus.OK);
    createLogEntry(httpRequest, HttpResponseStatus.OK);
}
Also used : Role(co.cask.cdap.proto.security.Role) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 7 with Role

use of co.cask.cdap.proto.security.Role in project cdap by caskdata.

the class AuthorizationHandler method removeRoleFromPrincipal.

@Path("/{principal-type}/{principal-name}/roles/{role-name}")
@DELETE
public void removeRoleFromPrincipal(HttpRequest httpRequest, HttpResponder httpResponder, @PathParam("principal-type") String principalType, @PathParam("principal-name") String principalName, @PathParam("role-name") String roleName) throws Exception {
    ensureSecurityEnabled();
    Principal principal = new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase()));
    authorizer.removeRoleFromPrincipal(new Role(roleName), principal);
    httpResponder.sendStatus(HttpResponseStatus.OK);
    createLogEntry(httpRequest, HttpResponseStatus.OK);
}
Also used : Role(co.cask.cdap.proto.security.Role) Principal(co.cask.cdap.proto.security.Principal) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 8 with Role

use of co.cask.cdap.proto.security.Role in project cdap by caskdata.

the class RemoveRoleFromPrincipalCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String roleName = arguments.get("role-name");
    String principalType = arguments.get("principal-type");
    String principalName = arguments.get("principal-name");
    client.removeRoleFromPrincipal(new Role(roleName), new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())));
    output.printf("Successfully removed role '%s' from %s '%s'\n", roleName, principalType, principalName);
}
Also used : Role(co.cask.cdap.proto.security.Role) Principal(co.cask.cdap.proto.security.Principal)

Example 9 with Role

use of co.cask.cdap.proto.security.Role in project cdap by caskdata.

the class DropRoleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String roleName = arguments.get("role-name");
    client.dropRole(new Role(roleName));
    output.printf("Successfully dropped role '%s'\n", roleName);
}
Also used : Role(co.cask.cdap.proto.security.Role)

Example 10 with Role

use of co.cask.cdap.proto.security.Role in project cdap by caskdata.

the class InMemoryAuthorizer method enforce.

@Override
public void enforce(EntityId entity, Principal principal, Set<Action> actions) throws UnauthorizedException {
    // super users do not have any enforcement
    if (superUsers.contains(principal) || superUsers.contains(allSuperUsers)) {
        return;
    }
    // actions allowed for this principal
    Set<Action> allowed = getActions(entity, principal);
    if (allowed.containsAll(actions)) {
        return;
    }
    Set<Action> allowedForRoles = new HashSet<>();
    // actions allowed for any of the roles to which this principal belongs if its not a role
    if (principal.getType() != Principal.PrincipalType.ROLE) {
        for (Role role : getRoles(principal)) {
            allowedForRoles.addAll(getActions(entity, role));
        }
    }
    if (!allowedForRoles.containsAll(actions)) {
        throw new UnauthorizedException(principal, Sets.difference(actions, allowed), entity);
    }
}
Also used : Role(co.cask.cdap.proto.security.Role) Action(co.cask.cdap.proto.security.Action) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) HashSet(java.util.HashSet)

Aggregations

Role (co.cask.cdap.proto.security.Role)15 Principal (co.cask.cdap.proto.security.Principal)8 Path (javax.ws.rs.Path)4 NamespaceId (co.cask.cdap.proto.id.NamespaceId)3 Privilege (co.cask.cdap.proto.security.Privilege)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 AlreadyExistsException (co.cask.cdap.security.spi.authorization.AlreadyExistsException)2 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 RowMaker (co.cask.cdap.cli.util.RowMaker)1 Table (co.cask.cdap.cli.util.table.Table)1 AuthorizationClient (co.cask.cdap.client.AuthorizationClient)1 FeatureDisabledException (co.cask.cdap.common.FeatureDisabledException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 CommonNettyHttpServiceBuilder (co.cask.cdap.common.http.CommonNettyHttpServiceBuilder)1 Action (co.cask.cdap.proto.security.Action)1 MasterAuthenticationContext (co.cask.cdap.security.auth.context.MasterAuthenticationContext)1