@Override
  public void addManagedRepository(String repositoryId)
      throws NoSuchRepositoryException, ConfigurationException, IOException,
          NoSuchAuthorizationManagerException, NoSuchRoleException {
    final Repository repository;
    try {
      // Call verifies that the repository exists
      repository = this.repositoryRegistry.getRepository(repositoryId);
    } catch (NoSuchRepositoryException e) {
      throw new NoSuchRepositoryException(
          "Cannot manage repository that doesn't exist: " + repositoryId, e);
    }

    groupManagementPluginConfiguration.addManagedRepository(repositoryId);

    // Go through and add all privs/roles needed for the new repository for every existing managed
    // groupId
    final ManagedRepository managedRepository = this.createManagedRepository(repository);
    final ManagedGroupIds managedGroupIds = getManagedGroupIds();
    for (final ManagedGroupId managedGroupId : managedGroupIds.getManagedGroupIds()) {
      this.addRepositoryForGroupId(managedGroupId.getGroupId(), managedRepository);
    }

    this.nexusConfiguration.saveConfiguration();
  }
  @Override
  public void removeManagedRepository(String repositoryId)
      throws NoSuchRepositoryException, NoSuchPrivilegeException,
          NoSuchAuthorizationManagerException, IOException {
    final ManagedRepository repository = this.getAsManagedRepository(repositoryId);

    groupManagementPluginConfiguration.removeManagedRepository(repositoryId);

    final ManagedGroupIds managedGroupIds = getManagedGroupIds();
    for (final ManagedGroupId managedGroupId : managedGroupIds.getManagedGroupIds()) {
      this.removeRepositoryForGroupId(managedGroupId.getGroupId(), repository);
    }

    this.nexusConfiguration.saveConfiguration();
  }