Skip to content

Commit

Permalink
Bugfix for role permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 12, 2023
1 parent 0ba6090 commit 94dbc7f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/access/api/RoleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public ResponseEntity<List<Role>> rolesByApplication(@Parameter(hidden = true) U
public ResponseEntity<Role> role(@PathVariable("id") Long id, User user) {
LOG.debug("/role");
Role role = roleRepository.findById(id).orElseThrow(NotFoundException::new);
UserPermissions.assertRoleAccess(user, role, Authority.INVITER);

Map<String, Object> provider = manage.providerById(role.getManageType(), role.getManageId());
role.setApplication(provider);
UserPermissions.assertRoleAccess(user, role, Authority.INVITER);
return ResponseEntity.ok(role);
}

Expand Down
5 changes: 3 additions & 2 deletions server/src/main/java/access/security/UserPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public static void assertRoleAccess(User user, Role accessRole, Authority author
return;
}
user.getUserRoles().stream()
.filter(userRole -> userRole.getRole().getId().equals(accessRole.getId()) ||
.filter(userRole -> (userRole.getRole().getId().equals(accessRole.getId()) &&
userRole.getAuthority().hasEqualOrHigherRights(authority)) ||
(userRole.getRole().getManageId().equals(accessRole.getManageId()) &&
userRole.getAuthority().hasEqualOrHigherRights(authority)))
userRole.getAuthority().hasEqualOrHigherRights(Authority.MANAGER)))
.findFirst()
.orElseThrow(UserRestrictionException::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void assertRoleAccessInstitutionAdmin() {
void assertRoleAccess() {
String identifier = UUID.randomUUID().toString();
User user = userWithRole(Authority.GUEST, identifier);
UserPermissions.assertRoleAccess(user, user.getUserRoles().iterator().next().getRole());
assertThrows(UserRestrictionException.class, () -> UserPermissions.assertRoleAccess(user, user.getUserRoles().iterator().next().getRole()));
}

@Test
Expand Down

0 comments on commit 94dbc7f

Please sign in to comment.