Exemple #1
0
function url_maybe_adapt_idp($url, $idpAuthnRequest_url)
{
    if (!$idpAuthnRequest_url) {
        return $url;
    }
    global $currentIdpId;
    global $entityID_to_AuthnRequest_url;
    $currentAuthnRequest = $entityID_to_AuthnRequest_url[$currentIdpId];
    $url_ = removePrefixOrNULL($url, $currentAuthnRequest);
    if ($url_) {
        $url = $idpAuthnRequest_url . $url_;
        debug_msg("personalized shib url is now {$url}");
    }
    return $url;
}
function uportalGetChannel($channelFile, $groupNameToPagsKeysAndUsers)
{
    $xml = simplexml_load_file($channelFile);
    $users = simplexml_get_string_array($xml->users->user);
    $groupNames = simplexml_get_string_array($xml->groups->group);
    list($subUsers, $groups) = uportalGetPagsKeysAndUsers($groupNames, $groupNameToPagsKeysAndUsers);
    $fname = (string) $xml->fname;
    $channel = array();
    $channel["text"] = (string) $xml->name;
    $channel["title"] = (string) $xml->title;
    $channel["description"] = (string) $xml->desc;
    $channel["users"] = array_merge($users, $subUsers);
    $channel["groups"] = $groups;
    if ($xml->hashelp == 'Y') {
        $channel["hashelp"] = true;
    }
    foreach ($xml->portletPreferences->portletPreference as $pref) {
        if ($pref->name == 'url') {
            $url = (string) $pref->values->value;
            $service = removePrefixOrNULL($url, "/ExternalURLStats?fname={$fname}&service=");
            if ($service) {
                $url = urldecode($service);
                $channel["useExternalURLStats"] = true;
            } else {
                error_log("{$fname}: no ExternalURLStats in {$url}");
            }
            $channel["url"] = uportalAbsolutateUrl($url);
        }
    }
    foreach ($xml->parameters->parameter as $param) {
        if ($param->name == 'hideFromMobile') {
            $channel['hideFromMobile'] = $param->value == 'true';
        }
    }
    return array($fname, $channel);
}
function getShibPersonFromHeaders()
{
    checkShibProxyKey();
    $person = array();
    foreach ($_SERVER as $rawKey => $v) {
        $k = removePrefixOrNULL($rawKey, "HTTP_AJP_");
        if (is_null($k)) {
            $k = removePrefixOrNULL($rawKey, "HTTP_");
        }
        if ($k === "UNSCOPED_AFFILIATION") {
            $k = "eduPersonAffiliation";
        }
        if ($k === "PRIMARY_AFFILIATION") {
            $k = "eduPersonPrimaryAffiliation";
        }
        if ($k === "SHIB_IDENTITY_PROVIDER") {
            $k = "Shib-Identity-Provider";
        }
        if ($k === "ORG_DN") {
            $k = "eduPersonOrgDN";
        }
        if ($k && !preg_match("/^(Accept|Accept_Charset|Accept_Encoding|Accept_Language|Accept_Datetime|Authorization|Cache_Control|Connection|Cookie|Content_Length|Content_MD5|Content_Type|Date|Expect|From|Host|If_Match|If_Modified_Since|If_None_Match|If_Range|If_Unmodified_Since|Max_Forwards|Pragma|Proxy_Authorization|Range|Referer|TE|Upgrade|User_Agent|Via|Warning)\$/i", $k) && !preg_match("/^(X_.*|Shib_Application_ID|Shib_Authentication_Instant|Shib_AuthnContext_Decl|Shib_Session_ID|Shib_Assertion_Count|Shib_Authentication_Method|Shib_AuthnContext_Class)\$/i", $k) && $k !== "PREFERREDLANGUAGE" && $v) {
            $person[strtolower($k)] = explode(";", $v);
        }
    }
    $uid = eppn2uid($person['eppn']);
    if ($uid) {
        $person['uid'] = $uid;
        $person['id'] = $uid;
    } else {
        $person['id'] = $person['eppn'];
    }
    return $person;
}
function userAttributesKeyToText(&$user, $wanted_attrs)
{
    $supannEntiteAffectation = @$user['supannEntiteAffectation'];
    if ($supannEntiteAffectation) {
        if (isset($wanted_attrs['supannEntiteAffectation-all'])) {
            $user['supannEntiteAffectation-all'] = structureAll($supannEntiteAffectation);
        } else {
            if (isset($wanted_attrs['supannEntiteAffectation-ou'])) {
                $user['supannEntiteAffectation-ou'] = structureShortnames($supannEntiteAffectation);
            } else {
                if (isset($wanted_attrs['supannEntiteAffectation'])) {
                    // deprecated
                    $user['supannEntiteAffectation'] = structureShortnames($supannEntiteAffectation);
                }
            }
        }
    }
    if (isset($user['supannParrainDN'])) {
        if (isset($wanted_attrs['supannParrainDN-all'])) {
            $user['supannParrainDN-all'] = structureAll(rdnToSupannCodeEntites($user['supannParrainDN']));
        } else {
            if (isset($wanted_attrs['supannParrainDN-ou'])) {
                $user['supannParrainDN-ou'] = structureShortnames(rdnToSupannCodeEntites($user['supannParrainDN']));
            }
        }
        if (!isset($wanted_attrs['supannParrainDN'])) {
            unset($user['supannParrainDN']);
        }
    }
    if (isset($user['supannEtuInscription'])) {
        if (isset($wanted_attrs['supannEtuInscription-all'])) {
            $user['supannEtuInscription-all'] = supannEtuInscriptionsAll($user['supannEtuInscription']);
        }
        if (!isset($wanted_attrs['supannEtuInscription'])) {
            unset($user['supannEtuInscription']);
        }
    }
    if (isset($user['supannRoleEntite'])) {
        if (isset($wanted_attrs['supannRoleEntite-all'])) {
            $user['supannRoleEntite-all'] = supannRoleEntitesAll($user['supannRoleEntite']);
        }
        if (!isset($wanted_attrs['supannRoleEntite'])) {
            unset($user['supannRoleEntite']);
        }
    }
    if (isset($user['memberOf'])) {
        if (isset($wanted_attrs['memberOf-all'])) {
            $user['memberOf-all'] = memberOfAll($user['memberOf']);
        }
        if (!isset($wanted_attrs['memberOf'])) {
            unset($user['memberOf']);
        }
    }
    if (isset($user['supannRoleGenerique'])) {
        global $roleGeneriqueKeyToShortname;
        foreach ($user['supannRoleGenerique'] as &$e) {
            $e = $roleGeneriqueKeyToShortname[$e];
        }
    }
    if (isset($user['supannActivite'])) {
        if (isset($wanted_attrs['supannActivite-all'])) {
            $user['supannActivite-all'] = supannActiviteAll($user['supannActivite']);
        }
        if (isset($wanted_attrs['supannActivite'])) {
            $user['supannActivite'] = supannActiviteShortnames($user['supannActivite']);
        } else {
            unset($user['supannActivite']);
        }
    }
    if (isset($user['supannEtablissement'])) {
        // only return interesting supannEtablissement (ie not Paris1)
        $user['supannEtablissement'] = array_values(array_diff($user['supannEtablissement'], array('{UAI}0751717J', "{autre}")));
        if (!$user['supannEtablissement']) {
            unset($user['supannEtablissement']);
        } else {
            global $etablissementKeyToShortname;
            foreach ($user['supannEtablissement'] as &$e) {
                $usefulKey = removePrefixOrNULL($e, "{AUTRE}");
                $name = @$etablissementKeyToShortname[$e];
                if ($name) {
                    $e = $usefulKey ? "{$name} [{$usefulKey}]" : $name;
                }
            }
        }
    }
}