Skip to content

Commit 91f36a5

Browse files
authored
Merge pull request #1 from pasxel/symfony5
Add support Symfony 5 for controller
2 parents b73d6b9 + dca4f42 commit 91f36a5

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/LightSaml/SpBundle/Controller/DefaultController.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,39 @@
1111

1212
namespace LightSaml\SpBundle\Controller;
1313

14-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
14+
use LightSaml\Builder\Profile\Metadata\MetadataProfileBuilder;
15+
use LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpSendAuthnRequestProfileBuilderFactory;
16+
use LightSaml\SymfonyBridgeBundle\Bridge\Container\PartyContainer;
17+
use LightSaml\SymfonyBridgeBundle\Bridge\Container\StoreContainer;
18+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1519
use Symfony\Component\HttpFoundation\Request;
1620

17-
class DefaultController extends Controller
21+
class DefaultController extends AbstractController
1822
{
23+
private MetadataProfileBuilder $metadataProfileBuilder;
24+
private SsoSpSendAuthnRequestProfileBuilderFactory $profileLoginFactory;
25+
private StoreContainer $storeContainer;
26+
private PartyContainer $partyContainer;
27+
private string $discoveryRoute;
28+
29+
public function __construct(
30+
MetadataProfileBuilder $metadataProfileBuilder,
31+
SsoSpSendAuthnRequestProfileBuilderFactory $profileLoginFactory,
32+
StoreContainer $storeContainer,
33+
PartyContainer $partyContainer,
34+
string $discoveryRoute
35+
) {
36+
$this->metadataProfileBuilder = $metadataProfileBuilder;
37+
$this->profileLoginFactory = $profileLoginFactory;
38+
$this->storeContainer = $storeContainer;
39+
$this->discoveryRoute = $discoveryRoute;
40+
$this->partyContainer = $partyContainer;
41+
}
42+
1943
public function metadataAction()
2044
{
21-
$profile = $this->get('ligthsaml.profile.metadata');
22-
$context = $profile->buildContext();
23-
$action = $profile->buildAction();
45+
$context = $this->metadataProfileBuilder->buildContext();
46+
$action = $this->metadataProfileBuilder->buildAction();
2447

2548
$action->execute($context);
2649

@@ -29,7 +52,7 @@ public function metadataAction()
2952

3053
public function discoveryAction()
3154
{
32-
$parties = $this->get('lightsaml.container.build')->getPartyContainer()->getIdpEntityDescriptorStore()->all();
55+
$parties = $this->partyContainer->getIdpEntityDescriptorStore()->all();
3356

3457
if (1 == count($parties)) {
3558
return $this->redirect($this->generateUrl('lightsaml_sp.login', ['idp' => $parties[0]->getEntityID()]));
@@ -44,10 +67,10 @@ public function loginAction(Request $request)
4467
{
4568
$idpEntityId = $request->get('idp');
4669
if (null === $idpEntityId) {
47-
return $this->redirect($this->generateUrl($this->container->getParameter('lightsaml_sp.route.discovery')));
70+
return $this->redirect($this->generateUrl($this->discoveryRoute));
4871
}
4972

50-
$profile = $this->get('ligthsaml.profile.login_factory')->get($idpEntityId);
73+
$profile = $this->profileLoginFactory->get($idpEntityId);
5174
$context = $profile->buildContext();
5275
$action = $profile->buildAction();
5376

@@ -58,7 +81,7 @@ public function loginAction(Request $request)
5881

5982
public function sessionsAction()
6083
{
61-
$ssoState = $this->get('lightsaml.container.build')->getStoreContainer()->getSsoStateStore()->get();
84+
$ssoState = $this->storeContainer->getSsoStateStore()->get();
6285

6386
return $this->render('@LightSamlSp/sessions.html.twig', [
6487
'sessions' => $ssoState->getSsoSessions(),

src/LightSaml/SpBundle/Resources/config/services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ parameters:
33
lightsaml.route.login_check: lightsaml_sp.login_check
44

55
services:
6+
LightSaml\SpBundle\Controller\DefaultController:
7+
public: true
8+
tags: [ 'controller.service_arguments' ]
9+
arguments:
10+
$discoveryRoute: "%lightsaml_sp.route.discovery%"
11+
612
lightsaml_sp.username_mapper.simple:
713
class: LightSaml\SpBundle\Security\User\SimpleUsernameMapper
814
arguments:

0 commit comments

Comments
 (0)