Search in sources :

Example 11 with AccessPolicy

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();
}
Also used : RequestAction(org.apache.nifi.registry.security.authorization.RequestAction) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) AccessPolicy(org.apache.nifi.registry.authorization.AccessPolicy) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

AccessPolicy (org.apache.nifi.registry.authorization.AccessPolicy)11 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 Produces (javax.ws.rs.Produces)5 Path (javax.ws.rs.Path)4 ResourceNotFoundException (org.apache.nifi.registry.exception.ResourceNotFoundException)3 GET (javax.ws.rs.GET)2 Response (javax.ws.rs.core.Response)2 AccessPolicySummary (org.apache.nifi.registry.authorization.AccessPolicySummary)2 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 CurrentUser (org.apache.nifi.registry.authorization.CurrentUser)1 Permissions (org.apache.nifi.registry.authorization.Permissions)1 Tenant (org.apache.nifi.registry.authorization.Tenant)1 Bucket (org.apache.nifi.registry.bucket.Bucket)1 ConfigurableAccessPolicyProvider (org.apache.nifi.registry.security.authorization.ConfigurableAccessPolicyProvider)1 RequestAction (org.apache.nifi.registry.security.authorization.RequestAction)1