* Sync IdP groups into FileRise Pro groups using a prefix-based mapping. * * - Only runs when FR_PRO_ACTIVE + FR_PRO_BUNDLE_DIR + FR_OIDC_PRO_GROUP_PREFIX are set. * - Only groups whose *IdP name* starts with FR_OIDC_PRO_GROUP_PREFIX are considered. * - The Pro group name is derived from the suffix, normalized to [a-z0-9_-]. * - For those Pro groups: * - Ensure th
(string $username, array $groups)
| 891 | * - Does NOT touch per-folder grants; admins still configure ACLs via the Pro UI. |
| 892 | */ |
| 893 | public static function syncOidcGroupsToPro(string $username, array $groups): void |
| 894 | { |
| 895 | if (empty($groups)) { |
| 896 | return; |
| 897 | } |
| 898 | if ( |
| 899 | !defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE || |
| 900 | !defined('FR_PRO_BUNDLE_DIR') || !FR_PRO_BUNDLE_DIR || |
| 901 | !defined('FR_OIDC_PRO_GROUP_PREFIX') |
| 902 | ) { |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | $prefix = (string)FR_OIDC_PRO_GROUP_PREFIX; |
| 907 | $prefixLen = strlen($prefix); |
| 908 | |
| 909 | // Normalize incoming groups to a clean list of strings |
| 910 | $raw = []; |
| 911 | foreach ($groups as $g) { |
| 912 | $g = trim((string)$g); |
| 913 | if ($g !== '') { |
| 914 | $raw[] = $g; |
| 915 | } |
| 916 | } |
| 917 | if (!$raw) { |
| 918 | return; |
| 919 | } |
| 920 | |
| 921 | // Map IdP groups → Pro group names (suffix of prefix, normalized) |
| 922 | $desiredNames = []; |
| 923 | foreach ($raw as $g) { |
| 924 | if ($prefix === '' || stripos($g, $prefix) === 0) { |
| 925 | $slug = ($prefix === '') |
| 926 | ? $g |
| 927 | : substr($g, $prefixLen); |
| 928 | |
| 929 | $slug = strtolower(preg_replace('/[^a-z0-9_\-]/i', '_', $slug)); |
| 930 | if ($slug !== '') { |
| 931 | $desiredNames[] = $slug; |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | $desiredNames = array_values(array_unique($desiredNames)); |
| 936 | if (!$desiredNames) { |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | $proGroupsPath = rtrim((string)FR_PRO_BUNDLE_DIR, "/\\") . '/ProGroups.php'; |
| 941 | if (!is_file($proGroupsPath)) { |
| 942 | return; |
| 943 | } |
| 944 | |
| 945 | require_once $proGroupsPath; |
| 946 | if (!class_exists('ProGroups')) { |
| 947 | return; |
| 948 | } |
| 949 | |
| 950 | $store = new ProGroups(FR_PRO_BUNDLE_DIR); |
no test coverage detected