@Test public void hasPermission_aclsFromDifferentGroupAndUser() { DefaultUser user = new DefaultUser("user"); user.setId(USER_ID); Membership organizationMembership = new Membership(); organizationMembership.setMemberType(MemberType.USER); organizationMembership.setMemberId(USER_ID); organizationMembership.setReferenceType(ReferenceType.ORGANIZATION); organizationMembership.setReferenceId(ORGANIZATION_ID); organizationMembership.setRoleId(ROLE_ID); Membership groupMembership = new Membership(); groupMembership.setMemberType(MemberType.GROUP); groupMembership.setMemberId(GROUP_ID); groupMembership.setReferenceType(ReferenceType.ORGANIZATION); groupMembership.setReferenceId(ORGANIZATION_ID); groupMembership.setRoleId(ROLE_ID2); Role organizationRole = new Role(); organizationRole.setId(ROLE_ID); organizationRole.setAssignableType(ReferenceType.ORGANIZATION); organizationRole.setPermissionAcls(Permission.of(ORGANIZATION, READ)); Role groupRole = new Role(); groupRole.setId(ROLE_ID2); groupRole.setAssignableType(ReferenceType.ORGANIZATION); groupRole.setPermissionAcls(Permission.of(ORGANIZATION, CREATE)); Group group = new Group(); group.setId(GROUP_ID); group.setReferenceType(ReferenceType.ORGANIZATION); group.setReferenceId(ORGANIZATION_ID); group.setMembers(Arrays.asList(user.getId())); when(groupService.findByMember(user.getId())).thenReturn(Single.just(Arrays.asList(group))); when(membershipService.findByCriteria(eq(ReferenceType.ORGANIZATION), eq(ORGANIZATION_ID), any(MembershipCriteria.class))).thenReturn(Flowable.just(organizationMembership, groupMembership)); when(roleService.findByIdIn(Arrays.asList(organizationMembership.getRoleId(), groupMembership.getRoleId()))).thenReturn(Single.just(new HashSet<>(Arrays.asList(organizationRole, groupRole)))); TestObserver<Boolean> obs = cut.hasPermission(user, of(ReferenceType.ORGANIZATION, ORGANIZATION_ID, Permission.ORGANIZATION, READ, CREATE)).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);  }