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 linked in this page 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?
This is the login function:
public function login() {
/*if($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash("Invalid data provided");
}
}*/
App::import('Lib', 'ldap');
if ($this->Session->read('Auth.User')) {
$this->redirect(array('controller' => 'allocations', 'action' => 'index'));
} elseif (!empty($this->data)) {
$ldap = new ldap;
if ($ldap->auth($this->Auth->request->data['User']['username'], $this->Auth->request->data['User']['password'])) {
/*$userrow = $this->User->findByUsername($this->data['User']['username']);
if (!$userrow) {
$ldap_info = $ldap->getInfo($this->data['User']['username']);
$this->data['User']['user'] = $this->data['User']['username'];
$this->data['User']['name'] = $ldap_info['name'];
$this->data['User']['group_id'] = 3; //sets the default group
$this->add();
$userrow = $this->User->findByUsername($this->data['User']['user']);
}
$user = $userrow['User'];*/
$user = array()
$this->Auth->Session->write($this->Auth->sessionKey, $user);
$this->Auth->_loggedIn = true;
$this->redirect($this->Auth->redirect());
$this->Session->setFlash('You are logged in!');
} else {
$this->Session->setFlash(__('Login Failed', true));
}
}
}
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!