use of org.apache.nifi.registry.authorization.AccessPolicy in project nifi-registry by apache.
the class AccessPolicyResource method getAccessPolicyForResource.
/**
* Retrieve a specified access policy for a given (action, resource) pair.
*
* @param action the action, i.e. "read", "write"
* @param rawResource the name of the resource as a raw string
* @return An access policy.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{action}/{resource: .+}")
@ApiOperation(value = "Gets an access policy for the specified action and resource", response = AccessPolicy.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "read"), @ExtensionProperty(name = "resource", value = "/policies") }) })
@ApiResponses({ @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400), @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getAccessPolicyForResource(@ApiParam(value = "The request action.", allowableValues = "read, write, delete", required = true) @PathParam("action") final String action, @ApiParam(value = "The resource of the policy.", required = true) @PathParam("resource") final String rawResource) {
verifyAuthorizerIsManaged();
authorizeAccess(RequestAction.READ);
// parse the action and resource type
final RequestAction requestAction = RequestAction.valueOfValue(action);
final String resource = "/" + rawResource;
AccessPolicy accessPolicy = authorizationService.getAccessPolicy(resource, requestAction);
if (accessPolicy == null) {
throw new ResourceNotFoundException("No policy found for action='" + action + "', resource='" + resource + "'");
}
return generateOkResponse(accessPolicy).build();
}
Aggregations