vendor/lightsaml2/sp-bundle/src/LightSaml/SpBundle/Security/Firewall/LightSamlSpListener.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the LightSAML SP-Bundle package.
  4.  *
  5.  * (c) Milos Tomic <tmilos@lightsaml.com>
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace LightSaml\SpBundle\Security\Firewall;
  11. use LightSaml\Builder\Profile\ProfileBuilderInterface;
  12. use LightSaml\Model\Protocol\Response;
  13. use LightSaml\SpBundle\Security\Authentication\Token\SamlSpResponseToken;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  16. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  17. use Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener;
  18. class LightSamlSpListener extends AbstractAuthenticationListener
  19. {
  20.     /** @var ProfileBuilderInterface */
  21.     private $profile;
  22.     /**
  23.      * @return LightSamlSpListener
  24.      */
  25.     public function setProfile(ProfileBuilderInterface $profile)
  26.     {
  27.         $this->profile $profile;
  28.         return $this;
  29.     }
  30.     /**
  31.      * Performs authentication.
  32.      *
  33.      * @param Request $request A Request instance
  34.      *
  35.      * @return TokenInterface|Response|null The authenticated token, null if full authentication is not possible, or a Response
  36.      *
  37.      * @throws AuthenticationException if the authentication fails
  38.      */
  39.     protected function attemptAuthentication(Request $request)
  40.     {
  41.         $samlResponse $this->receiveSamlResponse();
  42.         $token = new SamlSpResponseToken($samlResponse$this->providerKey);
  43.         $token $this->authenticationManager->authenticate($token);
  44.         return $token;
  45.     }
  46.     /**
  47.      * @return \LightSaml\Model\Protocol\Response
  48.      */
  49.     private function receiveSamlResponse()
  50.     {
  51.         $context $this->profile->buildContext();
  52.         $action $this->profile->buildAction();
  53.         $action->execute($context);
  54.         return $context->getInboundMessage();
  55.     }
  56. }