@Test void testGetPermission() { PrincipalSid sid1 = mock(PrincipalSid.class); PrincipalSid sid2 = mock(PrincipalSid.class); MutableAcl acl = mock(MutableAcl.class); ObjectIdentity objectIdentity = new ObjectIdentityImpl("entity-typeId", "identifier"); when(acl.getObjectIdentity()).thenReturn(objectIdentity); AccessControlEntry ace1 = mock(AccessControlEntry.class); when(ace1.getSid()).thenReturn(sid1); when(ace1.getPermission()).thenReturn(COUNT); AccessControlEntry ace2 = mock(AccessControlEntry.class); when(ace2.getSid()).thenReturn(sid2); when(ace2.getPermission()).thenReturn(WRITEMETA); when(acl.getEntries()).thenReturn(Arrays.asList(ace1, ace2)); when(acl.getObjectIdentity()).thenReturn(objectIdentity); when(mutableAclService.readAclById(objectIdentity)).thenReturn(acl); LabelledPermission permission1 = LabelledPermission.create( sid2, LabelledObjectIdentity.create( "entity-typeId", "typeId", "typeLabel", "identifier", "identifierLabel"), WRITEMETA, null); LabelledPermission permission2 = LabelledPermission.create( sid1, LabelledObjectIdentity.create( "entity-typeId", "typeId", "typeLabel", "identifier", "identifierLabel"), COUNT, null); Set<LabelledPermission> expected = newHashSet(permission1, permission2); when(entityHelper.getLabelledObjectIdentity(acl.getObjectIdentity())) .thenReturn( LabelledObjectIdentity.create( "entity-typeId", "typeId", "typeLabel", "identifier", "identifierLabel")); LinkedHashSet<Sid> sids = new LinkedHashSet<>(); sids.add(sid1); sids.add(sid2); when(userRoleTools.sortSids(sids)).thenReturn(new LinkedList<>(sids)); when(mutableAclClassService.getAclClassTypes()).thenReturn(singletonList("entity-typeId")); assertEquals( expected, newHashSet( permissionsApiService.getPermissionsForObject( new ObjectIdentityImpl("entity-typeId", "identifier"), sids, true))); }
@Override public Set<LabelledPermission> getPermissionsForObject( ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions) { checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); Acl acl = mutableAclService.readAclById(objectIdentity); return getPermissionResponses(acl, isReturnInheritedPermissions, sids); }
PermissionServiceImpl implements PermissionService { @Override public Set<LabelledPermission> getPermissionsForObject( ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions) { checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); Acl acl = mutableAclService.readAclById(objectIdentity); return getPermissionResponses(acl, isReturnInheritedPermissions, sids); } }
PermissionServiceImpl implements PermissionService { @Override public Set<LabelledPermission> getPermissionsForObject( ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions) { checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); Acl acl = mutableAclService.readAclById(objectIdentity); return getPermissionResponses(acl, isReturnInheritedPermissions, sids); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); }
PermissionServiceImpl implements PermissionService { @Override public Set<LabelledPermission> getPermissionsForObject( ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions) { checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); Acl acl = mutableAclService.readAclById(objectIdentity); return getPermissionResponses(acl, isReturnInheritedPermissions, sids); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override @Transactional void createAcl(ObjectIdentity objectIdentity); @Override @Transactional void createPermission(Permission permission); @Override @Transactional void createPermissions(Set<Permission> permissions); @Override @Transactional void updatePermission(Permission permission); @Override @Transactional void updatePermissions(Set<Permission> permissions); @Override @Transactional void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override @Transactional void addType(String typeId); @Override @Transactional void deleteType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid); }
PermissionServiceImpl implements PermissionService { @Override public Set<LabelledPermission> getPermissionsForObject( ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions) { checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); Acl acl = mutableAclService.readAclById(objectIdentity); return getPermissionResponses(acl, isReturnInheritedPermissions, sids); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override @Transactional void createAcl(ObjectIdentity objectIdentity); @Override @Transactional void createPermission(Permission permission); @Override @Transactional void createPermissions(Set<Permission> permissions); @Override @Transactional void updatePermission(Permission permission); @Override @Transactional void updatePermissions(Set<Permission> permissions); @Override @Transactional void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override @Transactional void addType(String typeId); @Override @Transactional void deleteType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid);  }