@Test void testCreatePermission() { MutableAcl acl = mock(MutableAcl.class); when(mutableAclService.readAclById(new ObjectIdentityImpl("entity-typeId", "identifier"))) .thenReturn(acl); when(mutableAclClassService.getAclClassTypes()).thenReturn(singletonList("entity-typeId")); Sid role = new GrantedAuthoritySid("ROLE_role"); permissionsApiService.createPermission( Permission.create(new ObjectIdentityImpl("entity-typeId", "identifier"), role, WRITE)); verify(acl).insertAce(0, WRITE, role, true); verify(mutableAclService).updateAcl(acl); }
@Override @Transactional public void createPermission(Permission permission) { ObjectIdentity objectIdentity = permission.getObjectIdentity(); checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); if (!getSuitablePermissionsForType(objectIdentity.getType()) .contains(permission.getPermission())) { throw new PermissionNotSuitableException( permission.getPermission().name(), objectIdentity.getType()); } Sid sid = permission.getSid(); if (getPermissionResponses(acl, false, singleton(sid)).isEmpty()) { acl.insertAce(acl.getEntries().size(), permission.getPermission(), sid, true); mutableAclService.updateAcl(acl); } else { throw new DuplicatePermissionException(objectIdentity, sid); } }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void createPermission(Permission permission) { ObjectIdentity objectIdentity = permission.getObjectIdentity(); checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); if (!getSuitablePermissionsForType(objectIdentity.getType()) .contains(permission.getPermission())) { throw new PermissionNotSuitableException( permission.getPermission().name(), objectIdentity.getType()); } Sid sid = permission.getSid(); if (getPermissionResponses(acl, false, singleton(sid)).isEmpty()) { acl.insertAce(acl.getEntries().size(), permission.getPermission(), sid, true); mutableAclService.updateAcl(acl); } else { throw new DuplicatePermissionException(objectIdentity, sid); } } }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void createPermission(Permission permission) { ObjectIdentity objectIdentity = permission.getObjectIdentity(); checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); if (!getSuitablePermissionsForType(objectIdentity.getType()) .contains(permission.getPermission())) { throw new PermissionNotSuitableException( permission.getPermission().name(), objectIdentity.getType()); } Sid sid = permission.getSid(); if (getPermissionResponses(acl, false, singleton(sid)).isEmpty()) { acl.insertAce(acl.getEntries().size(), permission.getPermission(), sid, true); mutableAclService.updateAcl(acl); } else { throw new DuplicatePermissionException(objectIdentity, sid); } } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void createPermission(Permission permission) { ObjectIdentity objectIdentity = permission.getObjectIdentity(); checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); if (!getSuitablePermissionsForType(objectIdentity.getType()) .contains(permission.getPermission())) { throw new PermissionNotSuitableException( permission.getPermission().name(), objectIdentity.getType()); } Sid sid = permission.getSid(); if (getPermissionResponses(acl, false, singleton(sid)).isEmpty()) { acl.insertAce(acl.getEntries().size(), permission.getPermission(), sid, true); mutableAclService.updateAcl(acl); } else { throw new DuplicatePermissionException(objectIdentity, sid); } } 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 @Transactional public void createPermission(Permission permission) { ObjectIdentity objectIdentity = permission.getObjectIdentity(); checkTypeExists(objectIdentity.getType()); entityHelper.checkEntityExists(objectIdentity); MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity); if (!getSuitablePermissionsForType(objectIdentity.getType()) .contains(permission.getPermission())) { throw new PermissionNotSuitableException( permission.getPermission().name(), objectIdentity.getType()); } Sid sid = permission.getSid(); if (getPermissionResponses(acl, false, singleton(sid)).isEmpty()) { acl.insertAce(acl.getEntries().size(), permission.getPermission(), sid, true); mutableAclService.updateAcl(acl); } else { throw new DuplicatePermissionException(objectIdentity, sid); } } 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);  }