/**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     /**  @var OrganizationContextTokenInterface $token */
     $rememberMeToken = parent::authenticate($token);
     $this->checkUserOrganization($rememberMeToken->getUser(), $token->getOrganizationContext());
     $authenticatedToken = new OrganizationRememberMeToken($rememberMeToken->getUser(), $rememberMeToken->getProviderKey(), $rememberMeToken->getKey(), $token->getOrganizationContext());
     return $authenticatedToken;
 }
 /**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     $guesser = new UserOrganizationGuesser();
     /**  @var TokenInterface $token */
     $authenticatedToken = parent::authenticate($token);
     /** @var User $user */
     $user = $authenticatedToken->getUser();
     $organization = $guesser->guess($user, $token);
     if (!$organization) {
         throw new BadCredentialsException("You don't have active organization assigned.");
     } elseif (!$user->getOrganizations(true)->contains($organization)) {
         throw new BadCredentialsException(sprintf("You don't have access to organization '%s'", $organization->getName()));
     }
     $authenticatedToken = new OrganizationRememberMeToken($user, $authenticatedToken->getProviderKey(), $authenticatedToken->getKey(), $organization);
     return $authenticatedToken;
 }