Search in sources :

Example 1 with GrantRequest

use of io.cdap.cdap.proto.security.GrantRequest in project cdap by caskdata.

the class AuthorizationClient method grant.

@Override
public void grant(Authorizable authorizable, Principal principal, Set<? extends Permission> permissions) throws AccessException {
    GrantRequest grantRequest = new GrantRequest(authorizable, principal, permissions);
    URL url = resolveURL(AUTHORIZATION_BASE + "/privileges/grant");
    HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(grantRequest)).build();
    executePrivilegeRequest(request);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) GrantRequest(io.cdap.cdap.proto.security.GrantRequest) URL(java.net.URL)

Example 2 with GrantRequest

use of io.cdap.cdap.proto.security.GrantRequest in project cdap by caskdata.

the class AuthorizationHandler method grant.

@Path("/privileges/grant")
@POST
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void grant(FullHttpRequest httpRequest, HttpResponder httpResponder) throws BadRequestException, FeatureDisabledException, UnknownHostException, AccessException {
    ensureSecurityEnabled();
    GrantRequest request = parseBody(httpRequest, GrantRequest.class);
    if (request == null) {
        throw new BadRequestException("Missing request body");
    }
    permissionManager.grant(request.getAuthorizable(), request.getPrincipal(), getRequestPermissions(request));
    httpResponder.sendStatus(HttpResponseStatus.OK);
    createLogEntry(httpRequest, HttpResponseStatus.OK);
}
Also used : GrantRequest(io.cdap.cdap.proto.security.GrantRequest) BadRequestException(io.cdap.cdap.common.BadRequestException) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Aggregations

GrantRequest (io.cdap.cdap.proto.security.GrantRequest)2 BadRequestException (io.cdap.cdap.common.BadRequestException)1 AuditPolicy (io.cdap.cdap.common.security.AuditPolicy)1 HttpRequest (io.cdap.common.http.HttpRequest)1 URL (java.net.URL)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1