예제 #1
0
 function it_returns_null_if_authentication_fails(Identifier $identifier, Caller $caller, Authenticator $authenticator)
 {
     $subject = ['username' => 'john.doe', 'password' => 'secret'];
     $identifier->identify($subject)->willReturn($caller);
     $authenticator->authenticate($subject, $caller)->willReturn(false);
     $this->authenticateAndReturn($subject)->shouldReturn(null);
 }
예제 #2
0
 /**
  * Authenticates a subject and returns the associated caller
  *
  * @param array $subject
  *
  * @return Caller
  */
 public function authenticateAndReturn(array $subject)
 {
     $caller = $this->identifier->identify($subject);
     if ($this->authenticator->authenticate($subject, $caller)) {
         return $caller;
     }
 }
예제 #3
0
 function it_fails_to_log_a_caller_in(LoginTokenIdentifier $identifier, HasLoginToken $caller, Authenticator $authenticator, Session $session)
 {
     $subject = ['username' => 'john.doe', 'password' => 'secret'];
     $caller->getLoginToken()->willReturn(1);
     $identifier->identify($subject)->willReturn($caller);
     $authenticator->authenticate($subject, $caller)->willReturn(false);
     $session->setLoginToken(1)->shouldNotBeCalled();
     $this->login($subject)->shouldReturn(false);
 }
예제 #4
0
 /**
  * Logs a subject in
  *
  * @param array $subject
  */
 public function login(array $subject)
 {
     /** @var HasLoginToken */
     $caller = $this->identifier->identify($subject);
     if ($this->authenticator->authenticate($subject, $caller)) {
         $this->session->setLoginToken($caller->getLoginToken());
         $this->currentCaller = $caller;
         return true;
     }
     return false;
 }