@Test void testGetPermissionsForType() { PrincipalSid sid1 = mock(PrincipalSid.class); PrincipalSid sid2 = mock(PrincipalSid.class); MutableAcl acl = mock(MutableAcl.class); ObjectIdentity objectIdentity = mock(ObjectIdentity.class); 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)); Map<ObjectIdentity, Acl> aclMap = new HashMap<>(); aclMap.put(new ObjectIdentityImpl("entity-typeId", "identifier"), acl); when(mutableAclService.readAclsById( singletonList(new ObjectIdentityImpl("entity-typeId", "identifier")), Arrays.asList(sid1, sid2))) .thenReturn(aclMap); when(objectIdentityService.getObjectIdentities("entity-typeId", newHashSet(sid1, sid2))) .thenReturn(singletonList(new ObjectIdentityImpl("entity-typeId", "identifier"))); LinkedHashSet<Sid> sids = new LinkedHashSet<>(); sids.add(sid1); sids.add(sid2); when(userRoleTools.sortSids(sids)).thenReturn(new LinkedList(sids)); when(entityHelper.getLabelledObjectIdentity(acl.getObjectIdentity())) .thenReturn( LabelledObjectIdentity.create( "entity-typeId", "typeId", "typeLabel", "identifier", "identifierLabel")); LabelledPermission permission1 = LabelledPermission.create( sid1, LabelledObjectIdentity.create( "entity-typeId", "typeId", "typeLabel", "identifier", "identifierLabel"), COUNT, null); LabelledPermission permission2 = LabelledPermission.create( sid2, LabelledObjectIdentity.create( "entity-typeId", "typeId", "typeLabel", "identifier", "identifierLabel"), WRITEMETA, null); Map<String, HashSet<LabelledPermission>> expected = Collections.singletonMap("identifier", newHashSet(permission1, permission2)); assertEquals( expected, permissionsApiService.getPermissionsForType("entity-typeId", sids, false)); }
@Override public Map<String, Set<LabelledPermission>> getPermissionsForType( String typeId, Set<Sid> sids, int page, int pageSize) { entityHelper.checkEntityTypeExists(typeId); List<ObjectIdentity> objectIdentities = objectIdentityService.getObjectIdentities(typeId, sids, pageSize, (page - 1) * pageSize); Map<ObjectIdentity, Acl> aclMap = new LinkedHashMap<>(); if (!objectIdentities.isEmpty()) { aclMap = mutableAclService.readAclsById(objectIdentities, userRoleTools.sortSids(sids)); } return getPermissions(aclMap, objectIdentities, sids, false); }
PermissionServiceImpl implements PermissionService { @Override public Map<String, Set<LabelledPermission>> getPermissionsForType( String typeId, Set<Sid> sids, int page, int pageSize) { entityHelper.checkEntityTypeExists(typeId); List<ObjectIdentity> objectIdentities = objectIdentityService.getObjectIdentities(typeId, sids, pageSize, (page - 1) * pageSize); Map<ObjectIdentity, Acl> aclMap = new LinkedHashMap<>(); if (!objectIdentities.isEmpty()) { aclMap = mutableAclService.readAclsById(objectIdentities, userRoleTools.sortSids(sids)); } return getPermissions(aclMap, objectIdentities, sids, false); } }
PermissionServiceImpl implements PermissionService { @Override public Map<String, Set<LabelledPermission>> getPermissionsForType( String typeId, Set<Sid> sids, int page, int pageSize) { entityHelper.checkEntityTypeExists(typeId); List<ObjectIdentity> objectIdentities = objectIdentityService.getObjectIdentities(typeId, sids, pageSize, (page - 1) * pageSize); Map<ObjectIdentity, Acl> aclMap = new LinkedHashMap<>(); if (!objectIdentities.isEmpty()) { aclMap = mutableAclService.readAclsById(objectIdentities, userRoleTools.sortSids(sids)); } return getPermissions(aclMap, objectIdentities, sids, false); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); }
PermissionServiceImpl implements PermissionService { @Override public Map<String, Set<LabelledPermission>> getPermissionsForType( String typeId, Set<Sid> sids, int page, int pageSize) { entityHelper.checkEntityTypeExists(typeId); List<ObjectIdentity> objectIdentities = objectIdentityService.getObjectIdentities(typeId, sids, pageSize, (page - 1) * pageSize); Map<ObjectIdentity, Acl> aclMap = new LinkedHashMap<>(); if (!objectIdentities.isEmpty()) { aclMap = mutableAclService.readAclsById(objectIdentities, userRoleTools.sortSids(sids)); } return getPermissions(aclMap, objectIdentities, sids, false); } 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 Map<String, Set<LabelledPermission>> getPermissionsForType( String typeId, Set<Sid> sids, int page, int pageSize) { entityHelper.checkEntityTypeExists(typeId); List<ObjectIdentity> objectIdentities = objectIdentityService.getObjectIdentities(typeId, sids, pageSize, (page - 1) * pageSize); Map<ObjectIdentity, Acl> aclMap = new LinkedHashMap<>(); if (!objectIdentities.isEmpty()) { aclMap = mutableAclService.readAclsById(objectIdentities, userRoleTools.sortSids(sids)); } return getPermissions(aclMap, objectIdentities, sids, false); } 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);  }