Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 26, 2022
1 parent 25f9d77 commit 74015e2
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 2 deletions.
151 changes: 151 additions & 0 deletions src/Cas/SymfonyECas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace EcPhp\EuLoginBundle\Cas;

use EcPhp\CasBundle\Cas\SymfonyCasInterface;
use EcPhp\CasLib\Contract\CasInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
use Symfony\Component\HttpFoundation\Request;

final class SymfonyECas implements SymfonyCasInterface
{
private CasInterface $cas;

private HttpMessageFactoryInterface $httpMessageFactory;

public function __construct(
CasInterface $cas,
HttpMessageFactoryInterface $httpMessageFactory
) {
$this->cas = $cas;
$this->httpMessageFactory = $httpMessageFactory;
}

public function authenticate(
ServerRequestInterface|Request $request,
array $parameters = []
): array {
return $this
->cas
->authenticate(
$this->updateRequest($request),
$parameters
);
}

public function handleProxyCallback(
ServerRequestInterface|Request $request,
array $parameters = []
): ResponseInterface {
return $this
->cas
->handleProxyCallback(
$this->updateRequest($request),
$parameters
);
}

public function login(
ServerRequestInterface|Request $request,
array $parameters = []
): ResponseInterface {
return $this
->cas
->login(
$this->updateRequest($request),
$parameters
);
}

public function logout(
ServerRequestInterface|Request $request,
array $parameters = []
): ResponseInterface {
return $this
->cas
->logout(
$this->updateRequest($request),
$parameters
);
}

public function process(
ServerRequestInterface|Request $request,
RequestHandlerInterface $handler
): ResponseInterface {
return $this
->cas
->process(
$this->updateRequest($request),
$handler
);
}

public function requestProxyTicket(
ServerRequestInterface|Request $request,
array $parameters = []
): ResponseInterface {
return $this
->cas
->requestProxyTicket(
$this->updateRequest($request),
$parameters
);
}

public function requestServiceValidate(
ServerRequestInterface|Request $request,
array $parameters = []
): ResponseInterface {
return $this
->cas
->requestServiceValidate(
$this->updateRequest($request),
$parameters
);
}

public function requestTicketValidation(
ServerRequestInterface|Request $request,
array $parameters = []
): ResponseInterface {
return $this
->cas
->requestTicketValidation(
$this->updateRequest($request),
$parameters
);
}

public function supportAuthentication(
ServerRequestInterface|Request $request,
array $parameters = []
): bool {
return $this
->cas
->supportAuthentication(
$this->updateRequest($request),
$parameters
);
}

private function updateRequest(
ServerRequestInterface|Request $request
): ServerRequestInterface {
return $request instanceof Request
? $this->httpMessageFactory->createRequest($request)
: $request;
}
}
4 changes: 2 additions & 2 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use EcPhp\CasBundle\Cas\SymfonyCasInterface;
use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface;
use EcPhp\CasLib\Contract\Configuration\PropertiesInterface;
use EcPhp\Ecas\Ecas;
use EcPhp\Ecas\EcasProperties;
use EcPhp\EuLoginBundle\Cas\SymfonyECas;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider;

return static function (ContainerConfigurator $container) {
Expand All @@ -37,7 +37,7 @@
->arg('$casProperties', service('.inner'));

$services
->set(Ecas::class)
->set(SymfonyECas::class)
->decorate(SymfonyCasInterface::class)
->arg('$cas', service('.inner'));
};

0 comments on commit 74015e2

Please sign in to comment.