package com.sequenceiq.freeipa.client;

import java.util.List;
import java.util.function.Supplier;

public class FreeIpaChecks {
    /* Users in this list should not be added/deleted. */
    public static final List<String> IPA_PROTECTED_USERS = List.of("admin");

    /* Groups in this list should not be added/deleted. These groups are considered to be reserved in CDP-UMS.
    Therefore,
    https://github.infra.cloudera.com/thunderhead/thunderhead/blob/master/services/usermanagement/src/main/resources/com/cloudera/thunderhead/service/usermanagement/server/ipa_protected_groups.txt needs to be updated when the following list is updated. */
    public static final List<String> IPA_PROTECTED_GROUPS = List.of("admins", "editors", "ipausers", "trust admins");

    /* Group membership in these groups should not be changed. */
    public static final List<String> IPA_UNMANAGED_GROUPS = List.of("editors", "ipausers", "trust admins");

    private FreeIpaChecks() {
    }

    public static void checkUserNotProtected(String user, Supplier<String> errorMessage) throws FreeIpaClientException {
        if (IPA_PROTECTED_USERS.contains(user)) {
            throw new FreeIpaClientException(errorMessage.get());
        }
    }

    public static void checkGroupNotProtected(String group, Supplier<String> errorMessage) throws FreeIpaClientException {
        if (IPA_PROTECTED_GROUPS.contains(group)) {
            throw new FreeIpaClientException(errorMessage.get());
        }
    }

    public static void checkGroupNotUnmanaged(String group, Supplier<String> errorMessage) throws FreeIpaClientException {
        if (IPA_UNMANAGED_GROUPS.contains(group)) {
            throw new FreeIpaClientException(errorMessage.get());
        }
    }
}

@@ -167,24 +167,43 @@
 be added
-/deleted
+ to or deleted from FreeIPA
 . */%0A   
@@ -327,17 +327,40 @@
 dded
-/deleted.
+ to or deleted from FreeIPA.%0A   
  The
@@ -410,20 +410,16 @@
 CDP-UMS.
-%0A   
  Therefo
@@ -855,15 +855,37 @@
  be 
-changed
+explicitly changed in FreeIPA
 . */

Update comments