Search in sources :

Example 1 with MethodArgument

use of io.cdap.cdap.common.internal.remote.MethodArgument in project cdap by caskdata.

the class RemotePrivilegesHandler method listPrivileges.

@POST
@Path("/listPrivileges")
public void listPrivileges(FullHttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    Principal principal = deserializeNext(arguments);
    LOG.trace("Listing grantedPermissions for principal {}", principal);
    Set<GrantedPermission> grantedPermissions = permissionManager.listGrants(principal);
    LOG.debug("Returning grantedPermissions for principal {} as {}", principal, grantedPermissions);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(grantedPermissions));
}
Also used : MethodArgument(io.cdap.cdap.common.internal.remote.MethodArgument) GrantedPermission(io.cdap.cdap.proto.security.GrantedPermission) Principal(io.cdap.cdap.proto.security.Principal) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with MethodArgument

use of io.cdap.cdap.common.internal.remote.MethodArgument in project cdap by caskdata.

the class AbstractRemoteSystemOpsHandler method deserializeNext.

@Nullable
<T> T deserializeNext(Iterator<MethodArgument> arguments, @Nullable Type typeOfT) throws ClassNotFoundException, BadRequestException {
    if (!arguments.hasNext()) {
        throw new BadRequestException("Expected additional elements.");
    }
    MethodArgument argument = arguments.next();
    if (argument == null) {
        return null;
    }
    JsonElement value = argument.getValue();
    if (value == null) {
        return null;
    }
    if (typeOfT != null) {
        return GSON.fromJson(value, typeOfT);
    }
    return GSON.<T>fromJson(value, Class.forName(argument.getType()));
}
Also used : MethodArgument(io.cdap.cdap.common.internal.remote.MethodArgument) JsonElement(com.google.gson.JsonElement) BadRequestException(io.cdap.cdap.common.BadRequestException) Nullable(javax.annotation.Nullable)

Example 3 with MethodArgument

use of io.cdap.cdap.common.internal.remote.MethodArgument in project cdap by caskdata.

the class RemotePrivilegesHandler method revokeAll.

@POST
@Path("/revokeAll")
public void revokeAll(FullHttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    EntityId entityId = deserializeNext(arguments);
    LOG.trace("Revoking all actions on {}", entityId);
    permissionManager.revoke(Authorizable.fromEntityId(entityId));
    LOG.info("Revoked all actions on {} successfully", entityId);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : EntityId(io.cdap.cdap.proto.id.EntityId) MethodArgument(io.cdap.cdap.common.internal.remote.MethodArgument) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with MethodArgument

use of io.cdap.cdap.common.internal.remote.MethodArgument in project cdap by caskdata.

the class RemotePrivilegesHandler method grant.

@POST
@Path("/grant")
public void grant(FullHttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    EntityId entityId = deserializeNext(arguments);
    Principal principal = deserializeNext(arguments);
    Set<? extends Permission> permissions = deserializeNext(arguments, SET_OF_PERMISSIONS);
    LOG.trace("Granting {} on {} to {}", permissions, entityId, principal);
    permissionManager.grant(Authorizable.fromEntityId(entityId), principal, permissions);
    LOG.info("Granted {} on {} to {} successfully", permissions, entityId, principal);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : EntityId(io.cdap.cdap.proto.id.EntityId) MethodArgument(io.cdap.cdap.common.internal.remote.MethodArgument) Principal(io.cdap.cdap.proto.security.Principal) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 5 with MethodArgument

use of io.cdap.cdap.common.internal.remote.MethodArgument in project cdap by caskdata.

the class RemotePrivilegesHandler method revoke.

@POST
@Path("/revoke")
public void revoke(FullHttpRequest request, HttpResponder responder) throws Exception {
    Iterator<MethodArgument> arguments = parseArguments(request);
    EntityId entityId = deserializeNext(arguments);
    Principal principal = deserializeNext(arguments);
    Set<? extends Permission> permissions = deserializeNext(arguments, SET_OF_PERMISSIONS);
    LOG.trace("Revoking {} on {} from {}", permissions, entityId, principal);
    permissionManager.revoke(Authorizable.fromEntityId(entityId), principal, permissions);
    LOG.info("Revoked {} on {} from {} successfully", permissions, entityId, principal);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : EntityId(io.cdap.cdap.proto.id.EntityId) MethodArgument(io.cdap.cdap.common.internal.remote.MethodArgument) Principal(io.cdap.cdap.proto.security.Principal) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

MethodArgument (io.cdap.cdap.common.internal.remote.MethodArgument)5 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 EntityId (io.cdap.cdap.proto.id.EntityId)3 Principal (io.cdap.cdap.proto.security.Principal)3 JsonElement (com.google.gson.JsonElement)1 BadRequestException (io.cdap.cdap.common.BadRequestException)1 GrantedPermission (io.cdap.cdap.proto.security.GrantedPermission)1 Nullable (javax.annotation.Nullable)1