class PermissionsManager {

  public void remove(String userId, String domainId, String instanceId)
      throws ConflictException, ServerException, NotFoundException {
    final PermissionsDao<? extends AbstractPermissions> permissionsDao =
        getPermissionsDao(domainId);
    Permissions permissions;
    try (@SuppressWarnings("unused")
        Unlocker unlocker = updateLocks.writeLock(firstNonNull(instanceId, domainId))) {
      if (userHasLastSetPermissions(permissionsDao, userId, instanceId)) {
        throw new ConflictException(
            "Can't remove permissions because there is not any another user "
                + "with permission 'setPermissions'");
      }
      permissions = permissionsDao.get(userId, instanceId);
      permissionsDao.remove(userId, instanceId);
    }
    final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
    eventService.publish(new PermissionsRemovedEvent(initiator, permissions));
  }

  @Inject public  PermissionsManager(
      EventService eventService, Set<PermissionsDao<? extends AbstractPermissions>> daos);

}