@Test void testCreatePermissionsForType() throws Exception { String requestJson = "{" + "objects:[{" + "objectId:rij1," + "permissions:[" + "{" + "role:IT_VIEWER," + "permission:WRITE" + "}," + "{" + "role:IT_MANAGER," + "permission:READ" + "}" + "]}," + "{" + "objectId:rij2," + "permissions:[" + "{" + "role:IT_VIEWER," + "permission:WRITE" + "}" + "]}" + "]" + "}"; ObjectIdentity objectIdentity1 = new ObjectIdentityImpl("typeId", "rij1"); ObjectIdentity objectIdentity2 = new ObjectIdentityImpl("typeId", "rij2"); doReturn(objectIdentity1).when(entityHelper).getObjectIdentity("typeId", "rij1"); doReturn(objectIdentity2).when(entityHelper).getObjectIdentity("typeId", "rij2"); Permission permission1 = Permission.create(objectIdentity1, new GrantedAuthoritySid("ROLE_IT_VIEWER"), WRITE); Permission permission2 = Permission.create(objectIdentity1, new GrantedAuthoritySid("ROLE_IT_MANAGER"), READ); Permission permission3 = Permission.create(objectIdentity2, new GrantedAuthoritySid("ROLE_IT_VIEWER"), WRITE); mockMvc .perform(post(BASE_URI + "/typeId").contentType(APPLICATION_JSON_UTF8).content(requestJson)) .andExpect(status().isCreated()); verify(permissionsService) .createPermissions(Sets.newHashSet(permission3, permission1, permission2)); }
@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) public ResponseEntity<Object> createPermissions( HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId, @RequestBody SetTypePermissionsRequest setTypePermissionsRequest) { Set<Permission> permissions = convertRequests(setTypePermissionsRequest.getObjects(), typeId); permissionService.createPermissions(permissions); return ResponseEntity.created(getUriFromRequest(request)).build(); }
PermissionsController extends ApiController { @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) public ResponseEntity<Object> createPermissions( HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId, @RequestBody SetTypePermissionsRequest setTypePermissionsRequest) { Set<Permission> permissions = convertRequests(setTypePermissionsRequest.getObjects(), typeId); permissionService.createPermissions(permissions); return ResponseEntity.created(getUriFromRequest(request)).build(); } }
PermissionsController extends ApiController { @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) public ResponseEntity<Object> createPermissions( HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId, @RequestBody SetTypePermissionsRequest setTypePermissionsRequest) { Set<Permission> permissions = convertRequests(setTypePermissionsRequest.getObjects(), typeId); permissionService.createPermissions(permissions); return ResponseEntity.created(getUriFromRequest(request)).build(); } PermissionsController(
      PermissionService permissionService,
      RSQLParser rsqlParser,
      ObjectIdentityService objectIdentityService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper); }
PermissionsController extends ApiController { @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) public ResponseEntity<Object> createPermissions( HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId, @RequestBody SetTypePermissionsRequest setTypePermissionsRequest) { Set<Permission> permissions = convertRequests(setTypePermissionsRequest.getObjects(), typeId); permissionService.createPermissions(permissions); return ResponseEntity.created(getUriFromRequest(request)).build(); } 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 { @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) public ResponseEntity<Object> createPermissions( HttpServletRequest request, @PathVariable(value = TYPE_ID) String typeId, @RequestBody SetTypePermissionsRequest setTypePermissionsRequest) { Set<Permission> permissions = convertRequests(setTypePermissionsRequest.getObjects(), typeId); permissionService.createPermissions(permissions); return ResponseEntity.created(getUriFromRequest(request)).build(); } 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; }