public static void createLDAPRole(
     KeycloakSession session,
     RealmModel appRealm,
     UserFederationProviderModel ldapModel,
     String mapperName,
     String roleName) {
   UserFederationMapperModel mapperModel =
       appRealm.getUserFederationMapperByName(ldapModel.getId(), mapperName);
   LDAPFederationProvider ldapProvider = FederationTestUtils.getLdapProvider(session, ldapModel);
   getRoleMapper(mapperModel, ldapProvider, appRealm).createLDAPRole(roleName);
 }
 public static void removeAllLDAPGroups(
     KeycloakSession session,
     RealmModel appRealm,
     UserFederationProviderModel ldapModel,
     String mapperName) {
   UserFederationMapperModel mapperModel =
       appRealm.getUserFederationMapperByName(ldapModel.getId(), mapperName);
   LDAPFederationProvider ldapProvider = FederationTestUtils.getLdapProvider(session, ldapModel);
   LDAPQuery roleQuery = getGroupMapper(mapperModel, ldapProvider, appRealm).createGroupQuery();
   List<LDAPObject> ldapRoles = roleQuery.getResultList();
   for (LDAPObject ldapRole : ldapRoles) {
     ldapProvider.getLdapIdentityStore().remove(ldapRole);
   }
 }
  public static LDAPObject createLDAPGroup(
      KeycloakSession session,
      RealmModel appRealm,
      UserFederationProviderModel ldapModel,
      String groupName,
      String... additionalAttrs) {
    UserFederationMapperModel mapperModel =
        appRealm.getUserFederationMapperByName(ldapModel.getId(), "groupsMapper");
    LDAPFederationProvider ldapProvider = FederationTestUtils.getLdapProvider(session, ldapModel);

    Map<String, Set<String>> additAttrs = new HashMap<>();
    for (int i = 0; i < additionalAttrs.length; i += 2) {
      String attrName = additionalAttrs[i];
      String attrValue = additionalAttrs[i + 1];
      additAttrs.put(attrName, Collections.singleton(attrValue));
    }

    return getGroupMapper(mapperModel, ldapProvider, appRealm)
        .createLDAPGroup(groupName, additAttrs);
  }