use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method setFlowletInstances.
/**
* Increases number of instance for a flowlet within a flow.
*/
@PUT
@Path("/apps/{app-id}/flows/{flow-id}/flowlets/{flowlet-id}/instances")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public synchronized void setFlowletInstances(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("flow-id") String flowId, @PathParam("flowlet-id") String flowletId) throws Exception {
int instances = getInstances(request);
try {
lifecycleService.setInstances(new ProgramId(namespaceId, appId, ProgramType.FLOW, flowId), instances, flowletId);
responder.sendStatus(HttpResponseStatus.OK);
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
} catch (Throwable e) {
if (respondIfElementNotFound(e, responder)) {
return;
}
throw e;
}
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class RouteConfigHttpHandler method storeRouteConfig.
@PUT
@Path("/routeconfig")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void storeRouteConfig(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception {
NamespaceId namespace = new NamespaceId(namespaceId);
ProgramId programId = namespace.app(appId).service(serviceId);
Map<String, Integer> routes = parseBody(request, ROUTE_CONFIG_TYPE);
if (routes == null || routes.isEmpty()) {
throw new BadRequestException("Route config contains invalid format or empty content.");
}
List<ProgramId> nonExistingServices = new ArrayList<>();
for (String version : routes.keySet()) {
ProgramId routeProgram = namespace.app(appId, version).service(serviceId);
if (!lifecycleService.programExists(routeProgram)) {
nonExistingServices.add(routeProgram);
}
}
if (nonExistingServices.size() > 0) {
throw new BadRequestException("The following versions of the application/service could not be found : " + nonExistingServices);
}
RouteConfig routeConfig = new RouteConfig(routes);
if (!routeConfig.isValid()) {
throw new BadRequestException("Route Percentage needs to add up to 100.");
}
routeStore.store(programId, routeConfig);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class SecureStoreHandler method create.
@Path("/{key-name}")
@PUT
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void create(FullHttpRequest httpRequest, HttpResponder httpResponder, @PathParam("namespace-id") String namespace, @PathParam("key-name") String name) throws Exception {
SecureKeyId secureKeyId = new SecureKeyId(namespace, name);
SecureKeyCreateRequest secureKeyCreateRequest = parseBody(httpRequest, SecureKeyCreateRequest.class);
if (secureKeyCreateRequest == null) {
SecureKeyCreateRequest dummy = new SecureKeyCreateRequest("<description>", "<data>", ImmutableMap.of("key", "value"));
throw new BadRequestException("Unable to parse the request. The request body should be of the following format." + " \n" + GSON.toJson(dummy));
}
secureStoreManager.putSecureData(namespace, name, secureKeyCreateRequest.getData(), secureKeyCreateRequest.getDescription(), secureKeyCreateRequest.getProperties());
httpResponder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class AuthorizationHandler method revoke.
@Path("/privileges/revoke")
@POST
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void revoke(FullHttpRequest httpRequest, HttpResponder httpResponder) throws Exception {
ensureSecurityEnabled();
RevokeRequest request = parseBody(httpRequest, RevokeRequest.class);
if (request == null) {
throw new BadRequestException("Missing request body");
}
if (request.getPrincipal() == null && request.getActions() == null) {
privilegesManager.revoke(request.getAuthorizable());
} else {
Set<Action> actions = request.getActions() == null ? EnumSet.allOf(Action.class) : request.getActions();
privilegesManager.revoke(request.getAuthorizable(), request.getPrincipal(), actions);
}
httpResponder.sendStatus(HttpResponseStatus.OK);
createLogEntry(httpRequest, HttpResponseStatus.OK);
}
use of co.cask.cdap.common.security.AuditPolicy 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 Exception {
ensureSecurityEnabled();
GrantRequest request = parseBody(httpRequest, GrantRequest.class);
if (request == null) {
throw new BadRequestException("Missing request body");
}
Set<Action> actions = request.getActions() == null ? EnumSet.allOf(Action.class) : request.getActions();
privilegesManager.grant(request.getAuthorizable(), request.getPrincipal(), actions);
httpResponder.sendStatus(HttpResponseStatus.OK);
createLogEntry(httpRequest, HttpResponseStatus.OK);
}
Aggregations