6

Doctrine2とZF2を使用して認証を行いたいのですが。ヘルプを得るために、Zend 2 + doctrine 2 Auth Adapterを使用しましたが、呼び出すたびに$authService->authenticate($adapter);、クラス''が存在しないというエラーが表示されます。

module.config.phpの設定は使用されないようです。これは次のように表示されます。

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

しかし、authServiceでvar_dumpを作成した場合、すべてのセットがnullになります。私がログインしたい私のサービスでは、私は電話します

$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;
}

では、オプションを正しく設定する方法を教えてもらえますか?

4

2 に答える 2

10

間違った構成値を使用しているようです。DoctrineORMのドキュメントを見ると、認証アダプターの構成を設定するために以下を使用しています。

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

したがって、 module.config.phpでauthenticationadapteruseを使用する代わりに; 使用するauthentication代わりに、など。objectManagerobject_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']);

ドキュメントに従ってください。

于 2013-03-02T15:17:41.313 に答える
0

Hohner が提案するように Module.php で「Zend\Authentication\AuthenticationService」を使用している場合、これは BjyAuthorize モジュールの役割と ACL では機能しません。BjyAuthorize は、「ZfcUser\Authentication\Storage\Db」を使用する認証サービスの独自のデフォルト構成にデフォルト設定されます。BjyAuthorize に Doctrine ID を使用させるには、次のように「zfcuser_auth_service」に置き換えます (または追加します):

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

次に、同様の方法でコントローラーでも使用します。

$authService = $this->getServiceLocator()->get( 'zfcuser_auth_service' );
于 2014-06-04T12:57:37.167 に答える