Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoints to read, create, update and delete entity permissions #54

Merged
merged 32 commits into from
Aug 18, 2022

Conversation

dnlkoch
Copy link
Member

@dnlkoch dnlkoch commented Jun 30, 2020

This initializes the BasePermissionController which adds all relevant CRUD endpoints to manage all kind permissions (UserInstancePermission, UserClassPermission, GroupInstancePermission, GroupClassPermission) on entity level:

READ

  • @GetMapping("/{id}/permissions/class/group/{groupId}")
    • Returns the GroupClassPermission for the given Group and entity.
  • @GetMapping("/{id}/permissions/class/user/{userId}")
    • Returns the UserClassPermission for the given User and entity.
  • @GetMapping("/{id}/permissions/instance/group/{groupId}")
    • Returns the GroupInstancePermission for the given Group and entity.
  • @GetMapping("/{id}/permissions/instance/user/{userId}")
    • Returns the UserInstancePermission for the given User and entity.
  • @GetMapping("/{id}/permissions/class/group")
    • Returns all GroupClassPermission for the given entity.
  • @GetMapping("/{id}/permissions/class/user")
    • Returns all UserClassPermission for the given entity.
  • @GetMapping("/{id}/permissions/instance/group")
    • Returns all GroupInstancePermission for the given entity.
  • @GetMapping("/{id}/permissions/instance/user")
    • Returns all UserInstancePermission for the given entity.

CREATE/UPDATE

  • @PostMapping("/{id}/permissions/class/group/{groupId}")
    • Creates/Updates the GroupClassPermission for the given Group and entity (via the provided PermissionType in the request body).
  • @PostMapping("/{id}/permissions/class/user/{userId}")
    • Creates/Updates the UserClassPermission for the given Group and entity (via the provided PermissionType in the request body).
  • @PostMapping("/{id}/permissions/instance/group/{groupId}")
    • Creates/Updates the GroupInstancePermission for the given Group and entity (via the provided PermissionType in the request body).
  • @PostMapping("/{id}/permissions/instance/user/{userId}")
    • Creates/Updates the UserInstancePermission for the given Group and entity (via the provided PermissionType in the request body).

DELETE

  • @DeleteMapping("/{id}/permissions/class/group/{groupId}")
    • Deletes the GroupClassPermission for the given Group and entity.
  • @DeleteMapping("/{id}/permissions/class/user/{userId}")
    • Deletes the UserClassPermission for the given User and entity.
  • @DeleteMapping("/{id}/permissions/instance/group/{groupId}")
    • Deletes the GroupInstancePermission for the given Group and entity.
  • @DeleteMapping("/{id}/permissions/instance/user/{userId}")
    • Deletes the UserInstancePermission for the given User and entity.
  • @DeleteMapping("/{id}/permissions/class/group")
    • Deletes all GroupClassPermission for the given entity.
  • @DeleteMapping("/{id}/permissions/class/user")
    • Deletes all GroupClassPermission for the given entity.
  • @DeleteMapping("/{id}/permissions/instance/group")
    • Deletes all GroupInstancePermission for the given entity.
  • @DeleteMapping("/{id}/permissions/instance/user")
    • Deletes all UserInstancePermission for the given entity.

Breaking change:

The permissions field of the BasePermission has been renamed to permission.

Please review @terrestris/devs.

Copy link
Member

@hwbllmnn hwbllmnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in principle, just a question wrt. migrations and some suggestions about exception handling

@dnlkoch dnlkoch force-pushed the add-permission-controller branch from f941cca to 1ba671a Compare October 8, 2020 14:14
@dnlkoch dnlkoch force-pushed the add-permission-controller branch from 1ba671a to dc237af Compare January 29, 2021 17:45
@dnlkoch dnlkoch changed the title Add endpoints to read, create, update and delete entity permissions Draft: Add endpoints to read, create, update and delete entity permissions Feb 1, 2021
@dnlkoch dnlkoch force-pushed the add-permission-controller branch from dc237af to 0b32973 Compare February 26, 2021 13:45
@dnlkoch dnlkoch changed the title Draft: Add endpoints to read, create, update and delete entity permissions Add endpoints to read, create, update and delete entity permissions Jul 27, 2021
@dnlkoch dnlkoch marked this pull request as draft July 27, 2021 09:17
@LukasLohoff LukasLohoff force-pushed the add-permission-controller branch from bbcf211 to e81f37a Compare July 29, 2022 13:12
@LukasLohoff
Copy link
Member

LukasLohoff commented Jul 29, 2022

todo list:

  • fix tests for switch to repositories (DefaultPermissionEvaluatorTest)
  • for permission check setPermission(List<? extends BaseEntity> persistedEntityList, User user, PermissionCollectionType permissionCollectionType): call setPermission for each entity in persistedEntityList
  • for List<User> findOwner(BaseEntity entity): filter list of users (postfilter?)
  • resolve inconsistencies with read permissions on users
    • currently, users need read permission on other users to grant them permissions
    • possible solution: separate controller /service which grants access to users or user lists, but only exposes basic information
  • fix pipeline

* remove unused basePermissionService methods
* add todos for permission checks
* reorganize imports
@LukasLohoff
Copy link
Member

LukasLohoff commented Aug 3, 2022

Now all (Group/Class)PermissionServices are annotated with security checks.

One issue remains: Right now, we can't test permissions for permission objects. This is needed for example for the following method:

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#group, 'READ')")
    @PostFilter("hasRole('ROLE_ADMIN') or hasPermission(filterObject, 'READ')")
    // todo: in postfilter permission check: how to get either targetDomainType or entity from permission.entityId?
    public List<GroupClassPermission> findFor(Group group) {
        return super.findFor(group);
    }

I added a PostFilter check here to test if the user has permission on all entities of the returned GroupClassPermissions. However, this will only work if we find a way to get either the class name or the entity itself from the permission entity.

All methods which work like this are unused until now. So it might be enough for now to restrict them to users with role ADMIN only.

@LukasLohoff LukasLohoff force-pushed the add-permission-controller branch from 7d779ee to 7b72a28 Compare August 3, 2022 08:29
@LukasLohoff LukasLohoff marked this pull request as ready for review August 4, 2022 11:03
@LukasLohoff
Copy link
Member

New changes since last review: https://github.com/terrestris/shogun/compare/8c3d20a..7b72a28ff7c2a3e7b2e17013d497d0ff9f66e22e

@terrestris/devs Please review

Copy link

@Unraveler Unraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some spaces on the Doc-strings seem to be off. I would suggest changes on them all, but there are too many. Anyway, it is just a minor issue. Otherwise It looks good to me

@dnlkoch dnlkoch merged commit 647c378 into terrestris:main Aug 18, 2022
@dnlkoch dnlkoch deleted the add-permission-controller branch August 18, 2022 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants