diff --git a/src/ninegate-1.0/src/Cadoles/CASBundle/Controller/SecurityController.php b/src/ninegate-1.0/src/Cadoles/CASBundle/Controller/SecurityController.php index 350b94a1..3cfb2a89 100644 --- a/src/ninegate-1.0/src/Cadoles/CASBundle/Controller/SecurityController.php +++ b/src/ninegate-1.0/src/Cadoles/CASBundle/Controller/SecurityController.php @@ -22,17 +22,17 @@ class SecurityController extends Controller public function loginAction(Request $request) { - // Récupération de la cible de navigation + // Récupération de la cible de navigation $redirect = $request->get("redirect"); - + // Masteridentity $masteridentity=$this->getParameter("masteridentity"); // Init Client CAS \phpCAS::setDebug("/var/log/phpcas/phpCAS-ninegate.log"); - @\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('cas_host'), $this->getParameter('cas_port'), is_null($this->getParameter('cas_path')) ? '' : $this->getParameter('cas_path'), false); + \phpCAS::client(CAS_VERSION_2_0, $this->getParameter('cas_host'), $this->getParameter('cas_port'), is_null($this->getParameter('cas_path')) ? '' : $this->getParameter('cas_path'), false); \phpCAS::setNoCasServerValidation(); - + // Authentification \phpCAS::forceAuthentication(); @@ -52,13 +52,13 @@ class SecurityController extends Controller $em = $this->getDoctrine()->getManager(); if(isset($attributes[$this->getParameter('user_attr_cas_username')])) $username = $attributes[$this->getParameter('user_attr_cas_username')]; - + if(isset($attributes[$this->getParameter('user_attr_cas_mail')])) $email = $attributes[$this->getParameter('user_attr_cas_mail')]; - + if(isset($attributes[$this->getParameter('user_attr_cas_lastname')])) $lastname = $attributes[$this->getParameter('user_attr_cas_lastname')]; - + if(isset($attributes[$this->getParameter('user_attr_cas_firstname')])) $firstname = $attributes[$this->getParameter('user_attr_cas_firstname')]; @@ -96,7 +96,7 @@ class SecurityController extends Controller $user->setPassword("CASPWD-".$username); $user->setSalt("CASPWD-".$username); - + $user->setNiveau01($niveau01); $user->setSiren($niveau01->getSiren()); $user->setSiret(""); @@ -105,8 +105,8 @@ class SecurityController extends Controller $user->setVisible(true); $user->setAuthlevel("simple"); $user->setRole("ROLE_USER"); - - if(in_array($username,$this->getParameter("ldap_usersadmin"))) + + if(in_array($username,$this->getParameter("ldap_usersadmin"))) $user->setRole("ROLE_ADMIN"); $em->persist($user); @@ -116,7 +116,7 @@ class SecurityController extends Controller $this->submitGroup($attributes); // On calcule les groupes de l'utilisateur - $user=$em->getRepository('CadolesCoreBundle:Group')->calculateGroup($user,$attributes); + $user=$em->getRepository('CadolesCoreBundle:Group')->calculateGroup($user,$attributes); } } @@ -138,7 +138,7 @@ class SecurityController extends Controller $user->setNiveau01($niveau01); $user->setNiveau02(null); } - if(in_array($username,$this->getParameter("ldap_usersadmin"))) + if(in_array($username,$this->getParameter("ldap_usersadmin"))) $user->setRole("ROLE_ADMIN"); // Génération auto des groupes @@ -166,7 +166,7 @@ class SecurityController extends Controller } $ssoitems=$attributes[$user_attr_cas_item]; } - } + } $this->get('session')->set('ssoitems', $ssoitems); // Autoconnexion @@ -194,7 +194,7 @@ class SecurityController extends Controller public function logoutAction() { // Init Client CAS \phpCAS::setDebug(false); - @\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('cas_host'), $this->getParameter('cas_port'), is_null($this->getParameter('cas_path')) ? '' : $this->getParameter('cas_path'), true); + \phpCAS::client(CAS_VERSION_2_0, $this->getParameter('cas_host'), $this->getParameter('cas_port'), is_null($this->getParameter('cas_path')) ? '' : $this->getParameter('cas_path'), true); \phpCAS::setNoCasServerValidation(); @@ -208,9 +208,9 @@ class SecurityController extends Controller // Init Client CAS \phpCAS::setDebug("/var/log/phpcas/phpCAS-ninegate.log"); - @\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('cas_host'), $this->getParameter('cas_port'), is_null($this->getParameter('cas_path')) ? '' : $this->getParameter('cas_path'), false); + \phpCAS::client(CAS_VERSION_2_0, $this->getParameter('cas_host'), $this->getParameter('cas_port'), is_null($this->getParameter('cas_path')) ? '' : $this->getParameter('cas_path'), false); \phpCAS::setNoCasServerValidation(); - + // Authentification \phpCAS::forceAuthentication(); @@ -221,12 +221,12 @@ class SecurityController extends Controller // Récupération Attribut $attributes = \phpCAS::getAttributes(); $user = $em->getRepository('CadolesCoreBundle:User')->findOneBy(array("username"=>$username)); - + // On calcule le niveau01 de l'utilisateur $niveau01=$em->getRepository('CadolesCoreBundle:Niveau01')->calculateNiveau01($attributes); // Génération auto des groupes - $groups=$this->submitGroup($attributes); + $groups=$this->submitGroup($attributes); // On calcule les groupes de l'utilisateur $user=$em->getRepository('CadolesCoreBundle:Group')->calculateGroup($user,$attributes); @@ -234,12 +234,12 @@ class SecurityController extends Controller return $this->render('CadolesCASBundle:Test:test.html.twig',[ 'useheader' => true, 'usemenu' => false, - 'usesidebar' => false, + 'usesidebar' => false, 'attributes' => $attributes, 'user' => $user, 'username' => $username, - 'niveau01' => $niveau01, - ]); + 'niveau01' => $niveau01, + ]); } @@ -258,26 +258,38 @@ class SecurityController extends Controller } foreach($attributes[$user_attr_cas_group] as $ssogroup) { + $basedn=$this->getParameter('ldap_basedn'); + $name=$ssogroup; + if($basedn!="") { + // Si présence du basedn dans le nom du groupe = nous sommes en présence d'un DN = on récupere donc comme nom que son cn + if(stripos($name,$basedn)!==false) { + $tbname=explode(",",$name); + $tbname=explode("=",$tbname[0]); + $name=$tbname[1]; + } + } + + // Recherche du groupe - $group=$em->getRepository("CadolesCoreBundle:Group")->findOneBy(["label"=>$ssogroup]); + $group=$em->getRepository("CadolesCoreBundle:Group")->findOneBy(["label"=>$name]); if(!$group) { $group=new Group(); - $group->setLabel($ssogroup); + $group->setLabel($name); $group->setFgcancreatepage(false); $group->setFgcancreateblog(false); $group->setFgcancreatecalendar(false); - $group->setFgcancreateproject(false); - $group->setFgcanshare(false); + $group->setFgcancreateproject(false); + $group->setFgcanshare(false); $group->setFgopen(false); - $group->setFgall(false); + $group->setFgall(false); } - + $group->setAttributes('{"'.$user_attr_cas_group.'":"'.$ssogroup.'"}'); $group->setFgtemplate(false); $em->persist($group); - $em->flush(); - + $em->flush(); + } }