@Test void testUpdateEntityClassRlsEnableRls() { String entityTypeId = "entityTypeId"; EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock(); Attribute idAttribute = when(mock(Attribute.class).getDataType()).thenReturn(LONG).getMock(); when(entityType.getIdAttribute()).thenReturn(idAttribute); when(dataService.getEntityType(entityTypeId)).thenReturn(entityType); Entity entity = when(mock(Entity.class).getEntityType()).thenReturn(entityType).getMock(); when(entity.getIdValue()).thenReturn("entityId"); when(dataService.findAll(entityTypeId)).thenReturn(Stream.of(entity)); EntityTypeRlsRequest entityTypeRlsRequest = new EntityTypeRlsRequest(entityTypeId, true); permissionManagerController.updateEntityClassRls(entityTypeRlsRequest); verify(mutableAclClassService).createAclClass("entity-entityTypeId", Long.class); verify(mutableAclService).createAcl(new EntityIdentity(entity)); }
@PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) public void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest) { String entityTypeId = entityTypeRlsRequest.getId(); if (systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)) { throw new IllegalArgumentException("Updating system entity type not allowed"); } EntityType entityType = dataService.getEntityType(entityTypeId); String aclClassType = EntityIdentityUtils.toType(entityType); boolean hasAclClass = mutableAclClassService.hasAclClass(aclClassType); if (entityTypeRlsRequest.isRlsEnabled()) { if (!hasAclClass) { mutableAclClassService.createAclClass( aclClassType, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach(entity -> mutableAclService.createAcl(new EntityIdentity(entity))); } } else { if (hasAclClass) { mutableAclClassService.deleteAclClass(aclClassType); } } }
PermissionManagerController extends PluginController { @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) public void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest) { String entityTypeId = entityTypeRlsRequest.getId(); if (systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)) { throw new IllegalArgumentException("Updating system entity type not allowed"); } EntityType entityType = dataService.getEntityType(entityTypeId); String aclClassType = EntityIdentityUtils.toType(entityType); boolean hasAclClass = mutableAclClassService.hasAclClass(aclClassType); if (entityTypeRlsRequest.isRlsEnabled()) { if (!hasAclClass) { mutableAclClassService.createAclClass( aclClassType, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach(entity -> mutableAclService.createAcl(new EntityIdentity(entity))); } } else { if (hasAclClass) { mutableAclClassService.deleteAclClass(aclClassType); } } } }
PermissionManagerController extends PluginController { @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) public void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest) { String entityTypeId = entityTypeRlsRequest.getId(); if (systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)) { throw new IllegalArgumentException("Updating system entity type not allowed"); } EntityType entityType = dataService.getEntityType(entityTypeId); String aclClassType = EntityIdentityUtils.toType(entityType); boolean hasAclClass = mutableAclClassService.hasAclClass(aclClassType); if (entityTypeRlsRequest.isRlsEnabled()) { if (!hasAclClass) { mutableAclClassService.createAclClass( aclClassType, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach(entity -> mutableAclService.createAcl(new EntityIdentity(entity))); } } else { if (hasAclClass) { mutableAclClassService.deleteAclClass(aclClassType); } } } PermissionManagerController(
      DataService dataService,
      MutableAclService mutableAclService,
      MutableAclClassService mutableAclClassService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      PermissionRegistry permissionRegistry); }
PermissionManagerController extends PluginController { @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) public void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest) { String entityTypeId = entityTypeRlsRequest.getId(); if (systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)) { throw new IllegalArgumentException("Updating system entity type not allowed"); } EntityType entityType = dataService.getEntityType(entityTypeId); String aclClassType = EntityIdentityUtils.toType(entityType); boolean hasAclClass = mutableAclClassService.hasAclClass(aclClassType); if (entityTypeRlsRequest.isRlsEnabled()) { if (!hasAclClass) { mutableAclClassService.createAclClass( aclClassType, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach(entity -> mutableAclService.createAcl(new EntityIdentity(entity))); } } else { if (hasAclClass) { mutableAclClassService.deleteAclClass(aclClassType); } } } PermissionManagerController(
      DataService dataService,
      MutableAclService mutableAclService,
      MutableAclClassService mutableAclClassService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      PermissionRegistry permissionRegistry); @GetMapping String init(Model model); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/entityclass/role/{rolename}") @ResponseBody Permissions getRoleEntityClassPermissions(@PathVariable String rolename); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/plugin/user/{username}") @ResponseBody Permissions getUserPluginPermissions(@PathVariable String username); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/package/user/{username}") @ResponseBody Permissions getUserPackagePermissions(@PathVariable String username); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/package/role/{rolename}") @ResponseBody Permissions getRolePackagePermissions(@PathVariable String rolename); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/entityclass/user/{username}") @ResponseBody Permissions getUserEntityClassPermissions(@PathVariable String username); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/plugin/role") @ResponseStatus(HttpStatus.OK) void updateRolePluginPermissions(@RequestParam String rolename, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/role") @ResponseStatus(HttpStatus.OK) void updateRoleEntityClassPermissions(
      @RequestParam String rolename, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/package/role") @ResponseStatus(HttpStatus.OK) void updateRolePackagePermissions(@RequestParam String rolename, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/package/user") @ResponseStatus(HttpStatus.OK) void updateUserPackagePermissions(@RequestParam String username, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/plugin/user") @ResponseStatus(HttpStatus.OK) void updateUserPluginPermissions(@RequestParam String username, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/plugin/role/{rolename}") @ResponseBody Permissions getRolePluginPermissions(@PathVariable String rolename); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/user") @ResponseStatus(HttpStatus.OK) void updateUserEntityClassPermissions(
      @RequestParam String username, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest); @ApiOperation( value = "Get all permission sets", response = PermissionSetResponse.class, responseContainer = "List") @GetMapping("/permissionSets") @ResponseBody List<PermissionSetResponse> getPermissionSets(); @ExceptionHandler(RuntimeException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) Map<String, String> handleRuntimeException(RuntimeException e); }
PermissionManagerController extends PluginController { @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) public void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest) { String entityTypeId = entityTypeRlsRequest.getId(); if (systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)) { throw new IllegalArgumentException("Updating system entity type not allowed"); } EntityType entityType = dataService.getEntityType(entityTypeId); String aclClassType = EntityIdentityUtils.toType(entityType); boolean hasAclClass = mutableAclClassService.hasAclClass(aclClassType); if (entityTypeRlsRequest.isRlsEnabled()) { if (!hasAclClass) { mutableAclClassService.createAclClass( aclClassType, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach(entity -> mutableAclService.createAcl(new EntityIdentity(entity))); } } else { if (hasAclClass) { mutableAclClassService.deleteAclClass(aclClassType); } } } PermissionManagerController(
      DataService dataService,
      MutableAclService mutableAclService,
      MutableAclClassService mutableAclClassService,
      SystemEntityTypeRegistry systemEntityTypeRegistry,
      PermissionRegistry permissionRegistry); @GetMapping String init(Model model); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/entityclass/role/{rolename}") @ResponseBody Permissions getRoleEntityClassPermissions(@PathVariable String rolename); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/plugin/user/{username}") @ResponseBody Permissions getUserPluginPermissions(@PathVariable String username); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/package/user/{username}") @ResponseBody Permissions getUserPackagePermissions(@PathVariable String username); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/package/role/{rolename}") @ResponseBody Permissions getRolePackagePermissions(@PathVariable String rolename); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/entityclass/user/{username}") @ResponseBody Permissions getUserEntityClassPermissions(@PathVariable String username); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/plugin/role") @ResponseStatus(HttpStatus.OK) void updateRolePluginPermissions(@RequestParam String rolename, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/role") @ResponseStatus(HttpStatus.OK) void updateRoleEntityClassPermissions(
      @RequestParam String rolename, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/package/role") @ResponseStatus(HttpStatus.OK) void updateRolePackagePermissions(@RequestParam String rolename, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/package/user") @ResponseStatus(HttpStatus.OK) void updateUserPackagePermissions(@RequestParam String username, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/plugin/user") @ResponseStatus(HttpStatus.OK) void updateUserPluginPermissions(@RequestParam String username, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional(readOnly = true) @GetMapping("/plugin/role/{rolename}") @ResponseBody Permissions getRolePluginPermissions(@PathVariable String rolename); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/user") @ResponseStatus(HttpStatus.OK) void updateUserEntityClassPermissions(
      @RequestParam String username, WebRequest webRequest); @PreAuthorize("hasAnyRole('ROLE_SU')") @Transactional @PostMapping("/update/entityclass/rls") @ResponseStatus(HttpStatus.OK) void updateEntityClassRls(@Valid @RequestBody EntityTypeRlsRequest entityTypeRlsRequest); @ApiOperation( value = "Get all permission sets", response = PermissionSetResponse.class, responseContainer = "List") @GetMapping("/permissionSets") @ResponseBody List<PermissionSetResponse> getPermissionSets(); @ExceptionHandler(RuntimeException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) Map<String, String> handleRuntimeException(RuntimeException e); static final String URI; static final String RADIO; }