2013-03-02 9 views
6

मैं सिद्धांत 2 और ZF2 का उपयोग करके प्रमाणीकरण करना चाहता हूं। कुछ मदद पाने के लिए मैंने Zend 2 + doctrine 2 Auth Adapter का उपयोग किया, लेकिन हर बार जब मैं $authService->authenticate($adapter); पर कॉल करता हूं तो मुझे एक त्रुटि मिलती है कि वर्ग '' मौजूद नहीं है।Zend2 + Doctrine2 प्रमाणीकरण

ऐसा लगता है कि मेरे module.config.php से कॉन्फ़िगर # टी का उपयोग नहीं किया गया। यह इस तरह दिखाता है:

'authenticationadapter' => array(
     'orm_default' => array(
      'objectManager' => 'doctrine.entitymanager.orm_default', 
      'identityClass' => 'Profile\Entity\User', 
      'identityProperty' => 'username', 
      'credentialProperty' => 'password', 
     ), 
    ), 

लेकिन अगर मैंने authService पर var_dump बनाया है तो सभी सेट शून्य हैं। मेरी सेवा में, जहां मैं लॉगिन करना चाहते हैं मैं

$authAdapter = $this->getAuthAdapter(); 
$authAdapter->setIdentityValue($username); 
$authAdapter->setCredentialValue($password); 

फोन $ authAdapter से एक डंप मुझसे कहता है कि IdentityValue और CredentialValue सही ढंग से स्थापित कर रहे हैं।

$ authAdabter में अन्य बातों के कर रहे हैं:

protected 'options' => 
    object(DoctrineModule\Options\Authentication)[281] 
     protected 'objectManager' => 
     object(Doctrine\ORM\EntityManager)[248] 
      private 'config' => 
      object(Doctrine\ORM\Configuration)[250] 
       ... 
      private 'conn' => 
      object(Doctrine\DBAL\Connection)[252] 
       ... 
      private 'metadataFactory' => 
      object(Doctrine\ORM\Mapping\ClassMetadataFactory)[266] 
       ... 
      private 'repositories' => 
      array (size=0) 
       ... 
      private 'unitOfWork' => 
      object(Doctrine\ORM\UnitOfWork)[267] 
       ... 
      private 'eventManager' => 
      object(Doctrine\Common\EventManager)[242] 
       ... 
      private 'hydrators' => 
      array (size=0) 
       ... 
      private 'proxyFactory' => 
      object(Doctrine\ORM\Proxy\ProxyFactory)[268] 
       ... 
      private 'expressionBuilder' => null 
      private 'closed' => boolean false 
      private 'filterCollection' => null 
     protected 'objectRepository' => null 
     protected 'identityClass' => null 
     protected 'identityProperty' => null 
     protected 'credentialProperty' => null 
     protected 'credentialCallable' => null 
     protected 'classMetadata' => null 
     protected 'storage' => null 
     protected '__strictMode__' => boolean true 
    protected 'authenticationResultInfo' => null 

getAuthAdapter इस तरह पता चलता है:

public function getAuthAdapter() 
{ 
    if (null === $this->authAdapter) { 
     $this->authAdapter = $this->getServiceManager() 
      ->get('doctrine.authenticationadapter.ormdefault'); 
    } 
    return $this->authAdapter; 
} 

तो कुछ एक मुझे बताओ कैसे सही ढंग से विकल्प सेट करने के कर सकते हैं?

उत्तर

10

ऐसा लगता है कि आप गलत कॉन्फ़िगरेशन मान का उपयोग कर रहे हैं। आप DoctrineORM प्रलेखन को देखें, तो वे प्रमाणीकरण एडाप्टर के लिए विन्यास निर्धारित करने के लिए निम्नलिखित का उपयोग करें: बजाय अपने module.config.php में authenticationadapter उपयोग authentication का उपयोग कर के,

'doctrine' => array(
    'authentication' => array(
     'orm_default' => array(
      'object_manager' => 'Doctrine\ORM\EntityManager', 
      'identity_class' => 'Application\Entity\User', 
      'identity_property' => 'email', 
      'credential_property' => 'password', 
     ), 
    ), 
) 

तो; बजाय objectManager उपयोग object_manager, आदि


का उपयोग कर अपने Module.php में की, तो आप इस जोड़ने की आवश्यकता होगी:

use Zend\Authentication\AuthenticationService; 

... 

public function getServiceConfig() 
{ 
    return array(
     'factories' => array(
      'Zend\Authentication\AuthenticationService' => function($serviceManager) { 
       return $serviceManager->get('doctrine.authenticationservice.orm_default'); 

      } 
     ) 
    ); 
} 

और अपने नियंत्रक में, आप का उपयोग कर एडाप्टर पहुँच सकते हैं:

$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService'); 

$adapter = $authService->getAdapter(); 
$adapter->setIdentityValue($data['login']); 
$adapter->setCredentialValue($data['password']); 

कृपया documentation का पालन करें।

+0

ठीक है मैं बदलने के लिए:

'zfcuser_auth_service' => function ($serviceManager) { return $authenticationService = $serviceManager->get('doctrine.authenticationservice.orm_default'); }, 

तो फिर तुम भी यह नियंत्रक में एक समान तरीके से उपयोग करें: इस प्रकार BjyAuthorize प्राप्त करने के लिए के साथ बदलने के सिद्धांत पहचान का उपयोग करना (या जोड़ें) 'zfcuser_auth_service' लेकिन अब यह मुझे 'ज़ेंड \ ServiceManager \ ServiceManager :: बताता है कि getctine.authentication.orm_default' के लिए कोई उदाहरण लाने या बनाने में असमर्थ था। मैं गेटटर को 'पब्लिक फ़ंक्शन getAuthAdapter() { (null === $ this-> authAdapter) { $ यह-> authAdapter = $ this-> getServiceManager() -> प्राप्त करें (' doctrine.authentication ।orm_default '); } $ 2-> authAdapter; ' –

+0

अद्यतन उत्तर – hohner

+0

आपकी सहायता के लिए धन्यवाद देखें। अब केवल एक समस्या बाकी है। '$ AuthResult = $ authService-> प्रमाणीकरण() के बाद; 'मुझे एक खाली पृष्ठ मिलता है। कोई त्रुटि नहीं, कुछ भी नहीं। –

0

यदि आप होहनेर द्वारा सुझाए गए मॉड्यूल.एफ़पी में 'ज़ेंड \ प्रमाणीकरण \ प्रमाणीकरण सेवा' का उपयोग कर रहे हैं, तो यह BjyAuthorize मॉड्यूल भूमिकाओं और एसीएल के साथ काम नहीं करेगा। BjyAuthorize प्रमाणीकरण सेवा की अपनी डिफ़ॉल्ट कॉन्फ़िगरेशन के लिए डिफ़ॉल्ट होगा जो 'ZfcUser \ प्रमाणीकरण \ संग्रहण \ Db' का उपयोग करता है।

$authService = $this->getServiceLocator()->get('zfcuser_auth_service'); 
संबंधित मुद्दे