@Test public void hasPermission_fromUserMemberships() { DefaultUser user = new DefaultUser("user"); user.setId(USER_ID); Membership membership = new Membership(); membership.setMemberType(MemberType.USER); membership.setMemberId(USER_ID); membership.setReferenceType(ReferenceType.ORGANIZATION); membership.setReferenceId(ORGANIZATION_ID); membership.setRoleId(ROLE_ID); Role role = new Role(); role.setId(ROLE_ID); role.setAssignableType(ReferenceType.ORGANIZATION); role.setPermissionAcls(Permission.of(ORGANIZATION, READ)); when(groupService.findByMember(user.getId())).thenReturn(Single.just(emptyList())); when(membershipService.findByCriteria(eq(ReferenceType.ORGANIZATION), eq(ORGANIZATION_ID), argThat(criteria -> criteria.getUserId().get().equals(user.getId()) && !criteria.getGroupIds().isPresent() && criteria.isLogicalOR()))).thenReturn(Flowable.just(membership)); when(roleService.findByIdIn(Arrays.asList(membership.getRoleId()))).thenReturn(Single.just(Collections.singleton(role))); TestObserver<Boolean> obs = cut.hasPermission(user, of(ReferenceType.ORGANIZATION, ORGANIZATION_ID, Permission.ORGANIZATION, READ)) .test(); obs.awaitTerminalEvent(); obs.assertComplete(); obs.assertValue(true); }
public Single<Boolean> hasPermission(User user, PermissionAcls permissions) { return findMembershipPermissions(user, permissions.referenceStream()) .map(permissions::match); }
PermissionService { public Single<Boolean> hasPermission(User user, PermissionAcls permissions) { return findMembershipPermissions(user, permissions.referenceStream()) .map(permissions::match); } }
PermissionService { public Single<Boolean> hasPermission(User user, PermissionAcls permissions) { return findMembershipPermissions(user, permissions.referenceStream()) .map(permissions::match); } PermissionService(MembershipService membershipService,
                             GroupService groupService,
                             RoleService roleService); }
PermissionService { public Single<Boolean> hasPermission(User user, PermissionAcls permissions) { return findMembershipPermissions(user, permissions.referenceStream()) .map(permissions::match); } PermissionService(MembershipService membershipService,
                             GroupService groupService,
                             RoleService roleService); Single<Map<Permission, Set<Acl>>> findAllPermissions(User user, ReferenceType referenceType, String referenceId); Single<Boolean> hasPermission(User user, PermissionAcls permissions); }
PermissionService { public Single<Boolean> hasPermission(User user, PermissionAcls permissions) { return findMembershipPermissions(user, permissions.referenceStream()) .map(permissions::match); } PermissionService(MembershipService membershipService,
                             GroupService groupService,
                             RoleService roleService); Single<Map<Permission, Set<Acl>>> findAllPermissions(User user, ReferenceType referenceType, String referenceId); Single<Boolean> hasPermission(User user, PermissionAcls permissions);  }