Advertisement
RobsonAlexandre

Controller Autenticação Zend Auth Ldap

Feb 6th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. class AutenticacaoController extends Zend_Controller_Action {
  2.     public function init() {      
  3.     }
  4.  
  5.     public function indexAction() {
  6.         $form = new Application_Form_Login();
  7.  
  8.         if ($this->getRequest()->isPost()) {
  9.             $data = $this->getRequest()->getPost();
  10.             if ($form->isValid($data)) {
  11.                 $mm_login = $form->getValue('mm_login');
  12.                 $sha512_senha = hash('sha512', $form->getValue('sha512_senha'));
  13.                 $auth = Zend_Auth::getInstance();
  14.                 $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'production');
  15.                 $options = $config->ldap->toArray();
  16.                 $authAdapter = new Zend_Auth_Adapter_Ldap($options, $mm_login, $sha512_senha);
  17.                 $result = $auth->authenticate($authAdapter);
  18.                 if ($result->isValid()) {
  19.                     $usuario = $authAdapter->getResultRowObject();                  
  20.                     $auth->getStorage()->write($usuario);
  21.                     $session = new Zend_Session_Namespace();
  22.                     $this->_redirect($session->uri);
  23.                 } else {
  24.                     $form->getElement('error')->setLabel('Login / Senha Incorretos');
  25.                     $this->view->formulario = $form->populate($data);
  26.                 }
  27.             }
  28.         }
  29.         $this->view->formulario = $form;
  30.     }
  31.  
  32.     public function loginAction() {
  33.         $options = array(
  34.             'host' => 'dc1.dominio.com',
  35.             'port' => '389',
  36.             'useStartTls' => true,
  37.             'username' => 'cleston@dominio.com',
  38.             'password' => 'santos',
  39.             'accountDomainName' => 'dominio.com',
  40.             'accountDomainNameShort' => 'DOMINIO',
  41.             'accountCanonicalForm' => 4,
  42.             'baseDn' => 'DC=dominio,DC=com',
  43.             'bindRequiresDn' => false
  44.         );
  45.         $ldap = new Zend_Ldap($options);
  46.         $acctname = $ldap->getCanonicalAccountName('robson', Zend_Ldap::ACCTNAME_FORM_DN);
  47.         echo "$acctname\n";
  48.     }
  49.  
  50.     /*
  51.      * ACCTNAME_FORM_DN     1   CN=Alice Baker,CN=Users,DC=example,DC=com
  52.      * ACCTNAME_FORM_USERNAME   2   abaker
  53.      * ACCTNAME_FORM_BACKSLASH  3   EXAMPLE\abaker
  54.      * ACCTNAME_FORM_PRINCIPAL  4   abaker@example.com
  55.      */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement