2014-10-15 2 views
1

비밀번호를 사용하지 않고 사용자를 인증하고 싶습니다. 그래서 isValid()은 어떻게 든 setIdentityValue (사용자 이름), setCredentialValue (비밀번호)인증합니다()를 사용하지 않고 true로 설정해야합니다.비밀번호없이 ZF2 인증

사용자 이름/비밀번호없이 성공적으로 인증을 받으려면 어떻게해야합니까?

이상하게 들리지만이 경우 웹 서버는 인증 (SAML)을 처리합니다. 웹 서버가 액세스 권한을 부여하는 모든 사용자는 자동으로 웹 사이트에 액세스해야합니다. ZF 인증이 필요합니다. 사용자 이름/비밀번호로 웹 사이트에 액세스 할 수도 있기 때문입니다.

답변

1

거의 답을주었습니다. 결과은 아래 예제와 같은 배열이어야합니다.

use Zend\Authentication\Adapter\AdapterInterface; 
use Zend\Authentication\Result; 

class NoPasswordAuthAdapter implements AdapterInterface 
{ 
    protected $identity; 

    public function setIdentity($identity) 
    { 
    $this->identity = $identity; 

    return $this; 
    } 

    public function authenticate() 
    { 
    return new Result(
     Result::SUCCESS, 
     $this->identity, 
     array('Authentication successful.') 
    ); 
    } 
}

도움 주셔서 감사합니다.

0

ZF 인증이 시작되면 어댑터에 자격 증명으로 사용자 이름과 암호를 제공해야합니다. 은 나중에 authenticate($adapter)으로 전달되어야합니다. 따라서 자격 증명을 제공하지 않으려면 isValid() == true, 을 설정해야합니다. 모든 사용자 요청 당 DB의 특정 자격 증명을 하드 코딩하여 수동으로 수행해야합니다. 예제를 제공합니다. ZF2 authentication :

use Zend\Authentication\AuthenticationService; 

    // instantiate the authentication service 
    $auth = new AuthenticationService(); 

    // Set up the authentication adapter 
    $authAdapter = new My\Auth\Adapter($username, $password); 

    // Attempt authentication, saving the result 
    $result = $auth->authenticate($authAdapter); 

    if (!$result->isValid()) { 
    // Authentication failed; print the reasons why 
     foreach ($result->getMessages() as $message) { 
     echo "$message\n"; 
     } 
    } else { 
    // Authentication succeeded; the identity ($username) is stored 
    // in the session 
    // $result->getIdentity() === $auth->getIdentity() 
    // $result->getIdentity() === $username 
    } 
2

더미 인증을 수행하기 위해 고유 한 어댑터 클래스를 만들 수 있습니다.

class DummyDBAuthAdapter implements Zend\Authentication\Adapter\AdapterInterface 
{ 
    public function authenticate() 
    { 
     return Zend\Authentication\Result::SUCCESS; 
    } 
} 

따라서 사용자가 SAML로 인증 될 때마다 DB 어댑터에서이 어댑터로 전환 할 수 있습니다.

관련 문제