1

私は新しい Symfony2 プロジェクト (eibrowser) を開発しており、2 つのことを設定しようとしています: 1. カスタム認証プロバイダー 2. カスタム ユーザー プロバイダー

Symfony2 のドキュメント ページにある例 / チュートリアル (ほぼ単語ごと) に従いました。

http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html セキュリティ フォルダが存在する私のバンドルは 'NiwaUtilitiesBundle' と呼ばれます。

結局、この(恐ろしく)紛らわしいエラーメッセージが表示されます

Catchable Fatal Error: Argument 3 passed to Niwa\UtilitiesBundle\Security\Firewall
\WsseListener::__construct() must be an instance of Niwa\UtilitiesBundle\SecurityFirewall
\SessionAuthenticationStrategyInterface, none given, called in /home/uwe/www/eibrowser2
/app/cache/dev/appDevDebugProjectContainer.php on line 2007 and defined in /home/uwe
/www/eibrowser2/src/Niwa/UtilitiesBundle/Security/Firewall/WsseListener.php line 21 

ここにコードのどの部分を表示すればよいかさえわかりません....

ただし、以下のコードは、認証を行う社内のユーザー管理システムを使用しているため、少し変更する必要がある WsseProvider を示しています。

<?php 

namespace Niwa\UtilitiesBundle\Security\Authentication\Provider;

use Symfony\Component\Security\Core\Authentication\Provider   AuthenticationProviderInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\NonceExpiredException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Niwa\UtilitiesBundle\Security\Authentication\Token\WsseUserToken;

use Niwa\UsermanagementBundle\Lib\UserManagement;


class WsseProvider implements AuthenticationProviderInterface
{
    private $userProvider;
    private $cacheDir;
    private $userManagement;

public function __construct(UserProviderInterface $userProvider, $cacheDir,$userManagement)
{
    $this->userProvider   = $userProvider;
    $this->cacheDir       = $cacheDir;
    $this->userManagement = $userManagement;
}

public function authenticate(TokenInterface $token)
{
    $user = $this->userProvider->loadUserByName($token->getUsername());

    if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) {
        $authenticatedToken = new UmUserToken($user->getRoles());
        $authenticatedToken->setUser($user);

        return $authenticatedToken;
    }

    throw new AuthenticationException('The WSSE authentication failed.');
}

/**
 * This function is specific to Wsse authentication and is only used to help this example
 *
 * For more information specific to the logic here, see
 * https://github.com/symfony/symfony-docs/pull/3134#issuecomment-27699129
 */
protected function validateDigest($digest, $nonce, $created, $secret)
{
    // Check created time is not in the future
    if (strtotime($created) > time()) {
        return false;
    }

    // Expire timestamp after 5 minutes
    if (time() - strtotime($created) > 300) {
        return false;
    }

    // Validate that the nonce is *not* used in the last 5 minutes
    // if it has, this could be a replay attack
    if (file_exists($this->cacheDir.'/'.$nonce) && file_get_contents($this->cacheDir.'/'.$nonce) + 300 > time()) {
        throw new NonceExpiredException('Previously used nonce detected');
    }
    // If cache directory does not exist we create it
    if (!is_dir($this->cacheDir)) {
        mkdir($this->cacheDir, 0777, true);
    }
    file_put_contents($this->cacheDir.'/'.$nonce, time());

    // Validate Secret
   // $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true));

    //return $digest === $expected;

    $username = $this->extractUsername($token->getUsername());
    $domain   = $this->extractDomain($token->getUsername());

    $response = $this->userManagement->authenticate($username,$token->getCredentials(),$domain);

    return 200 == $response[$status];

}

public function supports(TokenInterface $token)
{
    return $token instanceof WsseUserToken;
}
}

Symfony で私のセキュリティ、yml を次のように設定して、カスタム プロバイダーを使用させようとしています:

    firewalls:
        wsse_secured:
            pattern: ^/

            provider: user_provider
            wsse: true
            form_login:
                login_path: /login
                check_path: /login_check
            anonymous: ~

ユーザー プロバイダーは、ドキュメントに従って作成したカスタム ユーザー プロバイダーです。その周りに単体テストを作成しましたが、うまくいくようです...

'wsse: true' という行を削除すると、Symfony2 はそのエラー メッセージなしで動作しますが、単純に標準の認証を使用します...

このチケットが少し厄介であることはわかっていますが、彼の問題をどこから始めればよいかわかりません。

何が問題なのかわからない場合は、お知らせください。

ウーヴェ

4

0 に答える 0