Skip to content

Commit

Permalink
Merge pull request #1 from pasxel/symfony5
Browse files Browse the repository at this point in the history
Add support Symfony 5 for controller
  • Loading branch information
escopecz committed Nov 24, 2023
2 parents b73d6b9 + dca4f42 commit 91f36a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/LightSaml/SpBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,39 @@

namespace LightSaml\SpBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use LightSaml\Builder\Profile\Metadata\MetadataProfileBuilder;
use LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpSendAuthnRequestProfileBuilderFactory;
use LightSaml\SymfonyBridgeBundle\Bridge\Container\PartyContainer;
use LightSaml\SymfonyBridgeBundle\Bridge\Container\StoreContainer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
class DefaultController extends AbstractController
{
private MetadataProfileBuilder $metadataProfileBuilder;
private SsoSpSendAuthnRequestProfileBuilderFactory $profileLoginFactory;
private StoreContainer $storeContainer;
private PartyContainer $partyContainer;
private string $discoveryRoute;

public function __construct(
MetadataProfileBuilder $metadataProfileBuilder,
SsoSpSendAuthnRequestProfileBuilderFactory $profileLoginFactory,
StoreContainer $storeContainer,
PartyContainer $partyContainer,
string $discoveryRoute
) {
$this->metadataProfileBuilder = $metadataProfileBuilder;
$this->profileLoginFactory = $profileLoginFactory;
$this->storeContainer = $storeContainer;
$this->discoveryRoute = $discoveryRoute;
$this->partyContainer = $partyContainer;
}

public function metadataAction()
{
$profile = $this->get('ligthsaml.profile.metadata');
$context = $profile->buildContext();
$action = $profile->buildAction();
$context = $this->metadataProfileBuilder->buildContext();
$action = $this->metadataProfileBuilder->buildAction();

$action->execute($context);

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

public function discoveryAction()
{
$parties = $this->get('lightsaml.container.build')->getPartyContainer()->getIdpEntityDescriptorStore()->all();
$parties = $this->partyContainer->getIdpEntityDescriptorStore()->all();

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

$profile = $this->get('ligthsaml.profile.login_factory')->get($idpEntityId);
$profile = $this->profileLoginFactory->get($idpEntityId);
$context = $profile->buildContext();
$action = $profile->buildAction();

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

public function sessionsAction()
{
$ssoState = $this->get('lightsaml.container.build')->getStoreContainer()->getSsoStateStore()->get();
$ssoState = $this->storeContainer->getSsoStateStore()->get();

return $this->render('@LightSamlSp/sessions.html.twig', [
'sessions' => $ssoState->getSsoSessions(),
Expand Down
6 changes: 6 additions & 0 deletions src/LightSaml/SpBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ parameters:
lightsaml.route.login_check: lightsaml_sp.login_check

services:
LightSaml\SpBundle\Controller\DefaultController:
public: true
tags: [ 'controller.service_arguments' ]
arguments:
$discoveryRoute: "%lightsaml_sp.route.discovery%"

lightsaml_sp.username_mapper.simple:
class: LightSaml\SpBundle\Security\User\SimpleUsernameMapper
arguments:
Expand Down

0 comments on commit 91f36a5

Please sign in to comment.