From a911fa7e618e5f68bd9c1789848b50f3b53e8950 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 15 Nov 2024 13:29:25 +0200 Subject: [PATCH] Review changes. --- composer.json | 11 ++++++++- public/login.php | 26 +++++--------------- src/Cas/AttributeExtractor.php | 2 +- src/Cas/Factories/ProcessingChainFactory.php | 13 ++-------- src/Cas/Protocol/SamlValidateResponder.php | 8 +++--- tests/config/jwks-cert.pem | 12 --------- tests/config/jwks-key.pem | 10 -------- tests/src/Cas/Protocol/SamlValidateTest.php | 2 +- 8 files changed, 24 insertions(+), 60 deletions(-) delete mode 100644 tests/config/jwks-cert.pem delete mode 100644 tests/config/jwks-key.pem diff --git a/composer.json b/composer.json index 6c769fe..6d347e2 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "simplesamlphp/composer-module-installer": "^1.3", "simplesamlphp/simplesamlphp": "^2.2", "simplesamlphp/xml-cas": "^v1.3", - "simplesamlphp/xml-common": "^v1.18", + "simplesamlphp/xml-common": "^v1.17", "simplesamlphp/xml-soap": "^v1.5" }, "require-dev": { @@ -54,5 +54,14 @@ }, "suggest": { "ext-pdo": "*" + }, + "scripts": { + "validate": [ + "vendor/bin/phpunit --no-coverage --testdox", + "vendor/bin/phpcs -p" + ], + "tests": [ + "vendor/bin/phpunit --no-coverage" + ] } } diff --git a/public/login.php b/public/login.php index 8cda8c8..5b9798a 100644 --- a/public/login.php +++ b/public/login.php @@ -183,25 +183,16 @@ // Get the state. // If we come from an authproc filter, we will load the state from the stateId. // If not, we will get the state from the AuthSource Data -try { - $state = $authProcId !== null ? - $attributeExtractor->manageState($authProcId) : - $as->getAuthDataArray(); -} catch (\SimpleSAML\Error\NoState $e) { - var_export($e, true); - die(); -} +$state = $authProcId !== null ? + $attributeExtractor->manageState($authProcId) : + $as->getAuthDataArray(); + // Attribute Handler $state['ReturnTo'] = $returnUrl; if ($authProcId !== null) { $state[ProcessingChain::AUTHPARAM] = $authProcId; } -try { - $mappedAttributes = $attributeExtractor->extractUserAndAttributes($state); -} catch (\SimpleSAML\Error\Exception $e) { - var_export($e, true); - die(); -} +$mappedAttributes = $attributeExtractor->extractUserAndAttributes($state); $serviceTicket = $ticketFactory->createServiceTicket([ 'service' => $serviceUrl, @@ -245,10 +236,5 @@ $httpUtils->redirectTrustedURL($httpUtils->addURLParameters($serviceUrl, $parameters)); } else { // POST - try { - $httpUtils->submitPOSTData($serviceUrl, $parameters); - } catch (\SimpleSAML\Error\Exception $e) { - var_export($e, true); - die(); - } + $httpUtils->submitPOSTData($serviceUrl, $parameters); } diff --git a/src/Cas/AttributeExtractor.php b/src/Cas/AttributeExtractor.php index 6db73d7..bee5fd4 100644 --- a/src/Cas/AttributeExtractor.php +++ b/src/Cas/AttributeExtractor.php @@ -32,7 +32,7 @@ class AttributeExtractor public function __construct( Configuration $casconfig, - ProcessingChainFactory $processingChainFactory + ProcessingChainFactory $processingChainFactory, ) { $this->casconfig = $casconfig; $this->processingChainFactory = $processingChainFactory; diff --git a/src/Cas/Factories/ProcessingChainFactory.php b/src/Cas/Factories/ProcessingChainFactory.php index 90820a5..6b92e5a 100644 --- a/src/Cas/Factories/ProcessingChainFactory.php +++ b/src/Cas/Factories/ProcessingChainFactory.php @@ -31,18 +31,9 @@ public function __construct( */ public function build(array $state): ProcessingChain { - $idpMetadata = [ - 'entityid' => $state['Source']['entityid'] ?? '', - // ProcessChain needs to know the list of authproc filters we defined in casserver configuration - 'authproc' => $this->casconfig->getOptionalArray('authproc', []), - ]; - $spMetadata = [ - 'entityid' => $state['Destination']['entityid'] ?? '', - ]; - return new ProcessingChain( - $idpMetadata, - $spMetadata, + $state['Source'], + $state['Destination'], 'casserver', ); } diff --git a/src/Cas/Protocol/SamlValidateResponder.php b/src/Cas/Protocol/SamlValidateResponder.php index dcc82b4..0ce7115 100644 --- a/src/Cas/Protocol/SamlValidateResponder.php +++ b/src/Cas/Protocol/SamlValidateResponder.php @@ -6,8 +6,8 @@ use SimpleSAML\Configuration; use SimpleSAML\Module\casserver\Shib13\AuthnResponse; -use SimpleSAML\SOAP\XML\env_200305\Body; -use SimpleSAML\SOAP\XML\env_200305\Envelope; +use SimpleSAML\SOAP\XML\env_200106\Body; +use SimpleSAML\SOAP\XML\env_200106\Envelope; use SimpleSAML\XML\Chunk; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\SerializableElementInterface; @@ -64,11 +64,11 @@ public function convertToSaml(array $ticket): Chunk /** * @param \SimpleSAML\XML\SerializableElementInterface $samlResponse - * @return \SimpleSAML\SOAP\XML\env\Envelope + * @return \SimpleSAML\SOAP\XML\env_200106\Envelope */ public function wrapInSoap(SerializableElementInterface $samlResponse): Envelope { - $body = new Body(null, [$samlResponse]); + $body = new Body([$samlResponse]); return new Envelope($body); } } diff --git a/tests/config/jwks-cert.pem b/tests/config/jwks-cert.pem deleted file mode 100644 index 1d37f73..0000000 --- a/tests/config/jwks-cert.pem +++ /dev/null @@ -1,12 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIBxTCCAW+gAwIBAgIUF6cgHno1ftvK5NSTMgKzb+N/9cUwDQYJKoZIhvcNAQEL -BQAwNzELMAkGA1UEBhMCTk8xEzARBgNVBAgMClNvbWUtU3RhdGUxEzARBgNVBAoM -ClNpbXBsZVNBTUwwHhcNMTkwODIzMTMxODAzWhcNMjkwODIwMTMxODAzWjA3MQsw -CQYDVQQGEwJOTzETMBEGA1UECAwKU29tZS1TdGF0ZTETMBEGA1UECgwKU2ltcGxl -U0FNTDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDDblC3zTyaroUJr2vVcxsXRrI4 -X1KWpOewfI8qdVCK1efXcjJO/lStq0l3rPHzX2g6VIFKS897E4thBdqbRYHPAgMB -AAGjUzBRMB0GA1UdDgQWBBSle2ndlvLV99q5YZGROsv+MEIjATAfBgNVHSMEGDAW -gBSle2ndlvLV99q5YZGROsv+MEIjATAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3 -DQEBCwUAA0EACx6Z1TGX74wL65mvOEqz3BurPqQlPp7q4bywm3GtMZY7xU/vpyiD -ldRq83U+KnyEmQ9IrrzYXs8ReQ3GSY7q/g== ------END CERTIFICATE----- diff --git a/tests/config/jwks-key.pem b/tests/config/jwks-key.pem deleted file mode 100644 index 304d6aa..0000000 --- a/tests/config/jwks-key.pem +++ /dev/null @@ -1,10 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAw25Qt808mq6FCa9r -1XMbF0ayOF9SlqTnsHyPKnVQitXn13IyTv5UratJd6zx819oOlSBSkvPexOLYQXa -m0WBzwIDAQABAkBwaAAXZ/3mvmCY7IQqlnVLkwcpM3KuYRU+RraV5jo4T8Nq+Nm8 -Cs9ywc3aurepFf72XySwmx6C8/8s63H0WZRhAiEA+y8Noq39K6k1N9j5tSleMH1H -5VHv1zNtbGBL3MfwJjECIQDHLZi4eskwei5Hs98njAyx3WcMnPugfo9xo/yFO54n -/wIhAMkGdWE24iFpQGA71Ez6mJkyCrIrC0otrGtJ/izqDvZhAiAXrNXQZ9fuSTej -EkBeRQllQvnyx94pD6IhUeq8M3/zJQIhAJep7ljBTshymiQleAinU/R5w2y08T63 -QtCUAe5Q1aDW ------END PRIVATE KEY----- diff --git a/tests/src/Cas/Protocol/SamlValidateTest.php b/tests/src/Cas/Protocol/SamlValidateTest.php index 0b51ec5..217dc20 100644 --- a/tests/src/Cas/Protocol/SamlValidateTest.php +++ b/tests/src/Cas/Protocol/SamlValidateTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use SimpleSAML\Module\casserver\Cas\Protocol\SamlValidateResponder; -use SimpleSAML\SOAP\XML\env_200305\Envelope; +use SimpleSAML\SOAP\XML\env_200106\Envelope; class SamlValidateTest extends TestCase {