public function testSendNotification()
 {
     DomainEvents::setEventDispatcher(new EventDispatcher());
     $user = User::fromDTO(new CreateUserDTO('Ma27', 'test-password', '*****@*****.**'));
     $publisher = $this->getMock(BackendInterface::class);
     $publisher->expects($this->once())->method('createAndPublish')->with('sen_mailer', ['override_locale' => true, 'user' => $user, 'content' => 'notification.auth.failures', 'parameters' => ['translation_defaults' => ['%times%' => 2]]]);
     $hook = new AuthenticationReportListener($publisher);
     $entity = new AuthenticationFailure($user);
     $entity->updateReport();
     $entity->updateReport();
     $entityReport = $entity->createReport();
     $event = new AuthenticationAttemptEvent($user);
     $event->setReport($entityReport);
     $hook->onAuthenticationFailure($event);
 }
Ejemplo n.º 2
0
 /**
  * Authenticates the user token
  *
  * @param AuthDTO $credentials
  * @param ApiKeyFactoryInterface $apiKeyGenerator
  *
  * @return Value\ApiKey
  *
  * @throws AuthenticationException If the credentials are invalid
  * @throws AuthenticationException If the user was locked
  * @throws AuthenticationException If the api key generation failed
  */
 public function authenticateToken(AuthDTO $credentials, ApiKeyFactoryInterface $apiKeyGenerator)
 {
     $this->ensureActivated();
     if (!$this->getCredentials()->compare($credentials)) {
         if (null === $this->authenticationFailureReport) {
             $this->authenticationFailureReport = new AuthenticationFailure($this);
         }
         $this->authenticationFailureReport->updateReport();
         throw AuthenticationException::fromCredentialFailure();
     }
     if ($this->getSimpleProfile()->isLocked()) {
         throw AuthenticationException::fromLockedUser();
     }
     if (null === ($token = $this->getToken())) {
         try {
             $token = $apiKeyGenerator->generateKeyCode();
         } catch (\OverflowException $ex) {
             throw AuthenticationException::fromInvalidApiKey();
         }
         $this->token = new Token($token);
     }
     return $this->getToken();
 }