@Test void testGetPermissionsForType() throws Exception { mockMvc .perform(get(BASE_URI + "/" + TYPES + "/permissions/typeId?q=user==test")) .andExpect(status().isOk()); verify(permissionsService).getSuitablePermissionsForType("typeId"); }
@GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) public PagedApiResponse getPermissionsForType( @PathVariable(value = TYPE_ID) String typeId, @RequestParam(value = "q", required = false) String queryString, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "inheritance", defaultValue = "false", required = false) boolean inheritance) { validateQueryParams(page, pageSize, inheritance); Set<Sid> sids = getSidsFromQuery(queryString); PagedApiResponse response; TypePermissionsResponse permissionsResponse; Map<String, Set<LabelledPermission>> typePermission; if (page != null) { typePermission = permissionService.getPermissionsForType(typeId, sids, page, pageSize); permissionsResponse = convertToTypeResponse(typeId, typePermission); Integer totalItems = objectIdentityService.getNrOfObjectIdentities(typeId, sids); response = getPermissionResponse(queryString, page, pageSize, totalItems, permissionsResponse); } else { typePermission = permissionService.getPermissionsForType(typeId, sids, inheritance); permissionsResponse = convertToTypeResponse(typeId, typePermission); response = getPermissionResponse(queryString, permissionsResponse); } return response; }
PermissionsController extends ApiController { @GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) public PagedApiResponse getPermissionsForType( @PathVariable(value = TYPE_ID) String typeId, @RequestParam(value = "q", required = false) String queryString, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "inheritance", defaultValue = "false", required = false) boolean inheritance) { validateQueryParams(page, pageSize, inheritance); Set<Sid> sids = getSidsFromQuery(queryString); PagedApiResponse response; TypePermissionsResponse permissionsResponse; Map<String, Set<LabelledPermission>> typePermission; if (page != null) { typePermission = permissionService.getPermissionsForType(typeId, sids, page, pageSize); permissionsResponse = convertToTypeResponse(typeId, typePermission); Integer totalItems = objectIdentityService.getNrOfObjectIdentities(typeId, sids); response = getPermissionResponse(queryString, page, pageSize, totalItems, permissionsResponse); } else { typePermission = permissionService.getPermissionsForType(typeId, sids, inheritance); permissionsResponse = convertToTypeResponse(typeId, typePermission); response = getPermissionResponse(queryString, permissionsResponse); } return response; } }
PermissionsController extends ApiController { @GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) public PagedApiResponse getPermissionsForType( @PathVariable(value = TYPE_ID) String typeId, @RequestParam(value = "q", required = false) String queryString, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "inheritance", defaultValue = "false", required = false) boolean inheritance) { validateQueryParams(page, pageSize, inheritance); Set<Sid> sids = getSidsFromQuery(queryString); PagedApiResponse response; TypePermissionsResponse permissionsResponse; Map<String, Set<LabelledPermission>> typePermission; if (page != null) { typePermission = permissionService.getPermissionsForType(typeId, sids, page, pageSize); permissionsResponse = convertToTypeResponse(typeId, typePermission); Integer totalItems = objectIdentityService.getNrOfObjectIdentities(typeId, sids); response = getPermissionResponse(queryString, page, pageSize, totalItems, permissionsResponse); } else { typePermission = permissionService.getPermissionsForType(typeId, sids, inheritance); permissionsResponse = convertToTypeResponse(typeId, typePermission); response = getPermissionResponse(queryString, permissionsResponse); } return response; } PermissionsController(
      PermissionService permissionService,
      RSQLParser rsqlParser,
      ObjectIdentityService objectIdentityService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper); }
PermissionsController extends ApiController { @GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) public PagedApiResponse getPermissionsForType( @PathVariable(value = TYPE_ID) String typeId, @RequestParam(value = "q", required = false) String queryString, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "inheritance", defaultValue = "false", required = false) boolean inheritance) { validateQueryParams(page, pageSize, inheritance); Set<Sid> sids = getSidsFromQuery(queryString); PagedApiResponse response; TypePermissionsResponse permissionsResponse; Map<String, Set<LabelledPermission>> typePermission; if (page != null) { typePermission = permissionService.getPermissionsForType(typeId, sids, page, pageSize); permissionsResponse = convertToTypeResponse(typeId, typePermission); Integer totalItems = objectIdentityService.getNrOfObjectIdentities(typeId, sids); response = getPermissionResponse(queryString, page, pageSize, totalItems, permissionsResponse); } else { typePermission = permissionService.getPermissionsForType(typeId, sids, inheritance); permissionsResponse = convertToTypeResponse(typeId, typePermission); response = getPermissionResponse(queryString, permissionsResponse); } return response; } PermissionsController(
      PermissionService permissionService,
      RSQLParser rsqlParser,
      ObjectIdentityService objectIdentityService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper); @PostMapping(value = TYPES + "/{" + TYPE_ID + "}") @ApiOperation( value = "Create a type this enables row level secure an entity", code = 201, response = ResponseEntity.class) ResponseEntity enableRLS(
      HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId); @DeleteMapping(value = TYPES + "/{" + TYPE_ID + "}") @ApiOperation( value = "Delete a type this removes row level security from an entity", code = 204, response = ResponseEntity.class) ResponseEntity disableRLS(@PathVariable(value = TYPE_ID) String typeId); @GetMapping(value = TYPES) @ApiOperation(value = "Get a list of ACL types in the system", response = ApiResponse.class) ApiResponse getRlsEntities(); @GetMapping(value = TYPES + "/permissions/{" + TYPE_ID + "}") @ApiOperation( value = "Get a list of permissions that can be used on a type", response = ApiResponse.class) ApiResponse getSuitablePermissions(@PathVariable(value = TYPE_ID) String typeId); @PostMapping(value = OBJECTS + "/{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation(value = "Create a type for a entity", code = 201, response = ResponseEntity.class) ResponseEntity createAcl(
      HttpServletRequest request,
      @PathVariable(TYPE_ID) String typeId,
      @PathVariable(OBJECT_ID) String identifier); @GetMapping(value = OBJECTS + "/{" + TYPE_ID + "}") @ApiOperation( value = "Get a list object's for a type. Typically this is a row in a row level secured entity.", response = PagedApiResponse.class) PagedApiResponse getAcls(
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "pageSize", required = false) Integer pageSize); @GetMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation(value = "Gets permissions on a single object", response = ApiResponse.class) ApiResponse getPermissionsForObject(
      @PathVariable(TYPE_ID) String typeId,
      @PathVariable(OBJECT_ID) String identifier,
      @RequestParam(value = "q", required = false) String queryString,
      @RequestParam(value = "inheritance", defaultValue = "false", required = false)
          boolean inheritance); @GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) PagedApiResponse getPermissionsForType(
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestParam(value = "q", required = false) String queryString,
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "pageSize", required = false) Integer pageSize,
      @RequestParam(value = "inheritance", defaultValue = "false", required = false)
          boolean inheritance); @GetMapping() @ApiOperation( value = "Gets all permissions for one or more users or roles", response = ApiResponse.class) ApiResponse getPermissionsForUser(
      @RequestParam(value = "q", required = false) String queryString,
      @RequestParam(value = "inheritance", defaultValue = "false", required = false)
          boolean inheritance); @PatchMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation( value = "Update a permission on a single object for one or more users or roles", code = 204, response = ResponseEntity.class) ResponseEntity setPermission(
      @PathVariable(value = TYPE_ID) String typeId,
      @PathVariable(value = OBJECT_ID) String identifier,
      @RequestBody SetObjectPermissionRequest request); @PatchMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Update a list of permissions on objects of a certain type", code = 204, response = ResponseEntity.class) ResponseEntity setTypePermissions(
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestBody SetTypePermissionsRequest request); @PostMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Create a list of permissions on an type for a single user or role", code = 201, response = ResponseEntity.class) ResponseEntity<Object> createPermissions(
      HttpServletRequest request,
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestBody SetTypePermissionsRequest setTypePermissionsRequest); @PostMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation( value = "Create a permission on an object for a single user or role", code = 201, response = ResponseEntity.class) ResponseEntity<Object> createPermission(
      HttpServletRequest request,
      @PathVariable(value = TYPE_ID) String typeId,
      @PathVariable(value = OBJECT_ID) String identifier,
      @RequestBody SetObjectPermissionRequest setIdentityPermissionRequest); @DeleteMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation( value = "Delete a permission on an object for a single user or role", code = 204, response = ResponseEntity.class) ResponseEntity deletePermission(
      @PathVariable(value = TYPE_ID) String typeId,
      @PathVariable(value = OBJECT_ID) String identifier,
      @RequestBody DeletePermissionRequest request); }
PermissionsController extends ApiController { @GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) public PagedApiResponse getPermissionsForType( @PathVariable(value = TYPE_ID) String typeId, @RequestParam(value = "q", required = false) String queryString, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "inheritance", defaultValue = "false", required = false) boolean inheritance) { validateQueryParams(page, pageSize, inheritance); Set<Sid> sids = getSidsFromQuery(queryString); PagedApiResponse response; TypePermissionsResponse permissionsResponse; Map<String, Set<LabelledPermission>> typePermission; if (page != null) { typePermission = permissionService.getPermissionsForType(typeId, sids, page, pageSize); permissionsResponse = convertToTypeResponse(typeId, typePermission); Integer totalItems = objectIdentityService.getNrOfObjectIdentities(typeId, sids); response = getPermissionResponse(queryString, page, pageSize, totalItems, permissionsResponse); } else { typePermission = permissionService.getPermissionsForType(typeId, sids, inheritance); permissionsResponse = convertToTypeResponse(typeId, typePermission); response = getPermissionResponse(queryString, permissionsResponse); } return response; } PermissionsController(
      PermissionService permissionService,
      RSQLParser rsqlParser,
      ObjectIdentityService objectIdentityService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper); @PostMapping(value = TYPES + "/{" + TYPE_ID + "}") @ApiOperation( value = "Create a type this enables row level secure an entity", code = 201, response = ResponseEntity.class) ResponseEntity enableRLS(
      HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId); @DeleteMapping(value = TYPES + "/{" + TYPE_ID + "}") @ApiOperation( value = "Delete a type this removes row level security from an entity", code = 204, response = ResponseEntity.class) ResponseEntity disableRLS(@PathVariable(value = TYPE_ID) String typeId); @GetMapping(value = TYPES) @ApiOperation(value = "Get a list of ACL types in the system", response = ApiResponse.class) ApiResponse getRlsEntities(); @GetMapping(value = TYPES + "/permissions/{" + TYPE_ID + "}") @ApiOperation( value = "Get a list of permissions that can be used on a type", response = ApiResponse.class) ApiResponse getSuitablePermissions(@PathVariable(value = TYPE_ID) String typeId); @PostMapping(value = OBJECTS + "/{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation(value = "Create a type for a entity", code = 201, response = ResponseEntity.class) ResponseEntity createAcl(
      HttpServletRequest request,
      @PathVariable(TYPE_ID) String typeId,
      @PathVariable(OBJECT_ID) String identifier); @GetMapping(value = OBJECTS + "/{" + TYPE_ID + "}") @ApiOperation( value = "Get a list object's for a type. Typically this is a row in a row level secured entity.", response = PagedApiResponse.class) PagedApiResponse getAcls(
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "pageSize", required = false) Integer pageSize); @GetMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation(value = "Gets permissions on a single object", response = ApiResponse.class) ApiResponse getPermissionsForObject(
      @PathVariable(TYPE_ID) String typeId,
      @PathVariable(OBJECT_ID) String identifier,
      @RequestParam(value = "q", required = false) String queryString,
      @RequestParam(value = "inheritance", defaultValue = "false", required = false)
          boolean inheritance); @GetMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Gets all permissions for all objects of a certain type", response = PagedApiResponse.class) PagedApiResponse getPermissionsForType(
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestParam(value = "q", required = false) String queryString,
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "pageSize", required = false) Integer pageSize,
      @RequestParam(value = "inheritance", defaultValue = "false", required = false)
          boolean inheritance); @GetMapping() @ApiOperation( value = "Gets all permissions for one or more users or roles", response = ApiResponse.class) ApiResponse getPermissionsForUser(
      @RequestParam(value = "q", required = false) String queryString,
      @RequestParam(value = "inheritance", defaultValue = "false", required = false)
          boolean inheritance); @PatchMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation( value = "Update a permission on a single object for one or more users or roles", code = 204, response = ResponseEntity.class) ResponseEntity setPermission(
      @PathVariable(value = TYPE_ID) String typeId,
      @PathVariable(value = OBJECT_ID) String identifier,
      @RequestBody SetObjectPermissionRequest request); @PatchMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Update a list of permissions on objects of a certain type", code = 204, response = ResponseEntity.class) ResponseEntity setTypePermissions(
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestBody SetTypePermissionsRequest request); @PostMapping(value = "{" + TYPE_ID + "}") @ApiOperation( value = "Create a list of permissions on an type for a single user or role", code = 201, response = ResponseEntity.class) ResponseEntity<Object> createPermissions(
      HttpServletRequest request,
      @PathVariable(value = TYPE_ID) String typeId,
      @RequestBody SetTypePermissionsRequest setTypePermissionsRequest); @PostMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation( value = "Create a permission on an object for a single user or role", code = 201, response = ResponseEntity.class) ResponseEntity<Object> createPermission(
      HttpServletRequest request,
      @PathVariable(value = TYPE_ID) String typeId,
      @PathVariable(value = OBJECT_ID) String identifier,
      @RequestBody SetObjectPermissionRequest setIdentityPermissionRequest); @DeleteMapping(value = "{" + TYPE_ID + "}/{" + OBJECT_ID + "}") @ApiOperation( value = "Delete a permission on an object for a single user or role", code = 204, response = ResponseEntity.class) ResponseEntity deletePermission(
      @PathVariable(value = TYPE_ID) String typeId,
      @PathVariable(value = OBJECT_ID) String identifier,
      @RequestBody DeletePermissionRequest request); static final String BASE_URI; static final String TYPES; static final String OBJECTS; }