Jump to content

Edit History

Laetitia Bordon

Laetitia Bordon


solved

Hello,

I would like connect the user with ldap in prestashop in place of the login form.

Is someone did that? How?

I found this in the symfony doc https://symfony.com/doc/3.4/components/ldap.html

I've a script in php who does the connection and retrieve (with functions) the datas.

In classic php script, I do that to have infos :

include_once $_SERVER['DOCUMENT_ROOT'].'/titi/include/authentication.inc.php'; //the script I call for the ldap authentification
if (!$authenticated_user->is_valid()) 
{ 
	header('HTTP/1.0 401 Unauthorized'); 
	print 'Use portal - Ma zone/Mijn zone to access this application'; 
	exit; 
}
//get the service of the person
$service=$authenticated_user->get_service();

In the authentication script, I get the $_SERVER['HTTP_USER_AGENT'] var and I do treatments to do the authentification

/* * -------------------------------------------------------------------- * 
* Toute l'authentification se passe ici !!! 
* l'HTTP_USER_AGENT est de la forme "FedPol-Portal/2.0 445759153F" * 
* -------------------------------------------------------------------- */ 
class Authenticated_User 
{ 
  private $matricule = 0; 
  private $language = ''; 
  private $zone = ''; 
  private $grade=''; 
  private $ldap_data = ''; 
  private $user_found = false; 
  private $ldap_connect; 
  public $sso; 

  public function __construct() { 
    $sso = $_SERVER['HTTP_USER_AGENT']; 
    $this->sso = $sso; $this->matricule = array_pop(explode(' ', $sso)); 
    //$this->language = $this->matricule[strlen($this->matricule)-1]; 
    $this->language=substr($this->matricule,9,1); 
    if(strlen($this->matricule)>11) { 
      $this->zone = substr($this->matricule, 10, 4); 
      $this->grade = substr($this->matricule, 14, 3); 
    } 
    $this->matricule = substr($this->matricule, 0, 9); 
    $this->ldap_connect = ldap_connect(LDAP_HOST); 
    if ($this->ldap_connect) 
    { 
      ldap_set_option($this->ldap_connect, LDAP_OPT_PROTOCOL_VERSION, LDAP_PROTO); 
      $ldap_bind = ldap_bind($this->ldap_connect); /* bind au ldap en anonymous */ 
      if ($ldap_bind) { 
        $search = ldap_search($this->ldap_connect, LDAP_BASE, "(uid=$this->matricule)"); 
        $info = ldap_get_entries($this->ldap_connect, $search); 
        $this->user_found = $info["count"]; $this->ldap_data = $info[0]; 
      } 
    } 
  } 

  public function is_valid() { return $this->user_found; } 

  public function getsso() { return $this->sso; } 

  public function authorize($objectClass, $attributes = true) { // possede t on l'object class dont il est question ? 
    if (in_array($objectClass, $this->ldap_data['objectclass'])) { 
      if ($attributes) { // recuperation du schema LDAP pour determiner les attributs interessants $result = array(); 
        $info = ldap_read($this->ldap_connect, 'cn=subschema', '(objectClass=*)',array('objectclasses')); 
        $entries = ldap_get_entries($this->ldap_connect, $info); 
        foreach ($entries[0]['objectclasses'] as $entry) { 
          if (preg_match("/$objectClass/", $entry)) { 
            $list = ''; 
            if (preg_match('/MUST \(/', $entry)) $list = preg_replace('/.* MUST \((.*?)\).*/','$1',$entry); 
            elseif (preg_match('/MUST/', $entry)) $list = preg_replace('/.* MUST (.*?) .*/','$1',$entry); 
            if (preg_match('/MAY \(/', $entry)) 
            { 
              if ($list) $list .= ' $ '; 
              $list .= preg_replace('/.* MAY \((.*?)\).*/','$1',$entry); 
            } 
            elseif (preg_match('/MAY/', $entry)) 
            { 
              if ($list) $list .= ' $ '; 
              $list .= preg_replace('/.* MAY (.*?) .*/','$1',$entry); 
            } 
            if ($list) 
            { 
            foreach (explode('$', $list) as $attr) $result[trim($attr)]=$this->ldap_data[strtolower(trim($attr))][0]; 
            } 
          } 
        } 
        return array(true, $result); 
      } 
      else return array(true); 
    } 
    else return array(false); 
  } 

  public function get_matricule() { return $this->matricule; } 
  public function get_language() { return $this->language; } 
  public function get_zone() { return $this->zone; } 
  public function get_name() { return $this->ldap_data['cn'][0]; } 
  public function get_service() { return $this->ldap_data['bepolbruservice'][0]; } 
  public function get_mail() { return $this->ldap_data['mail'][0]; } 
  public function get_name2() { return $this->ldap_data['sn'][0].' '.$this->ldap_data['givenname'][0]; } 
  public function get_sn() { return $this->ldap_data['sn'][0]; } 
  public function get_givename() { return $this->ldap_data['givenname'][0]; } 
  public function get_grade() { return $this->grade; } 
  public function get_classes() { return $this->ldap_data['objectclass']; } 
} 

$authenticated_user = new Authenticated_User();

How can I do the same thing in prestashop? 

Is in the AdminLoginController.php (for the backOffice)? And where is the AdminController class?

Thank you for the help

Laetitia Bordon

Laetitia Bordon


solved

Hello,

I would like connect the user with ldap in prestashop in place of the login form.

Is someone did that? How?

I found this in the symfony doc https://symfony.com/doc/3.4/components/ldap.html

I've a script in php who does the connection and retrieve (with functions) the datas.

In classic php script, I do that to have infos :

include_once $_SERVER['DOCUMENT_ROOT'].'/titi/include/authentication.inc.php'; //the script I call for the ldap authentification
if (!$authenticated_user->is_valid()) 
{ 
	header('HTTP/1.0 401 Unauthorized'); 
	print 'Use portal - Ma zone/Mijn zone to access this application'; 
	exit; 
}
//get the service of the person
$service=$authenticated_user->get_service();

In the authentication script, I get the $_SERVER['HTTP_USER_AGENT'] var and I do treatments to do the authentification

/* * -------------------------------------------------------------------- * 
* Toute l'authentification se passe ici !!! 
* l'HTTP_USER_AGENT est de la forme "FedPol-Portal/2.0 445759153F" * 
* -------------------------------------------------------------------- */ 
class Authenticated_User 
{ 
  private $matricule = 0; 
  private $language = ''; 
  private $zone = ''; 
  private $grade=''; 
  private $ldap_data = ''; 
  private $user_found = false; 
  private $ldap_connect; 
  public $sso; 

  public function __construct() { 
    $sso = $_SERVER['HTTP_USER_AGENT']; 
    $this->sso = $sso; $this->matricule = array_pop(explode(' ', $sso)); 
    //$this->language = $this->matricule[strlen($this->matricule)-1]; 
    $this->language=substr($this->matricule,9,1); 
    if(strlen($this->matricule)>11) { 
      $this->zone = substr($this->matricule, 10, 4); 
      $this->grade = substr($this->matricule, 14, 3); 
    } 
    $this->matricule = substr($this->matricule, 0, 9); 
    $this->ldap_connect = ldap_connect(LDAP_HOST); 
    if ($this->ldap_connect) 
    { 
      ldap_set_option($this->ldap_connect, LDAP_OPT_PROTOCOL_VERSION, LDAP_PROTO); 
      $ldap_bind = ldap_bind($this->ldap_connect); /* bind au ldap en anonymous */ 
      if ($ldap_bind) { 
        $search = ldap_search($this->ldap_connect, LDAP_BASE, "(uid=$this->matricule)"); 
        $info = ldap_get_entries($this->ldap_connect, $search); 
        $this->user_found = $info["count"]; $this->ldap_data = $info[0]; 
      } 
    } 
  } 

  public function is_valid() { return $this->user_found; } 

  public function getsso() { return $this->sso; } 

  public function authorize($objectClass, $attributes = true) { // possede t on l'object class dont il est question ? 
    if (in_array($objectClass, $this->ldap_data['objectclass'])) { 
      if ($attributes) { // recuperation du schema LDAP pour determiner les attributs interessants $result = array(); 
        $info = ldap_read($this->ldap_connect, 'cn=subschema', '(objectClass=*)',array('objectclasses')); 
        $entries = ldap_get_entries($this->ldap_connect, $info); 
        foreach ($entries[0]['objectclasses'] as $entry) { 
          if (preg_match("/$objectClass/", $entry)) { 
            $list = ''; 
            if (preg_match('/MUST \(/', $entry)) $list = preg_replace('/.* MUST \((.*?)\).*/','$1',$entry); 
            elseif (preg_match('/MUST/', $entry)) $list = preg_replace('/.* MUST (.*?) .*/','$1',$entry); 
            if (preg_match('/MAY \(/', $entry)) 
            { 
              if ($list) $list .= ' $ '; 
              $list .= preg_replace('/.* MAY \((.*?)\).*/','$1',$entry); 
            } 
            elseif (preg_match('/MAY/', $entry)) 
            { 
              if ($list) $list .= ' $ '; 
              $list .= preg_replace('/.* MAY (.*?) .*/','$1',$entry); 
            } 
            if ($list) 
            { 
            foreach (explode('$', $list) as $attr) $result[trim($attr)]=$this->ldap_data[strtolower(trim($attr))][0]; 
            } 
          } 
        } 
        return array(true, $result); 
      } 
      else return array(true); 
    } 
    else return array(false); 
  } 

  public function get_matricule() { return $this->matricule; } 
  public function get_language() { return $this->language; } 
  public function get_zone() { return $this->zone; } 
  public function get_name() { return $this->ldap_data['cn'][0]; } 
  public function get_service() { return $this->ldap_data['bepolbruservice'][0]; } 
  public function get_mail() { return $this->ldap_data['mail'][0]; } 
  public function get_name2() { return $this->ldap_data['sn'][0].' '.$this->ldap_data['givenname'][0]; } 
  public function get_sn() { return $this->ldap_data['sn'][0]; } 
  public function get_givename() { return $this->ldap_data['givenname'][0]; } 
  public function get_grade() { return $this->grade; } 
  public function get_classes() { return $this->ldap_data['objectclass']; } 
} 

$authenticated_user = new Authenticated_User();

How can I do the same thing in prestashop? 

Is in the AdminLoginController.php (for the backOffice)? And where is the AdminController class?

Thank you for the help

Laetitia Bordon

Laetitia Bordon

Hello,

I would like connect the user with ldap in prestashop in place of the login form.

Is someone did that? How?

I found this in the symfony doc https://symfony.com/doc/3.4/components/ldap.html

I've a script in php who does the connection and retrieve (with functions) the datas.

In classic php script, I do that to have infos :

include_once $_SERVER['DOCUMENT_ROOT'].'/titi/include/authentication.inc.php'; //the script I call for the ldap authentification
if (!$authenticated_user->is_valid()) 
{ 
	header('HTTP/1.0 401 Unauthorized'); 
	print 'Use portal - Ma zone/Mijn zone to access this application'; 
	exit; 
}
//get the service of the person
$service=$authenticated_user->get_service();

In the authentication script, I get the $_SERVER['HTTP_USER_AGENT'] var and I do treatments to do the authentification

/* * -------------------------------------------------------------------- * 
* Toute l'authentification se passe ici !!! 
* l'HTTP_USER_AGENT est de la forme "FedPol-Portal/2.0 445759153F" * 
* -------------------------------------------------------------------- */ 
class Authenticated_User 
{ 
  private $matricule = 0; 
  private $language = ''; 
  private $zone = ''; 
  private $grade=''; 
  private $ldap_data = ''; 
  private $user_found = false; 
  private $ldap_connect; 
  public $sso; 

  public function __construct() { 
    $sso = $_SERVER['HTTP_USER_AGENT']; 
    $this->sso = $sso; $this->matricule = array_pop(explode(' ', $sso)); 
    //$this->language = $this->matricule[strlen($this->matricule)-1]; 
    $this->language=substr($this->matricule,9,1); 
    if(strlen($this->matricule)>11) { 
      $this->zone = substr($this->matricule, 10, 4); 
      $this->grade = substr($this->matricule, 14, 3); 
    } 
    $this->matricule = substr($this->matricule, 0, 9); 
    $this->ldap_connect = ldap_connect(LDAP_HOST); 
    if ($this->ldap_connect) 
    { 
      ldap_set_option($this->ldap_connect, LDAP_OPT_PROTOCOL_VERSION, LDAP_PROTO); 
      $ldap_bind = ldap_bind($this->ldap_connect); /* bind au ldap en anonymous */ 
      if ($ldap_bind) { 
        $search = ldap_search($this->ldap_connect, LDAP_BASE, "(uid=$this->matricule)"); 
        $info = ldap_get_entries($this->ldap_connect, $search); 
        $this->user_found = $info["count"]; $this->ldap_data = $info[0]; 
      } 
    } 
  } 

  public function is_valid() { return $this->user_found; } 

  public function getsso() { return $this->sso; } 

  public function authorize($objectClass, $attributes = true) { // possede t on l'object class dont il est question ? 
    if (in_array($objectClass, $this->ldap_data['objectclass'])) { 
      if ($attributes) { // recuperation du schema LDAP pour determiner les attributs interessants $result = array(); 
        $info = ldap_read($this->ldap_connect, 'cn=subschema', '(objectClass=*)',array('objectclasses')); 
        $entries = ldap_get_entries($this->ldap_connect, $info); 
        foreach ($entries[0]['objectclasses'] as $entry) { 
          if (preg_match("/$objectClass/", $entry)) { 
            $list = ''; 
            if (preg_match('/MUST \(/', $entry)) $list = preg_replace('/.* MUST \((.*?)\).*/','$1',$entry); 
            elseif (preg_match('/MUST/', $entry)) $list = preg_replace('/.* MUST (.*?) .*/','$1',$entry); 
            if (preg_match('/MAY \(/', $entry)) 
            { 
              if ($list) $list .= ' $ '; 
              $list .= preg_replace('/.* MAY \((.*?)\).*/','$1',$entry); 
            } 
            elseif (preg_match('/MAY/', $entry)) 
            { 
              if ($list) $list .= ' $ '; 
              $list .= preg_replace('/.* MAY (.*?) .*/','$1',$entry); 
            } 
            if ($list) 
            { 
            foreach (explode('$', $list) as $attr) $result[trim($attr)]=$this->ldap_data[strtolower(trim($attr))][0]; 
            } 
          } 
        } 
        return array(true, $result); 
      } 
      else return array(true); 
    } 
    else return array(false); 
  } 

  public function get_matricule() { return $this->matricule; } 
  public function get_language() { return $this->language; } 
  public function get_zone() { return $this->zone; } 
  public function get_name() { return $this->ldap_data['cn'][0]; } 
  public function get_service() { return $this->ldap_data['bepolbruservice'][0]; } 
  public function get_mail() { return $this->ldap_data['mail'][0]; } 
  public function get_name2() { return $this->ldap_data['sn'][0].' '.$this->ldap_data['givenname'][0]; } 
  public function get_sn() { return $this->ldap_data['sn'][0]; } 
  public function get_givename() { return $this->ldap_data['givenname'][0]; } 
  public function get_grade() { return $this->grade; } 
  public function get_classes() { return $this->ldap_data['objectclass']; } 
} 

$authenticated_user = new Authenticated_User();

How can I do the same thing in prestashop? 

Is in the AdminLoginController.php (for the backOffice)? And where is the AdminController class?

Thank you for the help

×
×
  • Create New...