示例#1
0
 /**
  * Return Doctrine EntityManager
  *
  * @param string $emName
  * @return \Doctrine\ORM\EntityManager
  */
 protected function getEntityManager($emName = null)
 {
     $containers = Core_Registry::getContainers();
     $emName = strtolower($emName);
     if (array_key_exists($emName, $containers)) {
         return $containers[$emName];
     }
     $dContainer = $this->locator->getDoctrineContainer();
     return $dContainer->getEntityManager($emName);
 }
示例#2
0
 /**
  * @return Zend_Controller_Plugin_Abstract
  */
 public function init()
 {
     $containers = $this->getOptions();
     foreach ($containers as $keyContainer => $container) {
         if (!isset($container['class'])) {
             continue;
         }
         $configs = isset($container['configs']) ? $container['configs'] : array();
         $configs += array('options' => array(), 'class' => 'Core_Model_OWM_Configuration');
         $objectConfig = new $configs['class']();
         foreach ($configs['options'] as $key => $config) {
             $methodSet = 'set' . $key;
             $methodAdd = 'add' . $key;
             if (method_exists($objectConfig, $methodSet) || method_exists($objectConfig, $methodAdd)) {
                 $objectConfig->{$methodSet}($config);
             }
         }
         unset($configs['class'], $configs['options']);
         $objectConfig->setConfigs($configs);
         $container = $container['class']::create($container['options'], $objectConfig);
         Core_Registry::setContainer($keyContainer, $container);
     }
     return Core_Registry::getContainers();
 }
示例#3
0
 protected function autenticateLdap()
 {
     try {
         $container = Core_Registry::getContainers();
         $ldap = $container['ldap']->getPersist();
         $config = \Zend_Registry::get('configs');
         $samAccountNameQuery = "samAccountName={$this->getIdentity()}";
         /**
          * Modifica o host para o servidor secundário.
          */
         if ($this->_secondaryHost && isset($config['resources']['container']['ldap']['host']['secondary'])) {
             $options = $ldap->getOptions();
             $options['host'] = $config['resources']['container']['ldap']['host']['secondary'];
             $ldap = new Zend_Ldap($options);
         }
         $admUsr = $config['authenticate']['username'];
         $admPwd = $config['authenticate']['password'];
         $ldap->bind($admUsr, $admPwd);
         $userLdapCount = $ldap->count($samAccountNameQuery);
         if ($userLdapCount <= 0) {
             throw new \Sica_Auth_Exception('MN175');
         }
         $userLdap = current($ldap->search($samAccountNameQuery)->toArray());
         $pwdLastSetLDAPTimestamp = isset($userLdap['pwdlastset'][0]) ? $userLdap['pwdlastset'][0] : 0;
         $pwdLastSetLDAPTimestamp_div = bcdiv($pwdLastSetLDAPTimestamp, '10000000');
         $pwdLastSetLDAPTimestamp_sub = bcsub($pwdLastSetLDAPTimestamp_div, '11644473600');
         $pwdLastSetDate = new \Zend_Date($pwdLastSetLDAPTimestamp_sub, \Zend_Date::TIMESTAMP);
         $measureTime = new \Zend_Measure_Time(\Zend_Date::now()->sub($pwdLastSetDate)->toValue(), \Zend_Measure_Time::SECOND);
         $measureTime->convertTo(\Zend_Measure_Time::DAY);
         $daysLeftToChangePwd = ceil($measureTime->getValue());
         if ($daysLeftToChangePwd >= self::LDAP_MAX_PWD_LAST_SET_DAYS) {
             throw new \Sica_Auth_Exception('EXPIRED_PWD_MSG');
         }
         $ldap->bind($this->getIdentity(), $this->getCredential());
         return TRUE;
     } catch (\Sica_Auth_Exception $authExc) {
         $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
         $this->_authenticateResultInfo['messages'] = $authExc->getMessage();
         return false;
     } catch (\Zend_Ldap_Exception $ldapExc) {
         $ldapCode = $ldapExc->getCode();
         $message = sprintf('[SICA-e] LDAP Error in %s: "%s"', __METHOD__, $ldapExc->getMessage());
         error_log($message);
         $message = sprintf('[Erro no LDAP] %s', $ldapExc->getMessage());
         /**
          * Se não foi possível contactar o servidor LDAP e se não
          * for uma tentativa de autenticação no servidor secundário.
          */
         if ($ldapCode == self::LDAP_CONST_CODE_CANT_CONTACT_SERVER && !$this->_secondaryHost) {
             #Tentativa de autenticação no servidor secundário.
             $this->_secondaryHost = TRUE;
             return $this->autenticateLdap();
         }
         if ($ldapCode > 0) {
             $message = sprintf('LDAP0x%02x', $ldapCode);
         }
         if (false !== strpos($ldapExc->getMessage(), self::LDAP_CONST_NT_STATUS_PASSWORD_EXPIRED)) {
             $message = 'EXPIRED_PWD_MSG';
         }
         $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_UNCATEGORIZED;
         $this->_authenticateResultInfo['messages'] = $message;
         return false;
     }
 }