public static function post_login($parameters) { $uid = $parameters['uid']; $casBackend = OC_USER_CAS::getInstance(); $userDatabase = new OC_User_Database(); if (phpCAS::isAuthenticated()) { // $cas_attributes may vary in name, therefore attributes are fetched to $attributes $cas_attributes = phpCAS::getAttributes(); $cas_uid = phpCAS::getUser(); // parameters $attributes = array(); if ($cas_uid == $uid) { OC_Log::write('cas', 'attr \\"' . implode(',', $cas_attributes) . '\\" for the user: '******'cas_name'] = $cas_attributes[$casBackend->displayNameMapping]; } else { $attributes['cas_name'] = $cas_attributes['cn']; } if (array_key_exists($casBackend->mailMapping, $cas_attributes)) { $attributes['cas_email'] = $cas_attributes[$casBackend->mailMapping]; } else { $attributes['cas_email'] = $cas_attributes['mail']; } if (array_key_exists($casBackend->groupMapping, $cas_attributes)) { $attributes['cas_groups'] = $cas_attributes[$casBackend->groupMapping]; } else { if (!empty($casBackend->defaultGroup)) { $attributes['cas_groups'] = array($casBackend->defaultGroup); OC_Log::write('cas', 'Using default group "' . $casBackend->defaultGroup . '" for the user: '******'/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) { OC_Log::write('cas', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OC_Log::DEBUG); return false; } else { $random_password = OC_Util::generateRandomBytes(20); OC_Log::write('cas', 'Creating new user: ' . $uid, OC_Log::DEBUG); $userDatabase->createUser($uid, $random_password); // after creating the user, fill the attributes if ($userDatabase->userExists($uid)) { OC_USER_CAS_Hooks::update_user($uid, $attributes); } } } // try to update user attributes if ($casBackend->updateUserData) { OC_USER_CAS_Hooks::update_user($cas_uid, $attributes); } return true; } } return false; }
public static function post_login($parameters) { $uid = $parameters['uid']; $wuid = $uid; $casBackend = new OC_USER_CAS(); $userDB = new OC_User_Database(); /* * Récupération des données du fichier config général /config/config.php */ $serveur_Search = OCP\Config::getSystemValue('serveur_Search', 'error'); $port = OCP\Config::getSystemValue('port', 'error'); $racineAMU = OCP\Config::getSystemValue('racineAMU', 'error'); $racineAMUGRP = OCP\Config::getSystemValue('racineAMUGRP', 'error'); $AMU_nuage_dn = OCP\Config::getSystemValue('AMU_nuage_dn', 'error'); $AMU_nuage_pw = OCP\Config::getSystemValue('AMU_nuage_pw', 'error'); $PQuota = OCP\Config::getSystemValue('PQuota', 'unManaged'); $EQuota = OCP\Config::getSystemValue('EQuota', 'unManaged'); $LDAP = new LDAP_Infos($serveur_Search, $AMU_nuage_dn, $AMU_nuage_pw, $racineAMUGRP, $racineAMUGRP); $restrictGrp = array("cn", "member"); /* * Récupération tableau Groupes * Si le tableau 'groupMapping' est vide pas de contrôle sur les groupes */ $AccesCloud = 0; OCP\Util::writeLog('user_cas', "Authentification (Mapping groups=" . $casBackend->groupMapping . ")", OCP\Util::DEBUG); if ($casBackend->groupMapping) { $wTabGrp = str_replace(array('<br>', '<br />', "\n", "\r"), array('@', '', '@', ''), $casBackend->groupMapping); $tabGRP = explode("@", $wTabGrp); $i = 0; $mesGroupes = array(); foreach ($tabGRP as $key => $value) { $ListeMembre = $LDAP->getMembersOfGroup($value, $restrictGrp); if (in_array($uid, $ListeMembre)) { $AccesCloudAMU = 1; } } } else { $AccesCloud = 1; } /* * Si pas d'acces, alors déconnexion */ if ($AccesCloud == 0) { /* * On vérifie si le compte utilisé est un compte local */ if (!$userDB->userExists($uid)) { OCP\Util::writeLog('user_cas', "Aucun droit d'accès pour l'utilisateur " . $uid, OCP\Util::ERROR); \OC_User::logout(); } else { OCP\Util::writeLog('user_cas', "Authentification locale pour l'utilisateur " . $uid, OCP\Util::DEBUG); OC::$REQUESTEDAPP = ''; OC_Util::redirectToDefaultPage(); exit(0); } } /** * Récupère les groupes liés à l'utilisateur avec la racine définie dans le formulaire 'cas_group_root' * Si 'cas_group_root' n'est pas renseingé => pas de récupération de groupes */ $mesGroupes = array(); OCP\Util::writeLog('user_cas', "Authentification (Racine Groupes LDAP=" . $casBackend->groupRoot . ")", OCP\Util::DEBUG); if ($casBackend->groupRoot) { $i = 0; $ListeGRP = $LDAP->getMemberOf($uid); $a = sizeof($ListeGRP); OCP\Util::writeLog('user_cas', "Taille=" . $a . " UID=" . $uid, OCP\Util::ERROR); OCP\Util::writeLog('user_cas', "Racine Groupe=" . $casBackend->groupRoot, OCP\Util::ERROR); foreach ($ListeGRP as $key => $value) { if (strstr($value, $casBackend->groupRoot)) { $mesGroupes[$i] = strtoupper(str_replace(':', '_', substr($value, 8))); OCP\Util::writeLog('user_cas', "Groupe[{$i}]=" . $mesGroupes[$i], OCP\Util::ERROR); $i++; } } } if (phpCAS::checkAuthentication()) { //$attributes = phpCAS::getAttributes(); $cas_uid = phpCAS::getUser(); if ($cas_uid == $uid) { /* * Récupération des information utilisateur (LDAP) */ $tabLdapUser = $LDAP->getUserInfo($uid); if ($tabLdapUser) { $DisplayName = $tabLdapUser['displayName']; } if (!$userDB->userExists($uid)) { if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) { OCP\Util::writeLog('cas', 'Utilisateur invalide "' . $uid . '", caracteres autorises "a-zA-Z0-9" and "_.@-" ', OCP\Util::DEBUG); return false; } else { /* * Dans le cas d'une création */ $random_password = \OC_Util::generateRandomBytes(20); $userDB->createUser($uid, $tabLdapUser['userpassword']); $userDB->setDisplayName($uid, $DisplayName); /* * Mise à jour du quota si gestion dans fichier de configuration */ if ($EQuota != "unManaged" && $tabLdapUser['eduPersonPrimaryAffiliation'] == 'student') { update_quota($uid, $EQuota); } if ($PQuota != "unManaged" && $tabLdapUser['eduPersonPrimaryAffiliation'] != 'student') { update_quota($uid, $PQuota); } } } /* * Mise à jour des groupes associés */ if (sizeof($mesGroupes) > 0) { $cas_groups = $mesGroupes; update_groups($uid, $cas_groups, $casBackend->protectedGroups, true); } /* * Mise à jour du mail */ update_mail($uid, $tabLdapUser['Mail']); /* * Mise à jour du display name */ $userDB->setDisplayName($uid, $DisplayName); return true; } } return false; }