title: LDAP Authentication with CakePHP
body: <p>I'm trying to create an app where the authorization part is done by checking the input criteria against LDAP, on CakePHP. I'm following the text <a href="http://lanrat.com/ldap-authentication-for-cakephp/" rel="nofollow">linked in this page</a> but I'm having issues. I don't want to use any users table, I have no interest in storing the data. All I want to do, is grant the access to the users in case they have any LDAP credentials. I managed to estabilish the connection and check the data, but the app won't save the session, so the user is never logged in. Do you have any clue on what am I doing wrong?</p>
  
  <p>This is the login function:</p>
  
  <pre><code>    public function login() {
      /*if($this-&gt;request-&gt;is('post')) {
          if ($this-&gt;Auth-&gt;login()) {
              $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
          } else {
              $this-&gt;Session-&gt;setFlash("Invalid data provided");
          }
      }*/
      App::import('Lib', 'ldap');
      if ($this-&gt;Session-&gt;read('Auth.User')) {
           $this-&gt;redirect(array('controller' =&gt; 'allocations', 'action' =&gt; 'index'));
      } elseif (!empty($this-&gt;data)) {
          $ldap = new ldap;
          if ($ldap-&gt;auth($this-&gt;Auth-&gt;request-&gt;data['User']['username'], $this-&gt;Auth-&gt;request-&gt;data['User']['password'])) {
              /*$userrow = $this-&gt;User-&gt;findByUsername($this-&gt;data['User']['username']);
              if (!$userrow) {
                  $ldap_info = $ldap-&gt;getInfo($this-&gt;data['User']['username']);
                  $this-&gt;data['User']['user'] = $this-&gt;data['User']['username'];
                  $this-&gt;data['User']['name'] = $ldap_info['name'];
                  $this-&gt;data['User']['group_id'] = 3; //sets the default group
                  $this-&gt;add();
                  $userrow = $this-&gt;User-&gt;findByUsername($this-&gt;data['User']['user']);
              }
  
              $user = $userrow['User'];*/
              $user = array()
              $this-&gt;Auth-&gt;Session-&gt;write($this-&gt;Auth-&gt;sessionKey, $user);
              $this-&gt;Auth-&gt;_loggedIn = true;
              $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
              $this-&gt;Session-&gt;setFlash('You are logged in!');
          } else {
              $this-&gt;Session-&gt;setFlash(__('Login Failed', true));
          }
      }
  }
  </code></pre>
  
  <p>I tried debugging the ldap->auth (which basically calls an ldap_bind function stored in an external library) and the result of the auth is correct (the method returns 'true'). So the problem has to be in the creation of the session. How do I make CakePHP know that the user has been correctly logged in and that it has to store the session? Thanks!</p>