public function setPermissions($type, $identifier, $permissions)
    {
        foreach ($permissions as $roleId => $rolePermissions) {
            $accessControl = $this->accessControlRepository->findByTypeAndIdAndRole($type, $identifier, $roleId);

            if ($accessControl) {
                $accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
            } else {
                $role = $this->roleRepository->findRoleById($roleId);

                $accessControl = new AccessControl();
                $accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
                $accessControl->setRole($role);
                $accessControl->setEntityId($identifier);
                $accessControl->setEntityClass($type);
                $this->objectManager->persist($accessControl);
            }
        }

        $this->objectManager->flush();
    }