Skip to content

Commit 09cb69f

Browse files
authored
Merge pull request #125 from a-menshchikov/v2_saml-logout_sf5.1
v2: Symfony 5.1, PHP 7.3, PhpUnit 9
2 parents cef2818 + a54f264 commit 09cb69f

16 files changed

Lines changed: 377 additions & 371 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ composer.lock
22
phpunit.xml
33
/vendor/
44
/build/
5+
.phpunit.result.cache

.travis.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
6-
- 7.1
7-
- 7.2
4+
- 7.3
5+
- 7.4
86

97
matrix:
108
fast_finish: true
119
include:
12-
- php: 5.6
13-
env: SYMFONY_VERSION=2.3.*
14-
- php: 5.6
15-
env: SYMFONY_VERSION=2.7.*
16-
- php: 5.6
17-
env: SYMFONY_VERSION=2.8.*
18-
- php: 7.2
19-
env: SYMFONY_VERSION=4.2.*
10+
- php: 7.3
11+
env: SYMFONY_VERSION=5.1.*
12+
- php: 7.4
13+
env: SYMFONY_VERSION=5.1.*
2014

2115
sudo: false
2216

DependencyInjection/Security/Factory/SamlFactory.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
7-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
87
use Symfony\Component\DependencyInjection\ChildDefinition;
98
use Symfony\Component\DependencyInjection\Reference;
109

@@ -18,7 +17,7 @@ public function __construct()
1817
$this->addOption('user_factory');
1918
$this->addOption('token_factory');
2019
$this->addOption('persist_user', false);
21-
20+
2221
if (!isset($this->options['success_handler'])) {
2322
$this->options['success_handler'] = 'hslavich_onelogin_saml.saml_authentication_success_handler';
2423
}
@@ -60,8 +59,7 @@ protected function getListenerId()
6059
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
6160
{
6261
$providerId = 'security.authentication.provider.saml.'.$id;
63-
$definitionClassname = $this->getDefinitionClassname();
64-
$definition = $container->setDefinition($providerId, new $definitionClassname('hslavich_onelogin_saml.saml_provider'))
62+
$definition = $container->setDefinition($providerId, new ChildDefinition('hslavich_onelogin_saml.saml_provider'))
6563
->replaceArgument(0, new Reference($userProviderId))
6664
->addArgument(array(
6765
'persist_user' => $config['persist_user']
@@ -79,44 +77,16 @@ protected function createAuthProvider(ContainerBuilder $container, $id, $config,
7977
return $providerId;
8078
}
8179

82-
protected function createListener($container, $id, $config, $userProvider)
83-
{
84-
$listenerId = parent::createListener($container, $id, $config, $userProvider);
85-
$this->createLogoutHandler($container, $id, $config);
86-
87-
return $listenerId;
88-
}
89-
9080
protected function createEntryPoint($container, $id, $config, $defaultEntryPoint)
9181
{
9282
$entryPointId = 'security.authentication.form_entry_point.'.$id;
93-
$definitionClassname = $this->getDefinitionClassname();
9483
$container
95-
->setDefinition($entryPointId, new $definitionClassname('security.authentication.form_entry_point'))
84+
->setDefinition($entryPointId, new ChildDefinition('security.authentication.form_entry_point'))
9685
->addArgument(new Reference('security.http_utils'))
9786
->addArgument($config['login_path'])
9887
->addArgument($config['use_forward'])
9988
;
10089

10190
return $entryPointId;
10291
}
103-
104-
protected function createLogoutHandler($container, $id, $config)
105-
{
106-
if ($container->hasDefinition('security.logout_listener.'.$id)) {
107-
$logoutListener = $container->getDefinition('security.logout_listener.'.$id);
108-
$samlListenerId = 'hslavich_onelogin_saml.saml_logout';
109-
110-
$definitionClassname = $this->getDefinitionClassname();
111-
$container
112-
->setDefinition($samlListenerId, new $definitionClassname('saml.security.http.logout'))
113-
->replaceArgument(2, array_intersect_key($config, $this->options));
114-
$logoutListener->addMethodCall('addHandler', array(new Reference($samlListenerId)));
115-
}
116-
}
117-
118-
private function getDefinitionClassname()
119-
{
120-
return class_exists(ChildDefinition::class) ? ChildDefinition::class : DefinitionDecorator::class;
121-
}
12292
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hslavich\OneloginSamlBundle\EventListener\Security;
6+
7+
use Hslavich\OneloginSamlBundle\Security\Authentication\Token\SamlTokenInterface;
8+
use Symfony\Component\Security\Http\Event\LogoutEvent;
9+
10+
class SamlLogoutListener
11+
{
12+
protected $samlAuth;
13+
14+
public function __construct(\OneLogin\Saml2\Auth $samlAuth)
15+
{
16+
$this->samlAuth = $samlAuth;
17+
}
18+
19+
public function __invoke(LogoutEvent $event)
20+
{
21+
$token = $event->getToken();
22+
if (!$token instanceof SamlTokenInterface) {
23+
return;
24+
}
25+
26+
try {
27+
$this->samlAuth->processSLO();
28+
} catch (\OneLogin\Saml2\Error $e) {
29+
if (!empty($this->samlAuth->getSLOurl())) {
30+
$sessionIndex = $token->hasAttribute('sessionIndex') ? $token->getAttribute('sessionIndex') : null;
31+
$this->samlAuth->logout(null, array(), $token->getUsername(), $sessionIndex);
32+
}
33+
}
34+
}
35+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OneloginSamlBundle
2-
OneLogin SAML Bundle for Symfony2. (https://github.com/onelogin/php-saml)
2+
OneLogin SAML Bundle for Symfony. (https://github.com/onelogin/php-saml)
33

44
[![Build Status](https://travis-ci.org/hslavich/OneloginSamlBundle.svg?branch=master)](https://travis-ci.org/hslavich/OneloginSamlBundle)
55
[![Coverage Status](https://coveralls.io/repos/github/hslavich/OneloginSamlBundle/badge.svg?branch=master)](https://coveralls.io/github/hslavich/OneloginSamlBundle?branch=master)

Resources/config/services.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ services:
2727
calls:
2828
- [setOneLoginAuth, ["@onelogin_auth"]]
2929

30-
hslavich_onelogin_saml.saml_logout:
31-
class: Hslavich\OneloginSamlBundle\Security\Logout\SamlLogoutHandler
30+
hslavich_onelogin_saml.saml_logout_listener:
31+
class: Hslavich\OneloginSamlBundle\EventListener\Security\SamlLogoutListener
3232
arguments:
3333
- "@onelogin_auth"
34+
tags:
35+
- name: kernel.event_listener
36+
event: Symfony\Component\Security\Http\Event\LogoutEvent

Security/Logout/SamlLogoutHandler.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)