Skip to content

Commit

Permalink
Intantiate classes after we finalize the casconfig overrides. Refacto…
Browse files Browse the repository at this point in the history
…r checkServiceUrl.Improve composer validate.
  • Loading branch information
ioigoume committed Jan 2, 2025
1 parent a1780a8 commit c56cac3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"require": {
"php": "^8.1",
"ext-ctype": "*",
"ext-dom": "*",
"ext-filter": "*",
"ext-libxml": "*",
Expand All @@ -54,7 +53,8 @@
"psalm/plugin-phpunit": "^0.19.0",
"squizlabs/php_codesniffer": "^3.7",
"maglnet/composer-require-checker": "4.7.1",
"vimeo/psalm": "^5"
"vimeo/psalm": "^5",
"icanhazstring/composer-unused": "^0.8.11"
},
"support": {
"issues": "https://github.com/simplesamlphp/simplesamlphp-module-casserver/issues",
Expand All @@ -66,7 +66,7 @@
"vendor/bin/phpcs -p",
"vendor/bin/composer-require-checker check composer.json",
"vendor/bin/psalm -c psalm-dev.xml",
"vendor/bin/psalm -c psalm.xml"
"vendor/bin/composer-unused"
],
"tests": [
"vendor/bin/phpunit --no-coverage"
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Cas20Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function proxy(
*/
public function proxyValidate(
Request $request,
#[MapQueryParameter] string $TARGET = null,
#[MapQueryParameter] ?string $TARGET = null,
#[MapQueryParameter] bool $renew = false,
#[MapQueryParameter] ?string $ticket = null,
#[MapQueryParameter] ?string $service = null,
Expand Down
54 changes: 33 additions & 21 deletions src/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class LoginController
* @param Configuration $sspConfig
* @param Configuration|null $casConfig
* @param Simple|null $source
* @param Utils\HTTP|null $httpUtils
* @param Utils\HTTP|null $httpUtils
*
* @throws \Exception
*/
Expand All @@ -89,28 +89,12 @@ public function __construct(
) {
$this->casConfig = ($casConfig === null || $casConfig === $sspConfig)
? Configuration::getConfig('module_casserver.php') : $casConfig;

$this->cas20Protocol = new Cas20($this->casConfig);
$this->authSource = $source ?? new Simple($this->casConfig->getValue('authsource'));
$this->httpUtils = $httpUtils ?? new Utils\HTTP();

$this->serviceValidator = new ServiceValidator($this->casConfig);
/* Instantiate ticket factory */
$this->ticketFactory = new TicketFactory($this->casConfig);
/* Instantiate ticket store */
$ticketStoreConfig = $this->casConfig->getOptionalValue(
'ticketstore',
['class' => 'casserver:FileSystemTicketStore'],
);
$ticketStoreClass = Module::resolveClass($ticketStoreConfig['class'], 'Cas\Ticket');
// Ticket Store
$this->ticketStore = new $ticketStoreClass($this->casConfig);
// Processing Chain Factory
$processingChainFactory = new ProcessingChainFactory($this->casConfig);
// Attribute Extractor
$this->attributeExtractor = new AttributeExtractor($this->casConfig, $processingChainFactory);
// Saml Validate Responsder
$this->samlValidateResponder = new SamlValidateResponder();
// Service Validator needs the generic casserver configuration. We do not need
$this->serviceValidator = new ServiceValidator($this->casConfig);
$this->authSource = $source ?? new Simple($this->casConfig->getValue('authsource'));
$this->httpUtils = $httpUtils ?? new Utils\HTTP();
}

/**
Expand Down Expand Up @@ -148,6 +132,7 @@ public function login(

// Set initial configurations, or fail
$this->handleServiceConfiguration($serviceUrl);
$this->intantiateClassDependencies($this->authSource, $this->httpUtils);
$this->handleScope($scope);
$this->handleLanguage($language);

Expand Down Expand Up @@ -427,4 +412,31 @@ public function getTicketStore(): TicketStore
{
return $this->ticketStore;
}

/**
* @param Simple|null $source
* @param Utils\HTTP|null $httpUtils
*
* @return void
* @throws \Exception
*/
private function intantiateClassDependencies(Simple $source = null, Utils\HTTP $httpUtils = null): void
{
$this->cas20Protocol = new Cas20($this->casConfig);

/* Instantiate ticket factory */
$this->ticketFactory = new TicketFactory($this->casConfig);
/* Instantiate ticket store */
$ticketStoreConfig = $this->casConfig->getOptionalValue(
'ticketstore',
['class' => 'casserver:FileSystemTicketStore'],
);
$ticketStoreClass = Module::resolveClass($ticketStoreConfig['class'], 'Cas\Ticket');
// Ticket Store
$this->ticketStore = new $ticketStoreClass($this->casConfig);
// Processing Chain Factory
$processingChainFactory = new ProcessingChainFactory($this->casConfig);
// Attribute Extractor
$this->attributeExtractor = new AttributeExtractor($this->casConfig, $processingChainFactory);
}
}

0 comments on commit c56cac3

Please sign in to comment.