Announcement

Collapse
No announcement yet.

Authentication using control and ldap

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Authentication using control and ldap

    hi i'm new in scriptcase... i've tried to do a login with application of control and ldap... i read about using the PHP functions and code in the onValidate Event, but i don't know how to do this..... anyone can help me
    Thanks

  • #2
    Re: Authentication using control and ldap

    I just learn how to do it.... I've created a library with a function called "verifica_login()" wich connects to ldap server and I've used to in an application of control in the onValidate Events... as follows

    ldap_conect.php - Conexion con LDAP

    Code:
     0| <?php
     1|
     2|
     3| function verifica_login($usuario, $password) {
     4|   $res = array(
     5|     'success' => false
     6|   );
     7|   $ldap = ldap_connect("<ldap server>");
     8|   if (!$ldap) {
     9|     $res&#91;'errors'] = array(
    10|       'reason' => 'No es posible conectar al servidor ldap'
    11|     );
    12|     return $res;
    13|   }
    14|   /* bind anonimo */
    15|   $conectado = @ldap_bind($ldap);
    16|   if ($conectado !== TRUE) {
    17|     $res&#91;'errors'] = array(
    18|       'reason' => 'No es posible conectar al servidor ldap (anonimo)'
    19|     );
    20|     return $res;
    21|   }
    22|   /*     */
    23|   $filtro = "(uid=" . $usuario . ")";
    24|   $base = "ou=<ou description>,dc=<dc descriptcion>";
    25|
    26|   $search = ldap_search($ldap, $base, $filtro, array('dn', 'displayName'));
    27|   $info = ldap_get_entries($ldap, $search);
    28|
    29|   
    30|   if (@$info&#91;'count'] != 1) {
    31|     $res&#91;'errors'] = array(
    32|       'reason' => 'No puede iniciar sesion. Verifique que su usuario y contraseņa sean correctos..'
    33|     );
    34|     return $res;
    35|   }
    36|   /* usuario fue encontrado */
    37|   $dn = $info[0]&#91;'dn'];
    38|   $conectado = @ldap_bind($ldap, $dn, $password);
    39|   if ($conectado === TRUE) {
    40|     $res&#91;'success'] = true;
    41|     $res&#91;'usuario'] = $usuario;
    42|     $res&#91;'descripcion'] = isset($info[0]) && isset($info[0]&#91;'displayname']) ? $info[0]&#91;'displayname'][0] : '';
    43|   }
    44|   else {
    45|     $res&#91;'errors'] = array(
    46|       'reason' => 'No puede iniciar sesion. Verifique que su usuario y contraseņa sean correctos.'
    47|     );
    48|   }
    49|   ldap_close($ldap);
    50|   return $res;
    51| }
    52|
    53| ?>
    and in the onValidate Event

    Code:
    // Redirection parameters
    $res = verifica_login({user}, {pass});
    $redir_app  = 'grid_co_referencial';         // Application name
    $redir_target = '_self';         // Target window (_blank, _self, _parent or modal)
    $redir_param = array(           // Param list, add as many as needed
    	'param_1' => 'value_1',
        'param_2' => 'value_2',
    );
    
    // Redirection
    if($res["success"]==true) {
      sc_redir($redir_app, $redir_param, $redir_target);
    }

    Comment


    • #3
      Re: Authentication using control and ldap

      Thanks for posting your solution.

      Regards,
      Scott.

      Comment


      • #4
        i try this answer, but did'nt work..
        the output "Fatal error: Call to undefined function ldap_connect() in".
        but i sure in my server LDAP is enable..
        please help me...

        Originally posted by RSOTO View Post
        I just learn how to do it.... I've created a library with a function called "verifica_login()" wich connects to ldap server and I've used to in an application of control in the onValidate Events... as follows

        ldap_conect.php - Conexion con LDAP

        Code:
         0| <?php
         1|
         2|
         3| function verifica_login($usuario, $password) {
         4|   $res = array(
         5|     'success' => false
         6|   );
         7|   $ldap = ldap_connect("<ldap server>");
         8|   if (!$ldap) {
         9|     $res['errors'] = array(
        10|       'reason' => 'No es posible conectar al servidor ldap'
        11|     );
        12|     return $res;
        13|   }
        14|   /* bind anonimo */
        15|   $conectado = @ldap_bind($ldap);
        16|   if ($conectado !== TRUE) {
        17|     $res['errors'] = array(
        18|       'reason' => 'No es posible conectar al servidor ldap (anonimo)'
        19|     );
        20|     return $res;
        21|   }
        22|   /*     */
        23|   $filtro = "(uid=" . $usuario . ")";
        24|   $base = "ou=<ou description>,dc=<dc descriptcion>";
        25|
        26|   $search = ldap_search($ldap, $base, $filtro, array('dn', 'displayName'));
        27|   $info = ldap_get_entries($ldap, $search);
        28|
        29|   
        30|   if (@$info['count'] != 1) {
        31|     $res['errors'] = array(
        32|       'reason' => 'No puede iniciar sesion. Verifique que su usuario y contraseņa sean correctos..'
        33|     );
        34|     return $res;
        35|   }
        36|   /* usuario fue encontrado */
        37|   $dn = $info[0]['dn'];
        38|   $conectado = @ldap_bind($ldap, $dn, $password);
        39|   if ($conectado === TRUE) {
        40|     $res['success'] = true;
        41|     $res['usuario'] = $usuario;
        42|     $res['descripcion'] = isset($info[0]) && isset($info[0]['displayname']) ? $info[0]['displayname'][0] : '';
        43|   }
        44|   else {
        45|     $res['errors'] = array(
        46|       'reason' => 'No puede iniciar sesion. Verifique que su usuario y contraseņa sean correctos.'
        47|     );
        48|   }
        49|   ldap_close($ldap);
        50|   return $res;
        51| }
        52|
        53| ?>
        and in the onValidate Event

        Code:
        // Redirection parameters
        $res = verifica_login({user}, {pass});
        $redir_app  = 'grid_co_referencial';         // Application name
        $redir_target = '_self';         // Target window (_blank, _self, _parent or modal)
        $redir_param = array(           // Param list, add as many as needed
        	'param_1' => 'value_1',
            'param_2' => 'value_2',
        );
        
        // Redirection
        if($res["success"]==true) {
          sc_redir($redir_app, $redir_param, $redir_target);
        }

        Comment


        • #5
          You must enable the ldap login in php, it is not probably not enabled. Check your php.ini.
          Seach for ;extension=php_ldap.dll and remove the ; in front.

          Comment


          • #6
            You must enable the ldap dll in php, it is not probably not enabled. Check your php.ini.
            Seach for ;extension=php_ldap.dll and remove the ; in front.

            Comment

            Working...
            X