1111
1212namespace LightSaml \SpBundle \Security \Firewall ;
1313
14+ use LightSaml \Binding \AbstractBinding ;
15+ use LightSaml \Binding \BindingFactory ;
1416use LightSaml \Builder \Profile \ProfileBuilderInterface ;
17+ use LightSaml \Context \Profile \MessageContext ;
18+ use LightSaml \Model \Protocol \LogoutResponse ;
1519use LightSaml \Model \Protocol \Response ;
20+ use LightSaml \SamlConstants ;
1621use LightSaml \SpBundle \Security \Authentication \Token \SamlSpResponseToken ;
1722use Symfony \Component \HttpFoundation \Request ;
1823use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
@@ -24,6 +29,9 @@ class LightSamlSpListener extends AbstractAuthenticationListener
2429 /** @var ProfileBuilderInterface */
2530 private $ profile ;
2631
32+ /** @var BindingFactory */
33+ private $ bindingFactory ;
34+
2735 /**
2836 * @param ProfileBuilderInterface $profile
2937 *
@@ -36,6 +44,18 @@ public function setProfile(ProfileBuilderInterface $profile)
3644 return $ this ;
3745 }
3846
47+ /**
48+ * @param BindingFactory $bindingFactory
49+ *
50+ * @return LightSamlSpListener
51+ */
52+ public function setBindingFactory (BindingFactory $ bindingFactory )
53+ {
54+ $ this ->bindingFactory = $ bindingFactory ;
55+
56+ return $ this ;
57+ }
58+
3959 /**
4060 * Performs authentication.
4161 *
@@ -47,6 +67,29 @@ public function setProfile(ProfileBuilderInterface $profile)
4767 */
4868 protected function attemptAuthentication (Request $ request )
4969 {
70+ $ bindingType = $ this ->bindingFactory ->detectBindingType ($ request );
71+
72+ if (null === $ bindingType ) {
73+ throw new \LogicException ('No SAML response. ' );
74+ }
75+
76+ $ binding = $ this ->bindingFactory ->create ($ bindingType );
77+ $ messageContext = new MessageContext ();
78+ /* @var $binding AbstractBinding */
79+ $ binding ->receive ($ request , $ messageContext );
80+ $ samlRequest = $ messageContext ->getMessage ();
81+
82+ if ($ samlRequest instanceof LogoutResponse) {
83+ $ status = $ samlRequest ->getStatus ();
84+ $ code = $ status ->getStatusCode () ? $ status ->getStatusCode ()->getValue () : null ;
85+
86+ if (SamlConstants::STATUS_PARTIAL_LOGOUT === $ code || SamlConstants::STATUS_SUCCESS === $ code ) {
87+ $ request ->getSession ()->invalidate ();
88+ }
89+
90+ throw new AuthenticationException ('This is a logout response ' );
91+ }
92+
5093 $ samlResponse = $ this ->receiveSamlResponse ();
5194
5295 $ token = new SamlSpResponseToken ($ samlResponse , $ this ->providerKey );
0 commit comments