예제 #1
0
 /**
  * Change the default address
  * 
  * @param string $username The username of the user to add the Exchange account to
  * @param string $emailAddress The email address to make default
  * @param bool $isGUID Is the username passed a GUID or a samAccountName
  * @return bool
  */
 public function primaryAddress($username, $emailAddress, $isGUID = false)
 {
     if ($username === NULL) {
         return "Missing compulsory field [username]";
     }
     if ($emailAddress === NULL) {
         return "Missing compulsory fields [emailAddress]";
     }
     // Find the dn of the user
     $user = $this->adldap->user()->info($username, array("cn", "proxyaddresses"), $isGUID);
     if ($user[0]["dn"] === NULL) {
         return false;
     }
     $userDn = $user[0]["dn"];
     if (is_array($user[0]["proxyaddresses"])) {
         $modAddresses = array();
         for ($i = 0; $i < sizeof($user[0]['proxyaddresses']); $i++) {
             if (strstr($user[0]['proxyaddresses'][$i], 'SMTP:') !== false) {
                 $user[0]['proxyaddresses'][$i] = str_replace('SMTP:', 'smtp:', $user[0]['proxyaddresses'][$i]);
             }
             if ($user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) {
                 $user[0]['proxyaddresses'][$i] = str_replace('smtp:', 'SMTP:', $user[0]['proxyaddresses'][$i]);
             }
             if ($user[0]['proxyaddresses'][$i] != '') {
                 $modAddresses['proxyAddresses'][$i] = $user[0]['proxyaddresses'][$i];
             }
         }
         $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $modAddresses);
         if ($result == false) {
             return false;
         }
         return true;
     }
 }
 public function AfterLoginAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $adldap = new adLDAP();
     $username = $this->get('security.context')->getToken()->getUsername();
     //var_dump($adldap->user()->authenticate($username, $this->get('security.context')->getToken()->getCredentials()));
     $TousLesPersonne = $em->getRepository('DeveloppementCartopliBundle:Personne')->findAll();
     foreach ($TousLesPersonne as $Personne) {
         $prenom = $Personne->getPrenom();
         $nom = $Personne->getNom();
         $compteAd = strtolower(substr($prenom, 0, 1)) . strtolower($nom);
         $userinfo = $adldap->user()->infoCollection($compteAd, array("*"));
         if ($userinfo == false) {
             echo $compteAd;
             exit;
         } else {
             echo $userinfo->mail;
             exit;
         }
     }
     $userinfo = $adldap->user()->infoCollection($username, array("*"));
     if ($em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($username)) {
         $UtilisateurCo = $em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($this->get('security.context')->getToken()->getUsername());
         $em->flush();
         echo "Connecté au moins une fois";
     } else {
         if ($em->getRepository('DeveloppementCartopliBundle:Personne')->PersonneByMailPersonne($userinfo->mail)) {
             echo "Nouveau utilisateur";
         } else {
             //var_dump($em->getRepository('DeveloppementCartopliBundle:Personne')->PersonneByMailPersonne($userinfo->mail));
             echo "Nouveau";
         }
     }
     exit;
     return $this->redirect($this->generateUrl('developpement_cartopli_applications'));
 }
예제 #3
0
 /**
  * Remove a user from a group
  * 
  * @param string $group The group to remove a user from
  * @param string $user The AD user to remove from the group
  * @param bool $isGUID Is the username passed a GUID or a samAccountName
  * @return bool
  */
 public function removeUser($group, $user, $isGUID = false)
 {
     // Find the parent dn
     $groupInfo = $this->info($group, array("cn"));
     if ($groupInfo[0]["dn"] === NULL) {
         return false;
     }
     $groupDn = $groupInfo[0]["dn"];
     // Find the users dn
     $userDn = $this->adldap->user()->dn($user, $isGUID);
     if ($userDn === false) {
         return false;
     }
     $del = array();
     $del["member"] = $userDn;
     $result = @ldap_mod_del($this->adldap->getLdapConnection(), $groupDn, $del);
     if ($result == false) {
         return false;
     }
     return true;
 }
 public function loadUserByUsername($username)
 {
     // effectuez un appel à votre service web ici
     // $userData = ...
     // supposons qu'il retourne un tableau en cas de succès, ou bien
     // « false » s'il n'y a pas d'utilisateur
     //return new LdapUser($username, $password, $salt, $roles);
     $adldap = new adLDAP();
     if ($adldap->user()->authenticate($username, $this->password)) {
         //                $userinfo = $adldap->user()->info($username, array("physicalDeliveryOfficeName","mail","displayname"));
         //                $em=$this->getDoctrine()->getEntityManager();
         //                 if($em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($username))
         //                 {
         //
         //                    $UtilisateurCo=$em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($this->get('security.context')->getToken()->getUsername());
         //                    $em->flush();
         //                    throw new UsernameNotFoundException("Connecté au moin une foi");
         //                 }
         //                 else{
         //
         //                   if($em->getRepository('DeveloppementCartopliBundle:Personne')->PersonneByMailPersonne($userinfo[0]["mail"][0]))
         //                 {
         //                       throw new UsernameNotFoundException("Nouveau utilisateur");
         //                   }
         //                   else{
         //                       throw new UsernameNotFoundException("Nouveau");
         //                   }
         //                 }
         if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_ADMIN')) {
             return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_ADMIN"));
         } else {
             if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_ADMIN_CST')) {
                 return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_ADMIN_CST"));
             } else {
                 if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_UTILISATEUR')) {
                     return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_UTILISATEUR"));
                 } else {
                     if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_CORRECTEUR')) {
                         return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_CORRECTEUR"));
                     } else {
                         if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_CORRECTEUR_IT')) {
                             return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_CORRECTEUR_IT"));
                         } else {
                             if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_LECTEUR')) {
                                 return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_LECTEUR"));
                             } else {
                                 throw new UsernameNotFoundException("Vous ne faites pas partie d'un groupe pour l'application, vous n'avez pas les droits.");
                             }
                         }
                     }
                 }
             }
         }
     } else {
         // var_dump ($this->password);
         //var_dump ($adldap->user()->authenticate($username, $this->password));
         //exit();
         throw new UsernameNotFoundException("Erreur de saisie");
     }
     //var_dump( $adldap->user()->authenticate('jbeutin_stage', '070893'));
     //$user = $adldap->user()->infoCollection('jbeutin_stage', array('*'));
     //var_dump($adldap);
     //echo $user->displayName;
     //$groupArray = $user->memberOf;
     // foreach ($groupArray as $group) {
     //echo $group . "\n";
     //}
     // if ($username=="user2"&& $this->password=="userpass2" )
     // {
     // }
     // else {
     //  throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     //}
 }