From 3eb8ec01663a9f6b0f4138a75396c12ea9a21fd2 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tim.dijen@minbzk.nl> Date: Sat, 13 Jun 2020 15:43:06 +0200 Subject: [PATCH] Migrate Assertions to wrapper class (#1339) Convert to our wrapper class for assertions --- composer.json | 4 +- composer.lock | 55 +++++++++++- lib/SimpleSAML/Auth/ProcessingChain.php | 2 +- lib/SimpleSAML/Auth/ProcessingFilter.php | 2 +- lib/SimpleSAML/Auth/Simple.php | 2 +- lib/SimpleSAML/Auth/Source.php | 2 +- lib/SimpleSAML/Auth/State.php | 2 +- lib/SimpleSAML/Configuration.php | 2 +- lib/SimpleSAML/Error/Assertion.php | 2 +- lib/SimpleSAML/Error/AuthSource.php | 2 +- lib/SimpleSAML/Error/BadRequest.php | 2 +- lib/SimpleSAML/Error/Error.php | 2 +- lib/SimpleSAML/Error/Exception.php | 2 +- lib/SimpleSAML/Error/MetadataNotFound.php | 2 +- lib/SimpleSAML/Error/NotFound.php | 2 +- lib/SimpleSAML/IdP.php | 2 +- lib/SimpleSAML/IdP/IFrameLogoutHandler.php | 2 +- .../IdP/TraditionalLogoutHandler.php | 2 +- lib/SimpleSAML/Locale/Language.php | 2 +- lib/SimpleSAML/Locale/Translate.php | 2 +- lib/SimpleSAML/Logger.php | 2 +- .../Metadata/MetaDataStorageHandler.php | 4 +- .../MetaDataStorageHandlerFlatFile.php | 2 +- .../Metadata/MetaDataStorageHandlerPdo.php | 2 +- .../MetaDataStorageHandlerSerialize.php | 2 +- .../Metadata/MetaDataStorageSource.php | 2 +- lib/SimpleSAML/Metadata/SAMLBuilder.php | 2 +- lib/SimpleSAML/Metadata/SAMLParser.php | 2 +- lib/SimpleSAML/Metadata/Sources/MDQ.php | 2 +- lib/SimpleSAML/Module.php | 2 +- lib/SimpleSAML/Session.php | 5 +- lib/SimpleSAML/SessionHandlerCookie.php | 2 +- lib/SimpleSAML/SessionHandlerPHP.php | 2 +- lib/SimpleSAML/SessionHandlerStore.php | 2 +- lib/SimpleSAML/Stats.php | 2 +- lib/SimpleSAML/Store/Memcache.php | 2 +- lib/SimpleSAML/Store/Redis.php | 2 +- lib/SimpleSAML/Store/SQL.php | 2 +- lib/SimpleSAML/Utils/Crypto.php | 2 +- lib/SimpleSAML/Utils/EMail.php | 2 +- lib/SimpleSAML/Utils/XML.php | 2 +- lib/SimpleSAML/XHTML/IdPDisco.php | 2 +- lib/SimpleSAML/XHTML/Template.php | 2 +- lib/SimpleSAML/XML/Errors.php | 2 +- lib/SimpleSAML/XML/Signer.php | 2 +- lib/SimpleSAML/XML/Validator.php | 2 +- modules/admin/lib/Controller/Federation.php | 2 +- modules/admin/lib/Controller/Menu.php | 2 +- modules/admin/lib/Controller/Test.php | 2 +- modules/core/hooks/hook_sanitycheck.php | 10 ++- .../core/lib/Auth/Process/AttributeAdd.php | 10 ++- .../core/lib/Auth/Process/AttributeAlter.php | 5 +- .../core/lib/Auth/Process/AttributeCopy.php | 10 ++- .../core/lib/Auth/Process/AttributeLimit.php | 5 +- .../core/lib/Auth/Process/AttributeMap.php | 16 ++-- .../lib/Auth/Process/AttributeValueMap.php | 5 +- modules/core/lib/Auth/Process/Cardinality.php | 4 +- .../lib/Auth/Process/CardinalitySingle.php | 4 +- .../lib/Auth/Process/ExtendIdPSession.php | 5 +- .../core/lib/Auth/Process/GenerateGroups.php | 8 +- .../core/lib/Auth/Process/LanguageAdaptor.php | 5 +- modules/core/lib/Auth/Process/PHP.php | 7 +- .../core/lib/Auth/Process/ScopeAttribute.php | 5 +- .../lib/Auth/Process/ScopeFromAttribute.php | 5 +- .../Auth/Process/StatisticsWithAttribute.php | 10 ++- modules/core/lib/Auth/Process/TargetedID.php | 14 +-- .../lib/Auth/Process/WarnShortSSOInterval.php | 4 +- .../core/lib/Auth/Source/AdminPassword.php | 5 +- modules/core/lib/Auth/UserPassBase.php | 4 +- modules/core/lib/Auth/UserPassOrgBase.php | 4 +- modules/core/lib/Controller/Login.php | 2 +- modules/core/lib/Controller/Redirection.php | 2 +- modules/core/lib/Stats/Output/File.php | 2 +- modules/core/www/postredirect.php | 28 +++--- modules/cron/hooks/hook_configpage.php | 10 ++- modules/cron/hooks/hook_cron.php | 5 +- modules/cron/hooks/hook_frontpage.php | 5 +- modules/cron/lib/Cron.php | 5 +- .../lib/Auth/Process/RedirectTest.php | 2 +- .../exampleauth/lib/Auth/Source/External.php | 4 +- .../lib/Auth/Source/StaticSource.php | 10 ++- .../exampleauth/lib/Auth/Source/UserPass.php | 14 +-- .../multiauth/lib/Auth/Source/MultiAuth.php | 15 ++-- modules/saml/hooks/hook_metadata_hosted.php | 5 +- .../saml/lib/Auth/Process/AttributeNameID.php | 5 +- .../lib/Auth/Process/AuthnContextClassRef.php | 7 +- .../Process/ExpectedAuthnContextClassRef.php | 5 +- .../saml/lib/Auth/Process/FilterScopes.php | 5 +- .../saml/lib/Auth/Process/NameIDAttribute.php | 5 +- .../lib/Auth/Process/PersistentNameID.php | 5 +- .../Process/PersistentNameID2TargetedID.php | 7 +- .../lib/Auth/Process/SQLPersistentNameID.php | 5 +- .../saml/lib/Auth/Process/TransientNameID.php | 5 +- modules/saml/lib/Auth/Source/SP.php | 2 +- modules/saml/lib/BaseNameIDGenerator.php | 2 +- modules/saml/lib/Error.php | 2 +- modules/saml/lib/IdP/SAML2.php | 2 +- modules/saml/lib/IdP/SQLNameID.php | 2 +- modules/saml/lib/Message.php | 2 +- modules/saml/lib/SP/LogoutStore.php | 2 +- modules/saml/www/sp/discoresp.php | 14 +-- modules/saml/www/sp/metadata.php | 82 ++++++++++-------- modules/saml/www/sp/saml2-acs.php | 69 ++++++++------- modules/saml/www/sp/saml2-logout.php | 85 +++++++++++-------- .../www/sp/wrong_authncontextclassref.php | 7 +- tests/lib/SimpleSAML/Utils/HTTPTest.php | 1 - www/saml2/idp/ArtifactResolutionService.php | 33 ++++--- www/saml2/idp/SSOService.php | 20 +++-- www/saml2/idp/SingleLogoutService.php | 23 +++-- www/saml2/idp/initSLO.php | 17 ++-- www/saml2/idp/metadata.php | 2 +- 111 files changed, 497 insertions(+), 331 deletions(-) diff --git a/composer.json b/composer.json index 154d8568d..aa32bf7b3 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "ext-mbstring": "*", "gettext/gettext": "^4.6", "phpmailer/phpmailer": "^6.1", + "simplesamlphp/assert": "0.0.10", "simplesamlphp/saml2": "^4.1", "simplesamlphp/twig-configurable-i18n": "^2.1", "symfony/cache": "^4.0", @@ -57,8 +58,7 @@ "symfony/routing": "^4.0", "symfony/var-exporter": "^5.0", "symfony/yaml": "^4.0", - "twig/twig": "~2.0", - "webmozart/assert": "~1.7" + "twig/twig": "~2.0" }, "require-dev": { "ext-curl": "*", diff --git a/composer.lock b/composer.lock index 39aa366b6..a67174417 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7918f96090daaec62106ab652c53210c", + "content-hash": "aaeb90faf72b11d0e427a3a375364c60", "packages": [ { "name": "gettext/gettext", @@ -377,6 +377,56 @@ ], "time": "2020-04-22T17:19:51+00:00" }, + { + "name": "simplesamlphp/assert", + "version": "v0.0.10", + "source": { + "type": "git", + "url": "https://github.com/simplesamlphp/assert.git", + "reference": "4b002bd83ea15717908c7fb26a23771d62ba41f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/simplesamlphp/assert/zipball/4b002bd83ea15717908c7fb26a23771d62ba41f2", + "reference": "4b002bd83ea15717908c7fb26a23771d62ba41f2", + "shasum": "" + }, + "require": { + "ext-spl": "*", + "php": "^5.6 || ^7.0", + "webmozart/assert": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^8.5", + "sensiolabs/security-checker": "~6.0", + "simplesamlphp/simplesamlphp-test-framework": "^0.1.9", + "squizlabs/php_codesniffer": "~3.5", + "vimeo/psalm": "~3.11" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "v0.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "SimpleSAML\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-or-later" + ], + "authors": [ + { + "name": "Tim van Dijen", + "email": "tvdijen@gmail.com" + } + ], + "description": "A wrapper around webmozart/assert to make it useful beyond checking method arguments", + "time": "2020-06-12T15:40:57+00:00" + }, { "name": "simplesamlphp/saml2", "version": "v4.1.7", @@ -5202,8 +5252,5 @@ "platform-dev": { "ext-curl": "*" }, - "platform-overrides": { - "php": "7.2.31" - }, "plugin-api-version": "1.1.0" } diff --git a/lib/SimpleSAML/Auth/ProcessingChain.php b/lib/SimpleSAML/Auth/ProcessingChain.php index fb7dddee4..a19b4878e 100644 --- a/lib/SimpleSAML/Auth/ProcessingChain.php +++ b/lib/SimpleSAML/Auth/ProcessingChain.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Auth; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Class for implementing authentication processing chains for IdPs. diff --git a/lib/SimpleSAML/Auth/ProcessingFilter.php b/lib/SimpleSAML/Auth/ProcessingFilter.php index 8e0e4db7f..be5c2fc5c 100644 --- a/lib/SimpleSAML/Auth/ProcessingFilter.php +++ b/lib/SimpleSAML/Auth/ProcessingFilter.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Auth; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Base class for authentication processing filters. diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php index 2c14c8ffb..f41e30c4c 100644 --- a/lib/SimpleSAML/Auth/Simple.php +++ b/lib/SimpleSAML/Auth/Simple.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Auth; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Module; use SimpleSAML\Session; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Helper class for simple authentication applications. diff --git a/lib/SimpleSAML/Auth/Source.php b/lib/SimpleSAML/Auth/Source.php index 0e260d277..691d1fcbe 100644 --- a/lib/SimpleSAML/Auth/Source.php +++ b/lib/SimpleSAML/Auth/Source.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace SimpleSAML\Auth; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Session; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * This class defines a base class for authentication source. diff --git a/lib/SimpleSAML/Auth/State.php b/lib/SimpleSAML/Auth/State.php index e06cd88b0..accfc8285 100644 --- a/lib/SimpleSAML/Auth/State.php +++ b/lib/SimpleSAML/Auth/State.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Auth; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Session; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * This is a helper class for saving and loading state information. diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php index fb2008abe..e41303f31 100644 --- a/lib/SimpleSAML/Configuration.php +++ b/lib/SimpleSAML/Configuration.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace SimpleSAML; use SAML2\Constants; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Configuration of SimpleSAMLphp diff --git a/lib/SimpleSAML/Error/Assertion.php b/lib/SimpleSAML/Error/Assertion.php index bf16f5b32..ff957ddd6 100644 --- a/lib/SimpleSAML/Error/Assertion.php +++ b/lib/SimpleSAML/Error/Assertion.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Error; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Class for creating exceptions from assertion failures. diff --git a/lib/SimpleSAML/Error/AuthSource.php b/lib/SimpleSAML/Error/AuthSource.php index b42ab25d0..0824f3e2b 100644 --- a/lib/SimpleSAML/Error/AuthSource.php +++ b/lib/SimpleSAML/Error/AuthSource.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Error; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Baseclass for auth source exceptions. diff --git a/lib/SimpleSAML/Error/BadRequest.php b/lib/SimpleSAML/Error/BadRequest.php index 272cee357..0f50939bf 100644 --- a/lib/SimpleSAML/Error/BadRequest.php +++ b/lib/SimpleSAML/Error/BadRequest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Error; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Exception which will show a 400 Bad Request error page. diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php index 46edc4808..4e69e8e27 100644 --- a/lib/SimpleSAML/Error/Error.php +++ b/lib/SimpleSAML/Error/Error.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Error; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Session; use SimpleSAML\Utils; use SimpleSAML\XHTML\Template; -use Webmozart\Assert\Assert; /** * Class that wraps SimpleSAMLphp errors in exceptions. diff --git a/lib/SimpleSAML/Error/Exception.php b/lib/SimpleSAML/Error/Exception.php index 943e9122f..edf708b16 100644 --- a/lib/SimpleSAML/Error/Exception.php +++ b/lib/SimpleSAML/Error/Exception.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Error; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Base class for SimpleSAMLphp Exceptions diff --git a/lib/SimpleSAML/Error/MetadataNotFound.php b/lib/SimpleSAML/Error/MetadataNotFound.php index fe730ff38..0c1806760 100644 --- a/lib/SimpleSAML/Error/MetadataNotFound.php +++ b/lib/SimpleSAML/Error/MetadataNotFound.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Error; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Error for missing metadata. diff --git a/lib/SimpleSAML/Error/NotFound.php b/lib/SimpleSAML/Error/NotFound.php index 216f007b9..02b65ac32 100644 --- a/lib/SimpleSAML/Error/NotFound.php +++ b/lib/SimpleSAML/Error/NotFound.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Error; +use SimpleSAML\Assert\Assert; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Exception which will show a 404 Not Found error page. diff --git a/lib/SimpleSAML/IdP.php b/lib/SimpleSAML/IdP.php index 430eb37b3..94f767289 100644 --- a/lib/SimpleSAML/IdP.php +++ b/lib/SimpleSAML/IdP.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML; use SAML2\Constants; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\IdP\IFrameLogoutHandler; use SimpleSAML\IdP\LogoutHandlerInterface; @@ -13,7 +14,6 @@ use SimpleSAML\Error; use SimpleSAML\Metadata\MetaDataStorageHandler; use SimpleSAML\Module\saml\Error\NoPassive; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * IdP class. diff --git a/lib/SimpleSAML/IdP/IFrameLogoutHandler.php b/lib/SimpleSAML/IdP/IFrameLogoutHandler.php index 7ec89343f..12d2601cb 100644 --- a/lib/SimpleSAML/IdP/IFrameLogoutHandler.php +++ b/lib/SimpleSAML/IdP/IFrameLogoutHandler.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\IdP; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Error; @@ -11,7 +12,6 @@ use SimpleSAML\IdP; use SimpleSAML\Module; use SimpleSAML\Utils; use SimpleSAML\XHTML\Template; -use Webmozart\Assert\Assert; /** * Class that handles iframe logout. diff --git a/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php b/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php index 9c9705ff7..2a555cdc3 100644 --- a/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php +++ b/lib/SimpleSAML/IdP/TraditionalLogoutHandler.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\IdP; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Error; use SimpleSAML\IdP; use SimpleSAML\Logger; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Class that handles traditional logout. diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php index c457378dd..ac9ae56fc 100644 --- a/lib/SimpleSAML/Locale/Language.php +++ b/lib/SimpleSAML/Locale/Language.php @@ -12,10 +12,10 @@ declare(strict_types=1); namespace SimpleSAML\Locale; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; class Language { diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php index 0d1188c98..107020d0a 100644 --- a/lib/SimpleSAML/Locale/Translate.php +++ b/lib/SimpleSAML/Locale/Translate.php @@ -13,10 +13,10 @@ declare(strict_types=1); namespace SimpleSAML\Locale; use Gettext\BaseTranslator; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Module; -use Webmozart\Assert\Assert; class Translate { diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php index 374b62f2d..10f237837 100644 --- a/lib/SimpleSAML/Logger.php +++ b/lib/SimpleSAML/Logger.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace SimpleSAML; use Exception; +use SimpleSAML\Assert\Assert; use SimpleSAML\Logger\ErrorLogLoggingHandler; use SimpleSAML\Logger\FileLoggingHandler; use SimpleSAML\Logger\LoggingHandlerInterface; use SimpleSAML\Logger\StandardErrorLoggingHandler; use SimpleSAML\Logger\SyslogLoggingHandler; -use Webmozart\Assert\Assert; /** * The main logger class for SimpleSAMLphp. diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php index e4a88e189..b93f8d7b6 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php @@ -6,13 +6,13 @@ namespace SimpleSAML\Metadata; use SAML2\Constants; use SAML2\XML\saml\Issuer; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Utils; use SimpleSAML\Error\MetadataNotFound; use SimpleSAML\Utils\ClearableState; -use Webmozart\Assert\Assert; /** * This file defines a class for metadata handling. @@ -21,7 +21,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class MetaDataStorageHandler implements \SimpleSAML\Utils\ClearableState +class MetaDataStorageHandler implements ClearableState { /** * This static variable contains a reference to the current diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php index 36a1b894b..ed0a4e267 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace SimpleSAML\Metadata; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; -use Webmozart\Assert\Assert; /** * This file defines a flat file metadata source. diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php index 2ab95ddba..7d88000e1 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Metadata; +use SimpleSAML\Assert\Assert; use SimpleSAML\Database; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * Class for handling metadata files stored in a database. diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php index 0a4af9c83..08d75d427 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Metadata; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Class for handling metadata files in serialized format. diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php index 875a488cc..a48191f7e 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Metadata; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * This abstract class defines an interface for metadata storage sources. diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php index 82ea3f891..1ea0a5e12 100644 --- a/lib/SimpleSAML/Metadata/SAMLBuilder.php +++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php @@ -25,11 +25,11 @@ use SAML2\XML\mdui\UIInfo; use SAML2\XML\saml\Attribute; use SAML2\XML\saml\AttributeValue; use SAML2\XML\shibmd\Scope; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Module\adfs\SAML2\XML\fed\SecurityTokenServiceType; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Class for generating SAML 2.0 metadata from SimpleSAMLphp metadata arrays. diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php index f1b0a1c85..61f783e80 100644 --- a/lib/SimpleSAML/Metadata/SAMLParser.php +++ b/lib/SimpleSAML/Metadata/SAMLParser.php @@ -35,9 +35,9 @@ use SAML2\XML\mdui\Logo; use SAML2\XML\mdui\UIInfo; use SAML2\XML\saml\Attribute; use SAML2\XML\shibmd\Scope; +use SimpleSAML\Assert\Assert; use SimpleSAML\Logger; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * This is class for parsing of SAML 2.0 metadata. diff --git a/lib/SimpleSAML/Metadata/Sources/MDQ.php b/lib/SimpleSAML/Metadata/Sources/MDQ.php index 10db837b9..8714d70c5 100644 --- a/lib/SimpleSAML/Metadata/Sources/MDQ.php +++ b/lib/SimpleSAML/Metadata/Sources/MDQ.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace SimpleSAML\Metadata\Sources; use RobRichards\XMLSecLibs\XMLSecurityDSig; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Metadata\SAMLParser; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * This class implements SAML Metadata Query Protocol diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php index 2402f66d6..0851b23ce 100644 --- a/lib/SimpleSAML/Module.php +++ b/lib/SimpleSAML/Module.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML; +use SimpleSAML\Assert\Assert; use SimpleSAML\Kernel; use SimpleSAML\Utils; use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; @@ -13,7 +14,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Webmozart\Assert\Assert; /** * Helper class for accessing information about modules. diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php index 9ec54c936..58081d72b 100644 --- a/lib/SimpleSAML/Session.php +++ b/lib/SimpleSAML/Session.php @@ -5,9 +5,10 @@ declare(strict_types=1); namespace SimpleSAML; use SAML2\XML\saml\AttributeValue; +use Serializable; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * The Session class holds information about a user session, and everything attached to it. @@ -27,7 +28,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class Session implements \Serializable, Utils\ClearableState +class Session implements Serializable, Utils\ClearableState { /** * This is a timeout value for setData, which indicates that the data diff --git a/lib/SimpleSAML/SessionHandlerCookie.php b/lib/SimpleSAML/SessionHandlerCookie.php index ef114976e..7384544c6 100644 --- a/lib/SimpleSAML/SessionHandlerCookie.php +++ b/lib/SimpleSAML/SessionHandlerCookie.php @@ -15,8 +15,8 @@ declare(strict_types=1); namespace SimpleSAML; +use SimpleSAML\Assert\Assert; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; abstract class SessionHandlerCookie extends SessionHandler { diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php index b81b58e45..634435cb5 100644 --- a/lib/SimpleSAML/SessionHandlerPHP.php +++ b/lib/SimpleSAML/SessionHandlerPHP.php @@ -13,9 +13,9 @@ declare(strict_types=1); namespace SimpleSAML; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; class SessionHandlerPHP extends SessionHandler { diff --git a/lib/SimpleSAML/SessionHandlerStore.php b/lib/SimpleSAML/SessionHandlerStore.php index 4c565d7bc..09f08c05d 100644 --- a/lib/SimpleSAML/SessionHandlerStore.php +++ b/lib/SimpleSAML/SessionHandlerStore.php @@ -10,7 +10,7 @@ declare(strict_types=1); namespace SimpleSAML; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; class SessionHandlerStore extends SessionHandlerCookie { diff --git a/lib/SimpleSAML/Stats.php b/lib/SimpleSAML/Stats.php index 252ab2bb8..f50227bbc 100644 --- a/lib/SimpleSAML/Stats.php +++ b/lib/SimpleSAML/Stats.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace SimpleSAML; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Statistics handler class. diff --git a/lib/SimpleSAML/Store/Memcache.php b/lib/SimpleSAML/Store/Memcache.php index cff7bbc94..02049476e 100644 --- a/lib/SimpleSAML/Store/Memcache.php +++ b/lib/SimpleSAML/Store/Memcache.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Store; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Store; -use Webmozart\Assert\Assert; /** * A memcache based data store. diff --git a/lib/SimpleSAML/Store/Redis.php b/lib/SimpleSAML/Store/Redis.php index cb242e3a7..a176c4334 100644 --- a/lib/SimpleSAML/Store/Redis.php +++ b/lib/SimpleSAML/Store/Redis.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace SimpleSAML\Store; use Predis\Client; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Store; -use Webmozart\Assert\Assert; /** * A data store using Redis to keep the data. diff --git a/lib/SimpleSAML/Store/SQL.php b/lib/SimpleSAML/Store/SQL.php index c15cf4804..d6d472677 100644 --- a/lib/SimpleSAML/Store/SQL.php +++ b/lib/SimpleSAML/Store/SQL.php @@ -6,10 +6,10 @@ namespace SimpleSAML\Store; use PDO; use PDOException; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Store; -use Webmozart\Assert\Assert; /** * A data store using a RDBMS to keep the data. diff --git a/lib/SimpleSAML/Utils/Crypto.php b/lib/SimpleSAML/Utils/Crypto.php index 9f104139c..c8089aab5 100644 --- a/lib/SimpleSAML/Utils/Crypto.php +++ b/lib/SimpleSAML/Utils/Crypto.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Utils; +use SimpleSAML\Assert\Assert; use InvalidArgumentException; use SimpleSAML\Configuration; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * A class for cryptography-related functions. diff --git a/lib/SimpleSAML/Utils/EMail.php b/lib/SimpleSAML/Utils/EMail.php index d21c8ded1..b3cc46631 100644 --- a/lib/SimpleSAML/Utils/EMail.php +++ b/lib/SimpleSAML/Utils/EMail.php @@ -5,10 +5,10 @@ declare(strict_types=1); namespace SimpleSAML\Utils; use PHPMailer\PHPMailer\PHPMailer; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\XHTML\Template; -use Webmozart\Assert\Assert; /** * E-mailer class that can generate a formatted e-mail from array diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php index 3822e5fac..b976626b0 100644 --- a/lib/SimpleSAML/Utils/XML.php +++ b/lib/SimpleSAML/Utils/XML.php @@ -16,11 +16,11 @@ use DOMElement; use DOMNode; use DOMText; use SAML2\DOMDocumentFactory; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\XML\Errors; -use Webmozart\Assert\Assert; class XML { diff --git a/lib/SimpleSAML/XHTML/IdPDisco.php b/lib/SimpleSAML/XHTML/IdPDisco.php index 6fa300240..19417c8ab 100644 --- a/lib/SimpleSAML/XHTML/IdPDisco.php +++ b/lib/SimpleSAML/XHTML/IdPDisco.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\XHTML; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Metadata\MetaDataStorageHandler; use SimpleSAML\Session; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * This class implements a generic IdP discovery service, for use in various IdP diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index 41567c5f5..02b663131 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace SimpleSAML\XHTML; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Locale\Language; use SimpleSAML\Locale\Localization; @@ -24,7 +25,6 @@ use Symfony\Component\HttpFoundation\Response; use Twig\Loader\FilesystemLoader; use Twig\TwigFilter; use Twig\TwigFunction; -use Webmozart\Assert\Assert; /** * The content-property is set upstream, but this is not recognized by Psalm diff --git a/lib/SimpleSAML/XML/Errors.php b/lib/SimpleSAML/XML/Errors.php index 5f000349c..c4bf02ec9 100644 --- a/lib/SimpleSAML/XML/Errors.php +++ b/lib/SimpleSAML/XML/Errors.php @@ -15,7 +15,7 @@ declare(strict_types=1); namespace SimpleSAML\XML; use LibXMLError; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; class Errors { diff --git a/lib/SimpleSAML/XML/Signer.php b/lib/SimpleSAML/XML/Signer.php index f4c9716bc..cd08ae2c1 100644 --- a/lib/SimpleSAML/XML/Signer.php +++ b/lib/SimpleSAML/XML/Signer.php @@ -18,8 +18,8 @@ use DOMElement; use DOMText; use RobRichards\XMLSecLibs\XMLSecurityDSig; use RobRichards\XMLSecLibs\XMLSecurityKey; +use SimpleSAML\Assert\Assert; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; class Signer { diff --git a/lib/SimpleSAML/XML/Validator.php b/lib/SimpleSAML/XML/Validator.php index 91cbbe581..793df2b52 100644 --- a/lib/SimpleSAML/XML/Validator.php +++ b/lib/SimpleSAML/XML/Validator.php @@ -15,8 +15,8 @@ use DOMNode; use DOMDocument; use RobRichards\XMLSecLibs\XMLSecEnc; use RobRichards\XMLSecLibs\XMLSecurityDSig; +use SimpleSAML\Assert\Assert; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; class Validator { diff --git a/modules/admin/lib/Controller/Federation.php b/modules/admin/lib/Controller/Federation.php index cd1ed6fde..d0e1ead67 100644 --- a/modules/admin/lib/Controller/Federation.php +++ b/modules/admin/lib/Controller/Federation.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\admin\Controller; use Exception; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\HTTP\RunnableResponse; @@ -24,7 +25,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\VarExporter\VarExporter; -use Webmozart\Assert\Assert; /** * Controller class for the admin module. diff --git a/modules/admin/lib/Controller/Menu.php b/modules/admin/lib/Controller/Menu.php index 4892a1fd7..5b6c44161 100644 --- a/modules/admin/lib/Controller/Menu.php +++ b/modules/admin/lib/Controller/Menu.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\admin\Controller; +use SimpleSAML\Assert\Assert; use SimpleSAML\Locale\Translate; use SimpleSAML\Module; use SimpleSAML\XHTML\Template; -use Webmozart\Assert\Assert; /** * A class to handle the menu in admin pages. diff --git a/modules/admin/lib/Controller/Test.php b/modules/admin/lib/Controller/Test.php index 75dd3d1ce..16ac22719 100644 --- a/modules/admin/lib/Controller/Test.php +++ b/modules/admin/lib/Controller/Test.php @@ -6,6 +6,7 @@ namespace SimpleSAML\Module\admin\Controller; use SAML2\Constants; use SAML2\XML\saml\NameID; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\HTTP\RunnableResponse; @@ -16,7 +17,6 @@ use SimpleSAML\Utils; use SimpleSAML\XHTML\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Webmozart\Assert\Assert; /** * Controller class for the admin module. diff --git a/modules/core/hooks/hook_sanitycheck.php b/modules/core/hooks/hook_sanitycheck.php index d37d6c62b..d51d4db76 100644 --- a/modules/core/hooks/hook_sanitycheck.php +++ b/modules/core/hooks/hook_sanitycheck.php @@ -2,7 +2,9 @@ declare(strict_types=1); -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Configuration; +use SimpleSAML\Module; /** * Hook to do sanitycheck @@ -15,7 +17,7 @@ function core_hook_sanitycheck(array &$hookinfo): void Assert::keyExists($hookinfo, 'errors'); Assert::keyExists($hookinfo, 'info'); - $config = \SimpleSAML\Configuration::getInstance(); + $config = Configuration::getInstance(); if ($config->getString('auth.adminpassword', '123') === '123') { $hookinfo['errors'][] = '[core] Password in config.php is not set properly'; @@ -40,8 +42,8 @@ function core_hook_sanitycheck(array &$hookinfo): void $mihookinfo = [ 'info' => &$info, ]; - $availmodules = SimpleSAML\Module::getModules(); - SimpleSAML\Module::callHooks('moduleinfo', $mihookinfo); + $availmodules = Module::getModules(); + Module::callHooks('moduleinfo', $mihookinfo); foreach ($info as $mi => $i) { if (isset($i['dependencies']) && is_array($i['dependencies'])) { foreach ($i['dependencies'] as $dep) { diff --git a/modules/core/lib/Auth/Process/AttributeAdd.php b/modules/core/lib/Auth/Process/AttributeAdd.php index d9b1ffd4c..5a1ff5e99 100644 --- a/modules/core/lib/Auth/Process/AttributeAdd.php +++ b/modules/core/lib/Auth/Process/AttributeAdd.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; -use Webmozart\Assert\Assert; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; /** * Filter to add attributes. @@ -14,7 +16,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -class AttributeAdd extends \SimpleSAML\Auth\ProcessingFilter +class AttributeAdd extends Auth\ProcessingFilter { /** * Flag which indicates wheter this filter should append new values or replace old values. @@ -46,7 +48,7 @@ class AttributeAdd extends \SimpleSAML\Auth\ProcessingFilter if ($values === '%replace') { $this->replace = true; } else { - throw new \Exception('Unknown flag: ' . var_export($values, true)); + throw new Exception('Unknown flag: ' . var_export($values, true)); } continue; } @@ -56,7 +58,7 @@ class AttributeAdd extends \SimpleSAML\Auth\ProcessingFilter } foreach ($values as $value) { if (!is_string($value)) { - throw new \Exception( + throw new Exception( 'Invalid value for attribute ' . $name . ': ' . var_export($values, true) ); } diff --git a/modules/core/lib/Auth/Process/AttributeAlter.php b/modules/core/lib/Auth/Process/AttributeAlter.php index 01970de30..b9a0b3875 100644 --- a/modules/core/lib/Auth/Process/AttributeAlter.php +++ b/modules/core/lib/Auth/Process/AttributeAlter.php @@ -4,8 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * Filter to modify attributes using regular expressions @@ -15,7 +16,7 @@ use Webmozart\Assert\Assert; * @author Jacob Christiansen, WAYF * @package SimpleSAMLphp */ -class AttributeAlter extends \SimpleSAML\Auth\ProcessingFilter +class AttributeAlter extends Auth\ProcessingFilter { /** * Should the pattern found be replaced? diff --git a/modules/core/lib/Auth/Process/AttributeCopy.php b/modules/core/lib/Auth/Process/AttributeCopy.php index 00dcddfcd..8fd600129 100644 --- a/modules/core/lib/Auth/Process/AttributeCopy.php +++ b/modules/core/lib/Auth/Process/AttributeCopy.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; -use Webmozart\Assert\Assert; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; /** * Attribute filter for renaming attributes. @@ -21,7 +23,7 @@ use Webmozart\Assert\Assert; * ), * */ -class AttributeCopy extends \SimpleSAML\Auth\ProcessingFilter +class AttributeCopy extends Auth\ProcessingFilter { /** * Assosiative array with the mappings of attribute names. @@ -42,11 +44,11 @@ class AttributeCopy extends \SimpleSAML\Auth\ProcessingFilter foreach ($config as $source => $destination) { if (!is_string($source)) { - throw new \Exception('Invalid source attribute name: ' . var_export($source, true)); + throw new Exception('Invalid source attribute name: ' . var_export($source, true)); } if (!is_string($destination) && !is_array($destination)) { - throw new \Exception('Invalid destination attribute name: ' . var_export($destination, true)); + throw new Exception('Invalid destination attribute name: ' . var_export($destination, true)); } $this->map[$source] = $destination; diff --git a/modules/core/lib/Auth/Process/AttributeLimit.php b/modules/core/lib/Auth/Process/AttributeLimit.php index f5f1f4698..e61301cd8 100644 --- a/modules/core/lib/Auth/Process/AttributeLimit.php +++ b/modules/core/lib/Auth/Process/AttributeLimit.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Error; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * A filter for limiting which attributes are passed on. @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -class AttributeLimit extends \SimpleSAML\Auth\ProcessingFilter +class AttributeLimit extends Auth\ProcessingFilter { /** * List of attributes which this filter will allow through. diff --git a/modules/core/lib/Auth/Process/AttributeMap.php b/modules/core/lib/Auth/Process/AttributeMap.php index 5a79368b9..8fcecb20d 100644 --- a/modules/core/lib/Auth/Process/AttributeMap.php +++ b/modules/core/lib/Auth/Process/AttributeMap.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Module; -use Webmozart\Assert\Assert; /** * Attribute filter for renaming attributes. @@ -14,7 +16,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -class AttributeMap extends \SimpleSAML\Auth\ProcessingFilter +class AttributeMap extends Auth\ProcessingFilter { /** * Associative array with the mappings of attribute names. @@ -55,11 +57,11 @@ class AttributeMap extends \SimpleSAML\Auth\ProcessingFilter } if (!is_string($origName)) { - throw new \Exception('Invalid attribute name: ' . var_export($origName, true)); + throw new Exception('Invalid attribute name: ' . var_export($origName, true)); } if (!is_string($newName) && !is_array($newName)) { - throw new \Exception('Invalid attribute name: ' . var_export($newName, true)); + throw new Exception('Invalid attribute name: ' . var_export($newName, true)); } $this->map[$origName] = $newName; @@ -89,7 +91,7 @@ class AttributeMap extends \SimpleSAML\Auth\ProcessingFilter if (count($m) === 2) { // we are asked for a file in a module if (!Module::isModuleEnabled($m[0])) { - throw new \Exception("Module '$m[0]' is not enabled."); + throw new Exception("Module '$m[0]' is not enabled."); } $filePath = Module::getModuleDir($m[0]) . '/attributemap/' . $m[1] . '.php'; } else { @@ -98,14 +100,14 @@ class AttributeMap extends \SimpleSAML\Auth\ProcessingFilter } if (!file_exists($filePath)) { - throw new \Exception('Could not find attribute map file: ' . $filePath); + throw new Exception('Could not find attribute map file: ' . $filePath); } /** @psalm-var mixed|null $attributemap */ $attributemap = null; include($filePath); if (!is_array($attributemap)) { - throw new \Exception('Attribute map file "' . $filePath . '" didn\'t define an attribute map.'); + throw new Exception('Attribute map file "' . $filePath . '" didn\'t define an attribute map.'); } if ($this->duplicate) { diff --git a/modules/core/lib/Auth/Process/AttributeValueMap.php b/modules/core/lib/Auth/Process/AttributeValueMap.php index 890cb0208..183b48546 100644 --- a/modules/core/lib/Auth/Process/AttributeValueMap.php +++ b/modules/core/lib/Auth/Process/AttributeValueMap.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Error; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Filter to create target attribute based on value(s) in source attribute @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @author Martin van Es, m7 * @package SimpleSAMLphp */ -class AttributeValueMap extends \SimpleSAML\Auth\ProcessingFilter +class AttributeValueMap extends Auth\ProcessingFilter { /** * The name of the attribute we should assign values to (ie: the target attribute). diff --git a/modules/core/lib/Auth/Process/Cardinality.php b/modules/core/lib/Auth/Process/Cardinality.php index 47a4308a9..9e3bb200c 100644 --- a/modules/core/lib/Auth/Process/Cardinality.php +++ b/modules/core/lib/Auth/Process/Cardinality.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Filter to ensure correct cardinality of attributes @@ -17,7 +17,7 @@ use Webmozart\Assert\Assert; * @author Guy Halse, http://orcid.org/0000-0002-9388-8592 * @package SimpleSAMLphp */ -class Cardinality extends \SimpleSAML\Auth\ProcessingFilter +class Cardinality extends Auth\ProcessingFilter { /** @var array Associative array with the mappings of attribute names. */ private $cardinality = []; diff --git a/modules/core/lib/Auth/Process/CardinalitySingle.php b/modules/core/lib/Auth/Process/CardinalitySingle.php index bcdec2780..23ddc4e54 100644 --- a/modules/core/lib/Auth/Process/CardinalitySingle.php +++ b/modules/core/lib/Auth/Process/CardinalitySingle.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Filter to ensure correct cardinality of single-valued attributes @@ -19,7 +19,7 @@ use Webmozart\Assert\Assert; * @author Guy Halse, http://orcid.org/0000-0002-9388-8592 * @package SimpleSAMLphp */ -class CardinalitySingle extends \SimpleSAML\Auth\ProcessingFilter +class CardinalitySingle extends Auth\ProcessingFilter { /** @var array Attributes that should be single-valued or we generate an error */ private $singleValued = []; diff --git a/modules/core/lib/Auth/Process/ExtendIdPSession.php b/modules/core/lib/Auth/Process/ExtendIdPSession.php index 764538336..f3e9f710f 100644 --- a/modules/core/lib/Auth/Process/ExtendIdPSession.php +++ b/modules/core/lib/Auth/Process/ExtendIdPSession.php @@ -4,15 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Session; use SimpleSAML\SessionHandler; -use Webmozart\Assert\Assert; /** * Extend IdP session and cookies. */ -class ExtendIdPSession extends \SimpleSAML\Auth\ProcessingFilter +class ExtendIdPSession extends Auth\ProcessingFilter { /** * @param array &$state diff --git a/modules/core/lib/Auth/Process/GenerateGroups.php b/modules/core/lib/Auth/Process/GenerateGroups.php index fe0cd5f3c..d5bb34529 100644 --- a/modules/core/lib/Auth/Process/GenerateGroups.php +++ b/modules/core/lib/Auth/Process/GenerateGroups.php @@ -4,8 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Filter to generate a groups attribute based on many of the attributes of the user. @@ -13,7 +15,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -class GenerateGroups extends \SimpleSAML\Auth\ProcessingFilter +class GenerateGroups extends Auth\ProcessingFilter { /** * The attributes we should generate groups from. @@ -43,7 +45,7 @@ class GenerateGroups extends \SimpleSAML\Auth\ProcessingFilter // Validate configuration foreach ($config as $attributeName) { if (!is_string($attributeName)) { - throw new \Exception('Invalid attribute name for core:GenerateGroups filter: ' . + throw new Exception('Invalid attribute name for core:GenerateGroups filter: ' . var_export($attributeName, true)); } } diff --git a/modules/core/lib/Auth/Process/LanguageAdaptor.php b/modules/core/lib/Auth/Process/LanguageAdaptor.php index c1cefff0c..3c1be618b 100644 --- a/modules/core/lib/Auth/Process/LanguageAdaptor.php +++ b/modules/core/lib/Auth/Process/LanguageAdaptor.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Locale\Language; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Filter to set and get language settings from attributes. @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @author Andreas Ă…kre Solberg, UNINETT AS. * @package SimpleSAMLphp */ -class LanguageAdaptor extends \SimpleSAML\Auth\ProcessingFilter +class LanguageAdaptor extends Auth\ProcessingFilter { /** @var string */ private $langattr = 'preferredLanguage'; diff --git a/modules/core/lib/Auth/Process/PHP.php b/modules/core/lib/Auth/Process/PHP.php index 541992d09..ad3454fbd 100644 --- a/modules/core/lib/Auth/Process/PHP.php +++ b/modules/core/lib/Auth/Process/PHP.php @@ -4,8 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * Attribute filter for running arbitrary PHP code. @@ -13,7 +14,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class PHP extends \SimpleSAML\Auth\ProcessingFilter +class PHP extends Auth\ProcessingFilter { /** * The PHP code that should be run. @@ -38,7 +39,7 @@ class PHP extends \SimpleSAML\Auth\ProcessingFilter if (!isset($config['code'])) { throw new Error\Exception("core:PHP: missing mandatory configuration option 'code'."); } - $this->code = (string) $config['code']; + $this->code = strval($config['code']); } diff --git a/modules/core/lib/Auth/Process/ScopeAttribute.php b/modules/core/lib/Auth/Process/ScopeAttribute.php index 8c13339b0..4c60aa0c8 100644 --- a/modules/core/lib/Auth/Process/ScopeAttribute.php +++ b/modules/core/lib/Auth/Process/ScopeAttribute.php @@ -4,8 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Configuration; -use Webmozart\Assert\Assert; /** * Add a scoped variant of an attribute. @@ -13,7 +14,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class ScopeAttribute extends \SimpleSAML\Auth\ProcessingFilter +class ScopeAttribute extends Auth\ProcessingFilter { /** * The attribute we extract the scope from. diff --git a/modules/core/lib/Auth/Process/ScopeFromAttribute.php b/modules/core/lib/Auth/Process/ScopeFromAttribute.php index eec2cf68b..7ed93ae74 100644 --- a/modules/core/lib/Auth/Process/ScopeFromAttribute.php +++ b/modules/core/lib/Auth/Process/ScopeFromAttribute.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Retrieve a scope from a source attribute and add it as a virtual target @@ -24,7 +25,7 @@ use Webmozart\Assert\Assert; * to add a virtual 'scope' attribute from the eduPersonPrincipalName * attribute. */ -class ScopeFromAttribute extends \SimpleSAML\Auth\ProcessingFilter +class ScopeFromAttribute extends Auth\ProcessingFilter { /** * The attribute where the scope is taken from diff --git a/modules/core/lib/Auth/Process/StatisticsWithAttribute.php b/modules/core/lib/Auth/Process/StatisticsWithAttribute.php index 66fedc761..8b2774b00 100644 --- a/modules/core/lib/Auth/Process/StatisticsWithAttribute.php +++ b/modules/core/lib/Auth/Process/StatisticsWithAttribute.php @@ -4,8 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Log a line in the STAT log with one attribute. @@ -13,7 +15,7 @@ use Webmozart\Assert\Assert; * @author Andreas Ă…kre Solberg, UNINETT AS. * @package SimpleSAMLphp */ -class StatisticsWithAttribute extends \SimpleSAML\Auth\ProcessingFilter +class StatisticsWithAttribute extends Auth\ProcessingFilter { /** * The attribute to log @@ -45,14 +47,14 @@ class StatisticsWithAttribute extends \SimpleSAML\Auth\ProcessingFilter if (array_key_exists('attributename', $config)) { $this->attribute = $config['attributename']; if (!is_string($this->attribute)) { - throw new \Exception('Invalid attribute name given to core:StatisticsWithAttribute filter.'); + throw new Exception('Invalid attribute name given to core:StatisticsWithAttribute filter.'); } } if (array_key_exists('type', $config)) { $this->typeTag = $config['type']; if (!is_string($this->typeTag)) { - throw new \Exception('Invalid typeTag given to core:StatisticsWithAttribute filter.'); + throw new Exception('Invalid typeTag given to core:StatisticsWithAttribute filter.'); } } diff --git a/modules/core/lib/Auth/Process/TargetedID.php b/modules/core/lib/Auth/Process/TargetedID.php index 5ed627839..6aff8258d 100644 --- a/modules/core/lib/Auth/Process/TargetedID.php +++ b/modules/core/lib/Auth/Process/TargetedID.php @@ -4,10 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use Exception; use SAML2\Constants; use SAML2\XML\saml\NameID; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Filter to generate the eduPersonTargetedID attribute. @@ -37,7 +39,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -class TargetedID extends \SimpleSAML\Auth\ProcessingFilter +class TargetedID extends Auth\ProcessingFilter { /** * The attribute we should generate the targeted id from, or NULL if we should use the @@ -68,14 +70,14 @@ class TargetedID extends \SimpleSAML\Auth\ProcessingFilter if (array_key_exists('attributename', $config)) { $this->attribute = $config['attributename']; if (!is_string($this->attribute)) { - throw new \Exception('Invalid attribute name given to core:TargetedID filter.'); + throw new Exception('Invalid attribute name given to core:TargetedID filter.'); } } if (array_key_exists('nameId', $config)) { $this->generateNameId = $config['nameId']; if (!is_bool($this->generateNameId)) { - throw new \Exception('Invalid value of \'nameId\'-option to core:TargetedID filter.'); + throw new Exception('Invalid value of \'nameId\'-option to core:TargetedID filter.'); } } } @@ -93,7 +95,7 @@ class TargetedID extends \SimpleSAML\Auth\ProcessingFilter if ($this->attribute === null) { if (!array_key_exists('UserID', $state)) { - throw new \Exception('core:TargetedID: Missing UserID for this user. Please' . + throw new Exception('core:TargetedID: Missing UserID for this user. Please' . ' check the \'userid.attribute\' option in the metadata against the' . ' attributes provided by the authentication source.'); } @@ -101,7 +103,7 @@ class TargetedID extends \SimpleSAML\Auth\ProcessingFilter $userID = $state['UserID']; } else { if (!array_key_exists($this->attribute, $state['Attributes'])) { - throw new \Exception('core:TargetedID: Missing attribute \'' . $this->attribute . + throw new Exception('core:TargetedID: Missing attribute \'' . $this->attribute . '\', which is needed to generate the targeted ID.'); } diff --git a/modules/core/lib/Auth/Process/WarnShortSSOInterval.php b/modules/core/lib/Auth/Process/WarnShortSSOInterval.php index 2ce421d3c..ef47239e9 100644 --- a/modules/core/lib/Auth/Process/WarnShortSSOInterval.php +++ b/modules/core/lib/Auth/Process/WarnShortSSOInterval.php @@ -4,18 +4,18 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Process; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Give a warning to the user if we receive multiple requests in a short time. * * @package SimpleSAMLphp */ -class WarnShortSSOInterval extends \SimpleSAML\Auth\ProcessingFilter +class WarnShortSSOInterval extends Auth\ProcessingFilter { /** * Process a authentication response. diff --git a/modules/core/lib/Auth/Source/AdminPassword.php b/modules/core/lib/Auth/Source/AdminPassword.php index 943337255..82ee499ab 100644 --- a/modules/core/lib/Auth/Source/AdminPassword.php +++ b/modules/core/lib/Auth/Source/AdminPassword.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth\Source; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; -use Webmozart\Assert\Assert; +use SimpleSAML\Module\core\Auth\UserPassBase; /** * Authentication source which verifies the password against @@ -15,7 +16,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class AdminPassword extends \SimpleSAML\Module\core\Auth\UserPassBase +class AdminPassword extends UserPassBase { /** * Constructor for this authentication source. diff --git a/modules/core/lib/Auth/UserPassBase.php b/modules/core/lib/Auth/UserPassBase.php index ccba12bcd..c81c172e9 100644 --- a/modules/core/lib/Auth/UserPassBase.php +++ b/modules/core/lib/Auth/UserPassBase.php @@ -5,13 +5,13 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth; use SAML2\Constants; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils\HTTP; -use Webmozart\Assert\Assert; /** * Helper class for username/password authentication. @@ -22,7 +22,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -abstract class UserPassBase extends \SimpleSAML\Auth\Source +abstract class UserPassBase extends Auth\Source { /** * The string used to identify our states. diff --git a/modules/core/lib/Auth/UserPassOrgBase.php b/modules/core/lib/Auth/UserPassOrgBase.php index 3ef8bbc23..a1186cae7 100644 --- a/modules/core/lib/Auth/UserPassOrgBase.php +++ b/modules/core/lib/Auth/UserPassOrgBase.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Auth; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Helper class for username/password/organization authentication. @@ -22,7 +22,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -abstract class UserPassOrgBase extends \SimpleSAML\Auth\Source +abstract class UserPassOrgBase extends Auth\Source { /** * The string used to identify our states. diff --git a/modules/core/lib/Controller/Login.php b/modules/core/lib/Controller/Login.php index e555b1c66..de75c4702 100644 --- a/modules/core/lib/Controller/Login.php +++ b/modules/core/lib/Controller/Login.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Controller; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Auth\AuthenticationFactory; use SimpleSAML\Configuration; @@ -16,7 +17,6 @@ use SimpleSAML\XHTML\Template; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Webmozart\Assert\Assert; /** * Controller class for the core module. diff --git a/modules/core/lib/Controller/Redirection.php b/modules/core/lib/Controller/Redirection.php index aa35589c8..373f77bff 100644 --- a/modules/core/lib/Controller/Redirection.php +++ b/modules/core/lib/Controller/Redirection.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Controller; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Error; @@ -14,7 +15,6 @@ use SimpleSAML\Utils; use SimpleSAML\XHTML\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Webmozart\Assert\Assert; /** * Controller class for the core module. diff --git a/modules/core/lib/Stats/Output/File.php b/modules/core/lib/Stats/Output/File.php index df8307692..90fde8437 100644 --- a/modules/core/lib/Stats/Output/File.php +++ b/modules/core/lib/Stats/Output/File.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\core\Stats\Output; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * Statistics logger that writes to a set of log files diff --git a/modules/core/www/postredirect.php b/modules/core/www/postredirect.php index 07bac08e8..4fecbd9f2 100644 --- a/modules/core/www/postredirect.php +++ b/modules/core/www/postredirect.php @@ -6,27 +6,33 @@ * @package SimpleSAMLphp */ -use Webmozart\Assert\Assert; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Configuration; +use SimpleSAML\Error; +use SimpleSAML\Session; +use SimpleSAML\Utils; +use SimpleSAML\XHTML\Template; if (array_key_exists('RedirId', $_REQUEST)) { $postId = $_REQUEST['RedirId']; - $session = \SimpleSAML\Session::getSessionFromRequest(); + $session = Session::getSessionFromRequest(); } elseif (array_key_exists('RedirInfo', $_REQUEST)) { $encData = base64_decode($_REQUEST['RedirInfo']); if (empty($encData)) { - throw new \SimpleSAML\Error\BadRequest('Invalid RedirInfo data.'); + throw new Error\BadRequest('Invalid RedirInfo data.'); } - list($sessionId, $postId) = explode(':', \SimpleSAML\Utils\Crypto::aesDecrypt($encData)); + list($sessionId, $postId) = explode(':', Utils\Crypto::aesDecrypt($encData)); if (empty($sessionId) || empty($postId)) { - throw new \SimpleSAML\Error\BadRequest('Invalid session info data.'); + throw new Error\BadRequest('Invalid session info data.'); } - $session = \SimpleSAML\Session::getSession($sessionId); + $session = Session::getSession($sessionId); } else { - throw new \SimpleSAML\Error\BadRequest('Missing redirection info parameter.'); + throw new Error\BadRequest('Missing redirection info parameter.'); } if ($session === null) { @@ -46,12 +52,12 @@ Assert::isArray($postData); Assert::keyExists($postData, 'url'); Assert::keyExists($postData, 'post'); -if (!\SimpleSAML\Utils\HTTP::isValidURL($postData['url'])) { - throw new \SimpleSAML\Error\Exception('Invalid destination URL.'); +if (!Utils\HTTP::isValidURL($postData['url'])) { + throw new Error\Exception('Invalid destination URL.'); } -$config = \SimpleSAML\Configuration::getInstance(); -$template = new \SimpleSAML\XHTML\Template($config, 'post.php'); +$config = Configuration::getInstance(); +$template = new Template($config, 'post.php'); $template->data['destination'] = $postData['url']; $template->data['post'] = $postData['post']; $template->send(); diff --git a/modules/cron/hooks/hook_configpage.php b/modules/cron/hooks/hook_configpage.php index cb4358299..05301a912 100644 --- a/modules/cron/hooks/hook_configpage.php +++ b/modules/cron/hooks/hook_configpage.php @@ -1,16 +1,20 @@ <?php +use SimpleSAML\Locale\Translate; +use SimpleSAML\Module; +use SimpleSAML\XHTML\Template; + /** * Hook to add the cron module to the config page. * * @param \SimpleSAML\XHTML\Template &$template The template that we should alter in this hook. * @return void */ -function cron_hook_configpage(\SimpleSAML\XHTML\Template &$template): void +function cron_hook_configpage(Template &$template): void { $template->data['links']['cron'] = [ - 'href' => SimpleSAML\Module::getModuleURL('cron/croninfo.php'), - 'text' => \SimpleSAML\Locale\Translate::noop('Cron module information page'), + 'href' => Module::getModuleURL('cron/croninfo.php'), + 'text' => Translate::noop('Cron module information page'), ]; $template->getLocalization()->addModuleDomain('cron'); } diff --git a/modules/cron/hooks/hook_cron.php b/modules/cron/hooks/hook_cron.php index 2211d7a40..f411fb7ca 100644 --- a/modules/cron/hooks/hook_cron.php +++ b/modules/cron/hooks/hook_cron.php @@ -1,6 +1,7 @@ <?php -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Configuration; /** * Hook to run a cron job. @@ -13,7 +14,7 @@ function cron_hook_cron(array &$croninfo): void Assert::keyExists($croninfo, 'summary'); Assert::keyExists($croninfo, 'tag'); - $cronconfig = \SimpleSAML\Configuration::getConfig('module_cron.php'); + $cronconfig = Configuration::getConfig('module_cron.php'); if ($cronconfig->getValue('debug_message', true)) { $croninfo['summary'][] = 'Cron did run tag [' . $croninfo['tag'] . '] at ' . date(DATE_RFC822); diff --git a/modules/cron/hooks/hook_frontpage.php b/modules/cron/hooks/hook_frontpage.php index 4e34f505d..9282b4a18 100644 --- a/modules/cron/hooks/hook_frontpage.php +++ b/modules/cron/hooks/hook_frontpage.php @@ -1,6 +1,7 @@ <?php -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Module; /** * Hook to add the modinfo module to the frontpage. @@ -13,7 +14,7 @@ function cron_hook_frontpage(array &$links): void Assert::keyExists($links, 'links'); $links['config'][] = [ - 'href' => SimpleSAML\Module::getModuleURL('cron/croninfo.php'), + 'href' => Module::getModuleURL('cron/croninfo.php'), 'text' => '{cron:cron:link_cron}', ]; } diff --git a/modules/cron/lib/Cron.php b/modules/cron/lib/Cron.php index c75bc80c2..0966b8773 100644 --- a/modules/cron/lib/Cron.php +++ b/modules/cron/lib/Cron.php @@ -4,10 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\cron; +use Exception; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; use SimpleSAML\Module; -use Webmozart\Assert\Assert; /** * Handles interactions with SSP's cron system/hooks. @@ -42,7 +43,7 @@ class Cron public function runTag(string $tag): array { if (!$this->isValidTag($tag)) { - throw new \Exception("Invalid cron tag '$tag''"); + throw new Exception("Invalid cron tag '$tag''"); } $summary = []; diff --git a/modules/exampleauth/lib/Auth/Process/RedirectTest.php b/modules/exampleauth/lib/Auth/Process/RedirectTest.php index 27b575f0f..6f9214d91 100644 --- a/modules/exampleauth/lib/Auth/Process/RedirectTest.php +++ b/modules/exampleauth/lib/Auth/Process/RedirectTest.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\exampleauth\Auth\Process; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * A simple processing filter for testing that redirection works as it should. diff --git a/modules/exampleauth/lib/Auth/Source/External.php b/modules/exampleauth/lib/Auth/Source/External.php index 235c159ad..7d59c63da 100644 --- a/modules/exampleauth/lib/Auth/Source/External.php +++ b/modules/exampleauth/lib/Auth/Source/External.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\exampleauth\Auth\Source; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Error; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Example external authentication source. @@ -30,7 +30,7 @@ use Webmozart\Assert\Assert; * * @package SimpleSAMLphp */ -class External extends \SimpleSAML\Auth\Source +class External extends Auth\Source { /** * The key of the AuthId field in the state. diff --git a/modules/exampleauth/lib/Auth/Source/StaticSource.php b/modules/exampleauth/lib/Auth/Source/StaticSource.php index 75e6a57da..ead4484ba 100644 --- a/modules/exampleauth/lib/Auth/Source/StaticSource.php +++ b/modules/exampleauth/lib/Auth/Source/StaticSource.php @@ -4,8 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\exampleauth\Auth\Source; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Example authentication source. @@ -16,7 +18,7 @@ use Webmozart\Assert\Assert; * @author Olav Morken, UNINETT AS. * @package SimpleSAMLphp */ -class StaticSource extends \SimpleSAML\Auth\Source +class StaticSource extends Auth\Source { /** * The attributes we return. @@ -39,8 +41,8 @@ class StaticSource extends \SimpleSAML\Auth\Source // Parse attributes try { $this->attributes = Utils\Attributes::normalizeAttributesArray($config); - } catch (\Exception $e) { - throw new \Exception('Invalid attributes for authentication source ' . + } catch (Exception $e) { + throw new Exception('Invalid attributes for authentication source ' . $this->authId . ': ' . $e->getMessage()); } } diff --git a/modules/exampleauth/lib/Auth/Source/UserPass.php b/modules/exampleauth/lib/Auth/Source/UserPass.php index e4e6b2188..62fa2ee09 100644 --- a/modules/exampleauth/lib/Auth/Source/UserPass.php +++ b/modules/exampleauth/lib/Auth/Source/UserPass.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\exampleauth\Auth\Source; +use Exception; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; +use SimpleSAML\Module\core\Auth\UserPassBase; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Example authentication source - username & password. @@ -18,7 +20,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class UserPass extends \SimpleSAML\Module\core\Auth\UserPassBase +class UserPass extends UserPassBase { /** * Our users, stored in an associative array. The key of the array is "<username>:<password>", @@ -45,14 +47,14 @@ class UserPass extends \SimpleSAML\Module\core\Auth\UserPassBase // Validate and parse our configuration foreach ($config as $userpass => $attributes) { if (!is_string($userpass)) { - throw new \Exception( + throw new Exception( 'Invalid <username>:<password> for authentication source ' . $this->authId . ': ' . $userpass ); } $userpass = explode(':', $userpass, 2); if (count($userpass) !== 2) { - throw new \Exception( + throw new Exception( 'Invalid <username>:<password> for authentication source ' . $this->authId . ': ' . $userpass[0] ); } @@ -61,8 +63,8 @@ class UserPass extends \SimpleSAML\Module\core\Auth\UserPassBase try { $attributes = Utils\Attributes::normalizeAttributesArray($attributes); - } catch (\Exception $e) { - throw new \Exception('Invalid attributes for user ' . $username . + } catch (Exception $e) { + throw new Exception('Invalid attributes for user ' . $username . ' in authentication source ' . $this->authId . ': ' . $e->getMessage()); } $this->users[$username . ':' . $password] = $attributes; diff --git a/modules/multiauth/lib/Auth/Source/MultiAuth.php b/modules/multiauth/lib/Auth/Source/MultiAuth.php index b4e00ad48..7e6cb6fb2 100644 --- a/modules/multiauth/lib/Auth/Source/MultiAuth.php +++ b/modules/multiauth/lib/Auth/Source/MultiAuth.php @@ -4,13 +4,14 @@ declare(strict_types=1); namespace SimpleSAML\Module\multiauth\Auth\Source; +use Exception; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Module; use SimpleSAML\Session; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Authentication source which let the user chooses among a list of @@ -19,7 +20,7 @@ use Webmozart\Assert\Assert; * @author Lorenzo Gil, Yaco Sistemas S.L. * @package SimpleSAMLphp */ -class MultiAuth extends \SimpleSAML\Auth\Source +class MultiAuth extends Auth\Source { /** * The key of the AuthId field in the state. @@ -65,12 +66,12 @@ class MultiAuth extends \SimpleSAML\Auth\Source parent::__construct($info, $config); if (!array_key_exists('sources', $config)) { - throw new \Exception('The required "sources" config option was not found'); + throw new Exception('The required "sources" config option was not found'); } if (array_key_exists('preselect', $config) && is_string($config['preselect'])) { if (!array_key_exists($config['preselect'], $config['sources'])) { - throw new \Exception('The optional "preselect" config option must be present in "sources"'); + throw new Exception('The optional "preselect" config option must be present in "sources"'); } $this->preselect = $config['preselect']; @@ -193,7 +194,7 @@ class MultiAuth extends \SimpleSAML\Auth\Source $state[self::SOURCESID] ); if ($as === null || !in_array($authId, $valid_sources, true)) { - throw new \Exception('Invalid authentication source: ' . $authId); + throw new Exception('Invalid authentication source: ' . $authId); } // Save the selected authentication source for the logout process. @@ -209,7 +210,7 @@ class MultiAuth extends \SimpleSAML\Auth\Source $as->authenticate($state); } catch (Error\Exception $e) { Auth\State::throwException($state, $e); - } catch (\Exception $e) { + } catch (Exception $e) { $e = new Error\UnserializableException($e); Auth\State::throwException($state, $e); } @@ -234,7 +235,7 @@ class MultiAuth extends \SimpleSAML\Auth\Source $source = Auth\Source::getById($authId); if ($source === null) { - throw new \Exception('Invalid authentication source during logout: ' . $authId); + throw new Exception('Invalid authentication source during logout: ' . $authId); } // Then, do the logout on it $source->logout($state); diff --git a/modules/saml/hooks/hook_metadata_hosted.php b/modules/saml/hooks/hook_metadata_hosted.php index 38f35ccfe..d91d8062d 100644 --- a/modules/saml/hooks/hook_metadata_hosted.php +++ b/modules/saml/hooks/hook_metadata_hosted.php @@ -1,6 +1,7 @@ <?php -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; /** * Hook to add the metadata for hosted entities to the frontpage. @@ -10,7 +11,7 @@ use Webmozart\Assert\Assert; */ function saml_hook_metadata_hosted(array &$metadataHosted) { - $sources = \SimpleSAML\Auth\Source::getSourcesOfType('saml:SP'); + $sources = Auth\Source::getSourcesOfType('saml:SP'); foreach ($sources as $source) { /** @var \SimpleSAML\Module\saml\Auth\Source\SP $source */ diff --git a/modules/saml/lib/Auth/Process/AttributeNameID.php b/modules/saml/lib/Auth/Process/AttributeNameID.php index 6c5db9bff..e840f2b6c 100644 --- a/modules/saml/lib/Auth/Process/AttributeNameID.php +++ b/modules/saml/lib/Auth/Process/AttributeNameID.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; +use SimpleSAML\Module\saml\BaseNameIDGenerator; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Authentication processing filter to create a NameID from an attribute. @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class AttributeNameID extends \SimpleSAML\Module\saml\BaseNameIDGenerator +class AttributeNameID extends BaseNameIDGenerator { /** * The attribute we should use as the NameID. diff --git a/modules/saml/lib/Auth/Process/AuthnContextClassRef.php b/modules/saml/lib/Auth/Process/AuthnContextClassRef.php index e1cb26b66..1c98f44ae 100644 --- a/modules/saml/lib/Auth/Process/AuthnContextClassRef.php +++ b/modules/saml/lib/Auth/Process/AuthnContextClassRef.php @@ -4,15 +4,16 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth\ProcessingFilter; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * Filter for setting the AuthnContextClassRef in the response. * * @package SimpleSAMLphp */ -class AuthnContextClassRef extends \SimpleSAML\Auth\ProcessingFilter +class AuthnContextClassRef extends ProcessingFilter { /** * The URI we should set as the AuthnContextClassRef in the login response. @@ -38,7 +39,7 @@ class AuthnContextClassRef extends \SimpleSAML\Auth\ProcessingFilter throw new Error\Exception('Missing AuthnContextClassRef option in processing filter.'); } - $this->authnContextClassRef = (string) $config['AuthnContextClassRef']; + $this->authnContextClassRef = strval($config['AuthnContextClassRef']); } diff --git a/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php b/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php index d33f6bad7..2ba768e3e 100644 --- a/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php +++ b/modules/saml/lib/Auth/Process/ExpectedAuthnContextClassRef.php @@ -4,12 +4,13 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; +use SimpleSAML\Auth\ProcessingFilter; use SimpleSAML\Error; use SimpleSAML\Logger; use SimpleSAML\Module; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Attribute filter to validate AuthnContextClassRef values. @@ -27,7 +28,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class ExpectedAuthnContextClassRef extends \SimpleSAML\Auth\ProcessingFilter +class ExpectedAuthnContextClassRef extends ProcessingFilter { /** * Array of accepted AuthnContextClassRef diff --git a/modules/saml/lib/Auth/Process/FilterScopes.php b/modules/saml/lib/Auth/Process/FilterScopes.php index 39b352069..0e374d07a 100644 --- a/modules/saml/lib/Auth/Process/FilterScopes.php +++ b/modules/saml/lib/Auth/Process/FilterScopes.php @@ -4,9 +4,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth\ProcessingFilter; use SimpleSAML\Logger; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Filter to remove attribute values which are not properly scoped. @@ -16,7 +17,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class FilterScopes extends \SimpleSAML\Auth\ProcessingFilter +class FilterScopes extends ProcessingFilter { /** * @var array Stores any pre-configured scoped attributes which come from the filter configuration. diff --git a/modules/saml/lib/Auth/Process/NameIDAttribute.php b/modules/saml/lib/Auth/Process/NameIDAttribute.php index e33265b56..7ec8a1cae 100644 --- a/modules/saml/lib/Auth/Process/NameIDAttribute.php +++ b/modules/saml/lib/Auth/Process/NameIDAttribute.php @@ -5,8 +5,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; use SAML2\Constants; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth\ProcessingFilter; use SimpleSAML\Error; -use Webmozart\Assert\Assert; /** * Authentication processing filter to create an attribute from a NameID. @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class NameIDAttribute extends \SimpleSAML\Auth\ProcessingFilter +class NameIDAttribute extends ProcessingFilter { /** * The attribute we should save the NameID in. diff --git a/modules/saml/lib/Auth/Process/PersistentNameID.php b/modules/saml/lib/Auth/Process/PersistentNameID.php index c36eaf62e..f54b21532 100644 --- a/modules/saml/lib/Auth/Process/PersistentNameID.php +++ b/modules/saml/lib/Auth/Process/PersistentNameID.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; use SAML2\Constants; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Logger; +use SimpleSAML\Module\saml\BaseNameIDGenerator; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Authentication processing filter to generate a persistent NameID. @@ -16,7 +17,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class PersistentNameID extends \SimpleSAML\Module\saml\BaseNameIDGenerator +class PersistentNameID extends BaseNameIDGenerator { /** * Which attribute contains the unique identifier of the user. diff --git a/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php b/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php index f9bfd25ba..3f889124f 100644 --- a/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php +++ b/modules/saml/lib/Auth/Process/PersistentNameID2TargetedID.php @@ -5,8 +5,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; use SAML2\Constants; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth\ProcessingFilter; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Authentication processing filter to create the eduPersonTargetedID attribute from the persistent NameID. @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class PersistentNameID2TargetedID extends \SimpleSAML\Auth\ProcessingFilter +class PersistentNameID2TargetedID extends ProcessingFilter { /** * The attribute we should save the NameID in. @@ -43,7 +44,7 @@ class PersistentNameID2TargetedID extends \SimpleSAML\Auth\ProcessingFilter parent::__construct($config, $reserved); if (isset($config['attribute'])) { - $this->attribute = (string) $config['attribute']; + $this->attribute = strval($config['attribute']); } else { $this->attribute = 'eduPersonTargetedID'; } diff --git a/modules/saml/lib/Auth/Process/SQLPersistentNameID.php b/modules/saml/lib/Auth/Process/SQLPersistentNameID.php index abf6d5809..2e2bd639d 100644 --- a/modules/saml/lib/Auth/Process/SQLPersistentNameID.php +++ b/modules/saml/lib/Auth/Process/SQLPersistentNameID.php @@ -5,9 +5,10 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; use SAML2\Constants; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; +use SimpleSAML\Module\saml\BaseNameIDGenerator; /** * Authentication processing filter to generate a persistent NameID. @@ -15,7 +16,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class SQLPersistentNameID extends \SimpleSAML\Module\saml\BaseNameIDGenerator +class SQLPersistentNameID extends BaseNameIDGenerator { /** * Which attribute contains the unique identifier of the user. diff --git a/modules/saml/lib/Auth/Process/TransientNameID.php b/modules/saml/lib/Auth/Process/TransientNameID.php index 932ef696a..7e3266117 100644 --- a/modules/saml/lib/Auth/Process/TransientNameID.php +++ b/modules/saml/lib/Auth/Process/TransientNameID.php @@ -5,8 +5,9 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml\Auth\Process; use SAML2\Constants; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Module\saml\BaseNameIDGenerator; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Authentication processing filter to generate a transient NameID. @@ -14,7 +15,7 @@ use Webmozart\Assert\Assert; * @package SimpleSAMLphp */ -class TransientNameID extends \SimpleSAML\Module\saml\BaseNameIDGenerator +class TransientNameID extends BaseNameIDGenerator { /** * Initialize this filter, parse configuration diff --git a/modules/saml/lib/Auth/Source/SP.php b/modules/saml/lib/Auth/Source/SP.php index 7664481f5..98ef637fd 100644 --- a/modules/saml/lib/Auth/Source/SP.php +++ b/modules/saml/lib/Auth/Source/SP.php @@ -8,6 +8,7 @@ use SAML2\AuthnRequest; use SAML2\Binding; use SAML2\Constants; use SAML2\XML\saml\NameID; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Error; @@ -18,7 +19,6 @@ use SimpleSAML\Module; use SimpleSAML\Session; use SimpleSAML\Store; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; class SP extends \SimpleSAML\Auth\Source { diff --git a/modules/saml/lib/BaseNameIDGenerator.php b/modules/saml/lib/BaseNameIDGenerator.php index 15bb39770..a6deb6010 100644 --- a/modules/saml/lib/BaseNameIDGenerator.php +++ b/modules/saml/lib/BaseNameIDGenerator.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml; use SAML2\XML\saml\NameID; +use SimpleSAML\Assert\Assert; use SimpleSAML\Logger; -use Webmozart\Assert\Assert; /** * Base filter for generating NameID values. diff --git a/modules/saml/lib/Error.php b/modules/saml/lib/Error.php index f8e7311b1..64a3835a7 100644 --- a/modules/saml/lib/Error.php +++ b/modules/saml/lib/Error.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace SimpleSAML\Module\saml; use SAML2\Constants; -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; /** * Class for representing a SAML 2 error. diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php index 613c9e707..4e8aaed31 100644 --- a/modules/saml/lib/IdP/SAML2.php +++ b/modules/saml/lib/IdP/SAML2.php @@ -25,6 +25,7 @@ use SAML2\XML\saml\Issuer; use SAML2\XML\saml\NameID; use SAML2\XML\saml\SubjectConfirmation; use SAML2\XML\saml\SubjectConfirmationData; +use SimpleSAML\Assert\Assert; use SimpleSAML\Auth; use SimpleSAML\Configuration; use SimpleSAML\Error; @@ -34,7 +35,6 @@ use SimpleSAML\Metadata\MetaDataStorageHandler; use SimpleSAML\Module; use SimpleSAML\Stats; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * IdP implementation for SAML 2.0 protocol. diff --git a/modules/saml/lib/IdP/SQLNameID.php b/modules/saml/lib/IdP/SQLNameID.php index 6a2e6d31f..d83ca6384 100644 --- a/modules/saml/lib/IdP/SQLNameID.php +++ b/modules/saml/lib/IdP/SQLNameID.php @@ -6,11 +6,11 @@ namespace SimpleSAML\Module\saml\IdP; use PDO; use PDOStatement; +use SimpleSAML\Assert\Assert; use SimpleSAML\Error; use SimpleSAML\Store; use SimpleSAML\Database; use SimpleSAML\Configuration; -use Webmozart\Assert\Assert; /** * Helper class for working with persistent NameIDs stored in SQL datastore. diff --git a/modules/saml/lib/Message.php b/modules/saml/lib/Message.php index c5194aeca..875f211bb 100644 --- a/modules/saml/lib/Message.php +++ b/modules/saml/lib/Message.php @@ -18,11 +18,11 @@ use SAML2\XML\ds\KeyInfo; use SAML2\XML\ds\X509Certificate; use SAML2\XML\ds\X509Data; use SAML2\XML\saml\Issuer; +use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Error as SSP_Error; use SimpleSAML\Logger; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * Common code for building SAML 2 messages based on the available metadata. diff --git a/modules/saml/lib/SP/LogoutStore.php b/modules/saml/lib/SP/LogoutStore.php index a955516dd..47af236b7 100644 --- a/modules/saml/lib/SP/LogoutStore.php +++ b/modules/saml/lib/SP/LogoutStore.php @@ -6,11 +6,11 @@ namespace SimpleSAML\Module\saml\SP; use PDO; use SAML2\XML\saml\NameID; +use SimpleSAML\Assert\Assert; use SimpleSAML\Logger; use SimpleSAML\Session; use SimpleSAML\Store; use SimpleSAML\Utils; -use Webmozart\Assert\Assert; /** * A directory over logout information. diff --git a/modules/saml/www/sp/discoresp.php b/modules/saml/www/sp/discoresp.php index 8ee798645..28d855a7c 100644 --- a/modules/saml/www/sp/discoresp.php +++ b/modules/saml/www/sp/discoresp.php @@ -4,29 +4,31 @@ * Handler for response from IdP discovery service. */ -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; +use SimpleSAML\Error; if (!array_key_exists('AuthID', $_REQUEST)) { - throw new \SimpleSAML\Error\BadRequest('Missing AuthID to discovery service response handler'); + throw new Error\BadRequest('Missing AuthID to discovery service response handler'); } if (!array_key_exists('idpentityid', $_REQUEST)) { - throw new \SimpleSAML\Error\BadRequest('Missing idpentityid to discovery service response handler'); + throw new Error\BadRequest('Missing idpentityid to discovery service response handler'); } /** @var array $state */ -$state = \SimpleSAML\Auth\State::loadState($_REQUEST['AuthID'], 'saml:sp:sso'); +$state = Auth\State::loadState($_REQUEST['AuthID'], 'saml:sp:sso'); // Find authentication source Assert::keyExists($state, 'saml:sp:AuthId'); $sourceId = $state['saml:sp:AuthId']; -$source = \SimpleSAML\Auth\Source::getById($sourceId); +$source = Auth\Source::getById($sourceId); if ($source === null) { throw new Exception('Could not find authentication source with id ' . $sourceId); } if (!($source instanceof \SimpleSAML\Module\saml\Auth\Source\SP)) { - throw new \SimpleSAML\Error\Exception('Source type changed?'); + throw new Error\Exception('Source type changed?'); } $source->startSSO($_REQUEST['idpentityid'], $state); diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php index c5727f0a9..d54431233 100644 --- a/modules/saml/www/sp/metadata.php +++ b/modules/saml/www/sp/metadata.php @@ -1,23 +1,33 @@ <?php +use SAML2\Constants; +use SimpleSAML\Auth; +use SimpleSAML\Configuration; +use SimpleSAML\Error; +use SimpleSAML\Locale\Translate; +use SimpleSAML\Metadata; +use SimpleSAML\Module; +use SimpleSAML\Store; +use SimpleSAML\Utils; +use SimpleSAML\XHTML\Template; use Symfony\Component\VarExporter\VarExporter; if (!array_key_exists('PATH_INFO', $_SERVER)) { - throw new \SimpleSAML\Error\BadRequest('Missing authentication source id in metadata URL'); + throw new Error\BadRequest('Missing authentication source id in metadata URL'); } -$config = \SimpleSAML\Configuration::getInstance(); +$config = Configuration::getInstance(); if ($config->getBoolean('admin.protectmetadata', false)) { - \SimpleSAML\Utils\Auth::requireAdmin(); + Utils\Auth::requireAdmin(); } $sourceId = substr($_SERVER['PATH_INFO'], 1); -$source = \SimpleSAML\Auth\Source::getById($sourceId); +$source = Auth\Source::getById($sourceId); if ($source === null) { - throw new \SimpleSAML\Error\AuthSource($sourceId, 'Could not find authentication source.'); + throw new Error\AuthSource($sourceId, 'Could not find authentication source.'); } -if (!($source instanceof \SimpleSAML\Module\saml\Auth\Source\SP)) { - throw new \SimpleSAML\Error\AuthSource( +if (!($source instanceof Module\saml\Auth\Source\SP)) { + throw new Error\AuthSource( $sourceId, 'The authentication source is not a SAML Service Provider.' ); @@ -25,20 +35,20 @@ if (!($source instanceof \SimpleSAML\Module\saml\Auth\Source\SP)) { $entityId = $source->getEntityId(); $spconfig = $source->getMetadata(); -$store = \SimpleSAML\Store::getInstance(); +$store = Store::getInstance(); $metaArray20 = []; $slosvcdefault = [ - \SAML2\Constants::BINDING_HTTP_REDIRECT, - \SAML2\Constants::BINDING_SOAP, + Constants::BINDING_HTTP_REDIRECT, + Constants::BINDING_SOAP, ]; $slob = $spconfig->getArray('SingleLogoutServiceBinding', $slosvcdefault); -$slol = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-logout.php/' . $sourceId); +$slol = Module::getModuleURL('saml/sp/saml2-logout.php/' . $sourceId); foreach ($slob as $binding) { - if ($binding == \SAML2\Constants::BINDING_SOAP && !($store instanceof \SimpleSAML\Store\SQL)) { + if ($binding == Constants::BINDING_SOAP && !($store instanceof Store\SQL)) { // we cannot properly support SOAP logout continue; } @@ -68,29 +78,29 @@ foreach ($assertionsconsumerservices as $services) { $acsArray = ['index' => $index]; switch ($services) { case 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST': - $acsArray['Binding'] = \SAML2\Constants::BINDING_HTTP_POST; - $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId); - if (!in_array(\SAML2\Constants::NS_SAMLP, $supported_protocols, true)) { - $supported_protocols[] = \SAML2\Constants::NS_SAMLP; + $acsArray['Binding'] = Constants::BINDING_HTTP_POST; + $acsArray['Location'] = Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId); + if (!in_array(Constants::NS_SAMLP, $supported_protocols, true)) { + $supported_protocols[] = Constants::NS_SAMLP; } break; case 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post': $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post'; - $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml1-acs.php/' . $sourceId); + $acsArray['Location'] = Module::getModuleURL('saml/sp/saml1-acs.php/' . $sourceId); if (!in_array('urn:oasis:names:tc:SAML:1.1:protocol', $supported_protocols, true)) { $supported_protocols[] = 'urn:oasis:names:tc:SAML:1.1:protocol'; } break; case 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact': $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact'; - $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId); - if (!in_array(\SAML2\Constants::NS_SAMLP, $supported_protocols, true)) { - $supported_protocols[] = \SAML2\Constants::NS_SAMLP; + $acsArray['Location'] = Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId); + if (!in_array(Constants::NS_SAMLP, $supported_protocols, true)) { + $supported_protocols[] = Constants::NS_SAMLP; } break; case 'urn:oasis:names:tc:SAML:1.0:profiles:artifact-01': $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:1.0:profiles:artifact-01'; - $acsArray['Location'] = \SimpleSAML\Module::getModuleURL( + $acsArray['Location'] = Module::getModuleURL( 'saml/sp/saml1-acs.php/' . $sourceId . '/artifact' ); if (!in_array('urn:oasis:names:tc:SAML:1.1:protocol', $supported_protocols, true)) { @@ -99,10 +109,10 @@ foreach ($assertionsconsumerservices as $services) { break; case 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser': $acsArray['Binding'] = 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser'; - $acsArray['Location'] = \SimpleSAML\Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId); - $acsArray['hoksso:ProtocolBinding'] = \SAML2\Constants::BINDING_HTTP_REDIRECT; - if (!in_array(\SAML2\Constants::NS_SAMLP, $supported_protocols, true)) { - $supported_protocols[] = \SAML2\Constants::NS_SAMLP; + $acsArray['Location'] = Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId); + $acsArray['hoksso:ProtocolBinding'] = Constants::BINDING_HTTP_REDIRECT; + if (!in_array(Constants::NS_SAMLP, $supported_protocols, true)) { + $supported_protocols[] = Constants::NS_SAMLP; } break; } @@ -113,7 +123,7 @@ foreach ($assertionsconsumerservices as $services) { $metaArray20['AssertionConsumerService'] = $spconfig->getArray('AssertionConsumerService', $eps); $keys = []; -$certInfo = \SimpleSAML\Utils\Crypto::loadPublicKey($spconfig, false, 'new_'); +$certInfo = Utils\Crypto::loadPublicKey($spconfig, false, 'new_'); if ($certInfo !== null && array_key_exists('certData', $certInfo)) { $hasNewCert = true; @@ -129,7 +139,7 @@ if ($certInfo !== null && array_key_exists('certData', $certInfo)) { $hasNewCert = false; } -$certInfo = \SimpleSAML\Utils\Crypto::loadPublicKey($spconfig); +$certInfo = Utils\Crypto::loadPublicKey($spconfig); if ($certInfo !== null && array_key_exists('certData', $certInfo)) { $certData = $certInfo['certData']; @@ -146,9 +156,9 @@ if ($certInfo !== null && array_key_exists('certData', $certInfo)) { $format = $spconfig->getValue('NameIDPolicy', null); if ($format !== null) { if (is_array($format)) { - $metaArray20['NameIDFormat'] = \SimpleSAML\Configuration::loadFromArray($format)->getString( + $metaArray20['NameIDFormat'] = Configuration::loadFromArray($format)->getString( 'Format', - \SAML2\Constants::NAMEID_TRANSIENT + Constants::NAMEID_TRANSIENT ); } elseif (is_string($format)) { $metaArray20['NameIDFormat'] = $format; @@ -198,14 +208,14 @@ if ($orgName !== null) { $metaArray20['OrganizationURL'] = $spconfig->getLocalizedString('OrganizationURL', null); if ($metaArray20['OrganizationURL'] === null) { - throw new \SimpleSAML\Error\Exception('If OrganizationName is set, OrganizationURL must also be set.'); + throw new Error\Exception('If OrganizationName is set, OrganizationURL must also be set.'); } } if ($spconfig->hasValue('contacts')) { $contacts = $spconfig->getArray('contacts'); foreach ($contacts as $contact) { - $metaArray20['contacts'][] = \SimpleSAML\Utils\Config\Metadata::getContact($contact); + $metaArray20['contacts'][] = Utils\Config\Metadata::getContact($contact); } } @@ -217,7 +227,7 @@ if ($email && $email !== 'na@example.org') { 'name' => $config->getString('technicalcontact_name', null), 'contactType' => 'technical' ]; - $metaArray20['contacts'][] = \SimpleSAML\Utils\Config\Metadata::getContact($techcontact); + $metaArray20['contacts'][] = Utils\Config\Metadata::getContact($techcontact); } // add certificate @@ -255,7 +265,7 @@ if ($spconfig->hasValue('redirect.sign')) { $metaArray20['metadata-set'] = 'saml20-sp-remote'; $metaArray20['entityid'] = $entityId; -$metaBuilder = new \SimpleSAML\Metadata\SAMLBuilder($entityId); +$metaBuilder = new Metadata\SAMLBuilder($entityId); $metaBuilder->addMetadataSP20($metaArray20, $supported_protocols); $metaBuilder->addOrganizationInfo($metaArray20); @@ -271,14 +281,14 @@ if (isset($metaArray20['attributes']) && is_array($metaArray20['attributes'])) { } // sign the metadata if enabled -$xml = \SimpleSAML\Metadata\Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP'); +$xml = Metadata\Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP'); if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] == 'xhtml') { - $t = new \SimpleSAML\XHTML\Template($config, 'metadata.twig', 'admin'); + $t = new Template($config, 'metadata.twig', 'admin'); $t->data['clipboard.js'] = true; $t->data['header'] = 'saml20-sp'; // TODO: Replace with headerString in 2.0 - $t->data['headerString'] = \SimpleSAML\Locale\Translate::noop('metadata_saml20-sp'); + $t->data['headerString'] = Translate::noop('metadata_saml20-sp'); $t->data['metadata'] = htmlspecialchars($xml); $t->data['metadataflat'] = '$metadata[' . var_export($entityId, true) . '] = ' . VarExporter::export($metaArray20) . ';'; diff --git a/modules/saml/www/sp/saml2-acs.php b/modules/saml/www/sp/saml2-acs.php index 1ca32b5c3..b287ef5b4 100644 --- a/modules/saml/www/sp/saml2-acs.php +++ b/modules/saml/www/sp/saml2-acs.php @@ -4,46 +4,57 @@ * Assertion consumer service handler for SAML 2.0 SP authentication client. */ -use Webmozart\Assert\Assert; +use SAML2\Binding; +use SAML2\Assertion; +use SAML2\HTTPArtifact; +use SAML2\Response; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Auth; +use SimpleSAML\Error; +use SimpleSAML\Module; +use SimpleSAML\Logger; +use SimpleSAML\Session; +use SimpleSAML\Store; +use SimpleSAML\Utils; if (!array_key_exists('PATH_INFO', $_SERVER)) { - throw new \SimpleSAML\Error\BadRequest('Missing authentication source ID in assertion consumer service URL'); + throw new Error\BadRequest('Missing authentication source ID in assertion consumer service URL'); } $sourceId = substr($_SERVER['PATH_INFO'], 1); /** @var \SimpleSAML\Module\saml\Auth\Source\SP $source */ -$source = \SimpleSAML\Auth\Source::getById($sourceId, '\SimpleSAML\Module\saml\Auth\Source\SP'); +$source = Auth\Source::getById($sourceId, '\SimpleSAML\Module\saml\Auth\Source\SP'); $spMetadata = $source->getMetadata(); try { - $b = \SAML2\Binding::getCurrentBinding(); + $b = Binding::getCurrentBinding(); } catch (Exception $e) { // TODO: look for a specific exception // This is dirty. Instead of checking the message of the exception, \SAML2\Binding::getCurrentBinding() should throw // a specific exception when the binding is unknown, and we should capture that here if ($e->getMessage() === 'Unable to find the current binding.') { - throw new \SimpleSAML\Error\Error('ACSPARAMS', $e, 400); + throw new Error\Error('ACSPARAMS', $e, 400); } else { // do not ignore other exceptions! throw $e; } } -if ($b instanceof \SAML2\HTTPArtifact) { +if ($b instanceof HTTPArtifact) { $b->setSPMetadata($spMetadata); } $response = $b->receive(); -if (!($response instanceof \SAML2\Response)) { - throw new \SimpleSAML\Error\BadRequest('Invalid message received to AssertionConsumerService endpoint.'); +if (!($response instanceof Response)) { + throw new Error\BadRequest('Invalid message received to AssertionConsumerService endpoint.'); } $issuer = $response->getIssuer(); if ($issuer === null) { // no Issuer in the response. Look for an unencrypted assertion with an issuer foreach ($response->getAssertions() as $a) { - if ($a instanceof \SAML2\Assertion) { + if ($a instanceof Assertion) { // we found an unencrypted assertion, there should be an issuer here $issuer = $a->getIssuer(); break; @@ -56,7 +67,7 @@ if ($issuer === null) { } $issuer = $issuer->getValue(); -$session = \SimpleSAML\Session::getSessionFromRequest(); +$session = Session::getSessionFromRequest(); $prevAuth = $session->getAuthData($sourceId, 'saml:sp:prevAuth'); /** @psalm-var string $issuer */ if ($prevAuth !== null && $prevAuth['id'] === $response->getId() && $prevAuth['issuer'] === $issuer) { @@ -67,15 +78,15 @@ if ($prevAuth !== null && $prevAuth['id'] === $response->getId() && $prevAuth['i * In that case we may as well just redo the previous redirect * instead of displaying a confusing error message. */ - SimpleSAML\Logger::info( + Logger::info( 'Duplicate SAML 2 response detected - ignoring the response and redirecting the user to the correct page.' ); if (isset($prevAuth['redirect'])) { - \SimpleSAML\Utils\HTTP::redirectTrustedURL($prevAuth['redirect']); + Utils\HTTP::redirectTrustedURL($prevAuth['redirect']); } - SimpleSAML\Logger::info('No RelayState or ReturnURL available, cannot redirect.'); - throw new \SimpleSAML\Error\Exception('Duplicate assertion received.'); + Logger::info('No RelayState or ReturnURL available, cannot redirect.'); + throw new Error\Exception('Duplicate assertion received.'); } $idpMetadata = null; @@ -85,10 +96,10 @@ $stateId = $response->getInResponseTo(); if (!empty($stateId)) { // this should be a response to a request we sent earlier try { - $state = \SimpleSAML\Auth\State::loadState($stateId, 'saml:sp:sso'); + $state = Auth\State::loadState($stateId, 'saml:sp:sso'); } catch (Exception $e) { // something went wrong, - SimpleSAML\Logger::warning('Could not load state specified by InResponseTo: ' . $e->getMessage() . + Logger::warning('Could not load state specified by InResponseTo: ' . $e->getMessage() . ' Processing response as unsolicited.'); } } @@ -97,7 +108,7 @@ if ($state) { // check that the authentication source is correct Assert::keyExists($state, 'saml:sp:AuthId'); if ($state['saml:sp:AuthId'] !== $sourceId) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'The authentication source id in the URL does not match the authentication source which sent the request.' ); } @@ -108,7 +119,7 @@ if ($state) { $idpMetadata = $source->getIdPMetadata($issuer); $idplist = $idpMetadata->getArrayize('IDPList', []); if (!in_array($state['ExpectedIssuer'], $idplist, true)) { - SimpleSAML\Logger::warning( + Logger::warning( 'The issuer of the response not match to the identity provider we sent the request to.' ); } @@ -118,7 +129,7 @@ if ($state) { $state = [ 'saml:sp:isUnsolicited' => true, 'saml:sp:AuthId' => $sourceId, - 'saml:sp:RelayState' => \SimpleSAML\Utils\HTTP::checkURLAllowed( + 'saml:sp:RelayState' => Utils\HTTP::checkURLAllowed( $spMetadata->getString( 'RelayState', $response->getRelayState() @@ -127,18 +138,18 @@ if ($state) { ]; } -SimpleSAML\Logger::debug('Received SAML2 Response from ' . var_export($issuer, true) . '.'); +Logger::debug('Received SAML2 Response from ' . var_export($issuer, true) . '.'); if (is_null($idpMetadata)) { $idpMetadata = $source->getIdPmetadata($issuer); } try { - $assertions = \SimpleSAML\Module\saml\Message::processResponse($spMetadata, $idpMetadata, $response); -} catch (\SimpleSAML\Module\saml\Error $e) { + $assertions = Module\saml\Message::processResponse($spMetadata, $idpMetadata, $response); +} catch (Module\saml\Error $e) { // the status of the response wasn't "success" $e = $e->toException(); - \SimpleSAML\Auth\State::throwException($state, $e); + Auth\State::throwException($state, $e); return; } @@ -151,12 +162,12 @@ $foundAuthnStatement = false; foreach ($assertions as $assertion) { // check for duplicate assertion (replay attack) - $store = \SimpleSAML\Store::getInstance(); + $store = Store::getInstance(); if ($store !== false) { $aID = $assertion->getId(); if ($store->get('saml.AssertionReceived', $aID) !== null) { - $e = new \SimpleSAML\Error\Exception('Received duplicate assertion.'); - \SimpleSAML\Auth\State::throwException($state, $e); + $e = new Error\Exception('Received duplicate assertion.'); + Auth\State::throwException($state, $e); } $notOnOrAfter = $assertion->getNotOnOrAfter(); @@ -192,8 +203,8 @@ foreach ($assertions as $assertion) { $assertion = end($assertions); if (!$foundAuthnStatement) { - $e = new \SimpleSAML\Error\Exception('No AuthnStatement found in assertion(s).'); - \SimpleSAML\Auth\State::throwException($state, $e); + $e = new Error\Exception('No AuthnStatement found in assertion(s).'); + Auth\State::throwException($state, $e); } if ($expire !== null) { @@ -205,7 +216,7 @@ if ($expire !== null) { if (!empty($nameId)) { // register this session in the logout store - \SimpleSAML\Module\saml\SP\LogoutStore::addSession($sourceId, $nameId, $sessionIndex, $logoutExpire); + Module\saml\SP\LogoutStore::addSession($sourceId, $nameId, $sessionIndex, $logoutExpire); // we need to save the NameID and SessionIndex for logout $logoutState = [ diff --git a/modules/saml/www/sp/saml2-logout.php b/modules/saml/www/sp/saml2-logout.php index aaf269e04..bc367c104 100644 --- a/modules/saml/www/sp/saml2-logout.php +++ b/modules/saml/www/sp/saml2-logout.php @@ -6,28 +6,41 @@ * This endpoint handles both logout requests and logout responses. */ +use Exception; +use SAML2\Binding; +use SAML2\Constants; +use SAML2\LogoutResponse; +use SAML2\LogoutRequest; +use SAML2\SOAP; +use SAML2\XML\saml\Issuer; +use SimpleSAML\Auth; +use SimpleSAML\Error; +use SimpleSAML\Logger; +use SimpleSAML\Metadata; +use SimpleSAML\Utils; + if (!array_key_exists('PATH_INFO', $_SERVER)) { - throw new \SimpleSAML\Error\BadRequest('Missing authentication source ID in logout URL'); + throw new Error\BadRequest('Missing authentication source ID in logout URL'); } $sourceId = substr($_SERVER['PATH_INFO'], 1); /** @var \SimpleSAML\Module\saml\Auth\Source\SP $source */ -$source = \SimpleSAML\Auth\Source::getById($sourceId); +$source = Auth\Source::getById($sourceId); if ($source === null) { - throw new \Exception('Could not find authentication source with id ' . $sourceId); + throw new Exception('Could not find authentication source with id ' . $sourceId); } elseif (!($source instanceof \SimpleSAML\Module\saml\Auth\Source\SP)) { - throw new \SimpleSAML\Error\Exception('Source type changed?'); + throw new Error\Exception('Source type changed?'); } try { - $binding = \SAML2\Binding::getCurrentBinding(); -} catch (\Exception $e) { + $binding = Binding::getCurrentBinding(); +} catch (Exception $e) { // TODO: look for a specific exception // This is dirty. Instead of checking the message of the exception, \SAML2\Binding::getCurrentBinding() should throw // an specific exception when the binding is unknown, and we should capture that here if ($e->getMessage() === 'Unable to find the current binding.') { - throw new \SimpleSAML\Error\Error('SLOSERVICEPARAMS', $e, 400); + throw new Error\Error('SLOSERVICEPARAMS', $e, 400); } else { throw $e; // do not ignore other exceptions! } @@ -35,7 +48,7 @@ try { $message = $binding->receive(); $issuer = $message->getIssuer(); -if ($issuer instanceof \SAML2\XML\saml\Issuer) { +if ($issuer instanceof Issuer) { $idpEntityId = $issuer->getValue(); } else { $idpEntityId = $issuer; @@ -43,60 +56,60 @@ if ($issuer instanceof \SAML2\XML\saml\Issuer) { if ($idpEntityId === null) { // Without an issuer we have no way to respond to the message. - throw new \SimpleSAML\Error\BadRequest('Received message on logout endpoint without issuer.'); + throw new Error\BadRequest('Received message on logout endpoint without issuer.'); } $spEntityId = $source->getEntityId(); -$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); +$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $idpMetadata = $source->getIdPMetadata($idpEntityId); $spMetadata = $source->getMetadata(); -\SimpleSAML\Module\saml\Message::validateMessage($idpMetadata, $spMetadata, $message); +Module\saml\Message::validateMessage($idpMetadata, $spMetadata, $message); $destination = $message->getDestination(); -if ($destination !== null && $destination !== \SimpleSAML\Utils\HTTP::getSelfURLNoQuery()) { - throw new \SimpleSAML\Error\Exception('Destination in logout message is wrong.'); +if ($destination !== null && $destination !== Utils\HTTP::getSelfURLNoQuery()) { + throw new Error\Exception('Destination in logout message is wrong.'); } -if ($message instanceof \SAML2\LogoutResponse) { +if ($message instanceof LogoutResponse) { $relayState = $message->getRelayState(); if ($relayState === null) { // Somehow, our RelayState has been lost. - throw new \SimpleSAML\Error\BadRequest('Missing RelayState in logout response.'); + throw new Error\BadRequest('Missing RelayState in logout response.'); } if (!$message->isSuccess()) { - \SimpleSAML\Logger::warning( - 'Unsuccessful logout. Status was: ' . \SimpleSAML\Module\saml\Message::getResponseError($message) + Logger::warning( + 'Unsuccessful logout. Status was: ' . Module\saml\Message::getResponseError($message) ); } - $state = \SimpleSAML\Auth\State::loadState($relayState, 'saml:slosent'); + $state = Auth\State::loadState($relayState, 'saml:slosent'); $state['saml:sp:LogoutStatus'] = $message->getStatus(); \SimpleSAML\Auth\Source::completeLogout($state); -} elseif ($message instanceof \SAML2\LogoutRequest) { - \SimpleSAML\Logger::debug('module/saml2/sp/logout: Request from ' . $idpEntityId); - \SimpleSAML\Logger::stats('saml20-idp-SLO idpinit ' . $spEntityId . ' ' . $idpEntityId); +} elseif ($message instanceof LogoutRequest) { + Logger::debug('module/saml2/sp/logout: Request from ' . $idpEntityId); + Logger::stats('saml20-idp-SLO idpinit ' . $spEntityId . ' ' . $idpEntityId); if ($message->isNameIdEncrypted()) { try { - $keys = \SimpleSAML\Module\saml\Message::getDecryptionKeys($idpMetadata, $spMetadata); - } catch (\Exception $e) { - throw new \SimpleSAML\Error\Exception('Error decrypting NameID: ' . $e->getMessage()); + $keys = Module\saml\Message::getDecryptionKeys($idpMetadata, $spMetadata); + } catch (Exception $e) { + throw new Error\Exception('Error decrypting NameID: ' . $e->getMessage()); } - $blacklist = \SimpleSAML\Module\saml\Message::getBlacklistedAlgorithms($idpMetadata, $spMetadata); + $blacklist = Module\saml\Message::getBlacklistedAlgorithms($idpMetadata, $spMetadata); $lastException = null; foreach ($keys as $i => $key) { try { $message->decryptNameId($key, $blacklist); - \SimpleSAML\Logger::debug('Decryption with key #' . $i . ' succeeded.'); + Logger::debug('Decryption with key #' . $i . ' succeeded.'); $lastException = null; break; - } catch (\Exception $e) { - \SimpleSAML\Logger::debug('Decryption with key #' . $i . ' failed with exception: ' . $e->getMessage()); + } catch (Exception $e) { + Logger::debug('Decryption with key #' . $i . ' failed with exception: ' . $e->getMessage()); $lastException = $e; } } @@ -109,7 +122,7 @@ if ($message instanceof \SAML2\LogoutResponse) { $sessionIndexes = $message->getSessionIndexes(); /** @psalm-suppress PossiblyNullArgument This will be fixed in saml2 5.0 */ - $numLoggedOut = \SimpleSAML\Module\saml\SP\LogoutStore::logoutSessions($sourceId, $nameId, $sessionIndexes); + $numLoggedOut = Module\saml\SP\LogoutStore::logoutSessions($sourceId, $nameId, $sessionIndexes); if ($numLoggedOut === false) { // This type of logout was unsupported. Use the old method $source->handleLogout($idpEntityId); @@ -117,24 +130,24 @@ if ($message instanceof \SAML2\LogoutResponse) { } // Create and send response - $lr = \SimpleSAML\Module\saml\Message::buildLogoutResponse($spMetadata, $idpMetadata); + $lr = Module\saml\Message::buildLogoutResponse($spMetadata, $idpMetadata); $lr->setRelayState($message->getRelayState()); $lr->setInResponseTo($message->getId()); if ($numLoggedOut < count($sessionIndexes)) { - \SimpleSAML\Logger::warning('Logged out of ' . $numLoggedOut . ' of ' . count($sessionIndexes) . ' sessions.'); + Logger::warning('Logged out of ' . $numLoggedOut . ' of ' . count($sessionIndexes) . ' sessions.'); } $dst = $idpMetadata->getEndpointPrioritizedByBinding( 'SingleLogoutService', [ - \SAML2\Constants::BINDING_HTTP_REDIRECT, - \SAML2\Constants::BINDING_HTTP_POST + Constants::BINDING_HTTP_REDIRECT, + Constants::BINDING_HTTP_POST ] ); - if (!($binding instanceof \SAML2\SOAP)) { - $binding = \SAML2\Binding::getBinding($dst['Binding']); + if (!($binding instanceof SOAP)) { + $binding = Binding::getBinding($dst['Binding']); if (isset($dst['ResponseLocation'])) { $dst = $dst['ResponseLocation']; } else { @@ -147,5 +160,5 @@ if ($message instanceof \SAML2\LogoutResponse) { $binding->send($lr); } else { - throw new \SimpleSAML\Error\BadRequest('Unknown message received on logout endpoint: ' . get_class($message)); + throw new Error\BadRequest('Unknown message received on logout endpoint: ' . get_class($message)); } diff --git a/modules/saml/www/sp/wrong_authncontextclassref.php b/modules/saml/www/sp/wrong_authncontextclassref.php index 15c08cd9a..da2ed84f9 100644 --- a/modules/saml/www/sp/wrong_authncontextclassref.php +++ b/modules/saml/www/sp/wrong_authncontextclassref.php @@ -1,5 +1,8 @@ <?php -$globalConfig = \SimpleSAML\Configuration::getInstance(); -$t = new \SimpleSAML\XHTML\Template($globalConfig, 'saml:sp/wrong_authncontextclassref.twig'); +use SimpleSAML\Configuration; +use SimpleSAML\XHTML\Template; + +$globalConfig = Configuration::getInstance(); +$t = new Template($globalConfig, 'saml:sp/wrong_authncontextclassref.twig'); $t->send(); diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php index 09b9f699b..5ecbef2d2 100644 --- a/tests/lib/SimpleSAML/Utils/HTTPTest.php +++ b/tests/lib/SimpleSAML/Utils/HTTPTest.php @@ -9,7 +9,6 @@ use SimpleSAML\Configuration; use SimpleSAML\Error; use SimpleSAML\Test\Utils\ClearStateTestCase; use SimpleSAML\Utils\HTTP; -use Webmozart\Assert\Assert; class HTTPTest extends ClearStateTestCase { diff --git a/www/saml2/idp/ArtifactResolutionService.php b/www/saml2/idp/ArtifactResolutionService.php index 16a99dc62..c98fba2a8 100644 --- a/www/saml2/idp/ArtifactResolutionService.php +++ b/www/saml2/idp/ArtifactResolutionService.php @@ -10,25 +10,36 @@ require_once('../../_include.php'); -$config = \SimpleSAML\Configuration::getInstance(); +use Exception; +use SAML2\ArtifactResolve; +use SAML2\ArtifactResponse; +use SAML2\DOMDocumentFactory; +use SAML2\SOAP; +use SimpleSAML\Configuration; +use SimpleSAML\Error; +use SimpleSAML\Module; +use SimpleSAML\Metadata; +use SimpleSAML\Store; + +$config = Configuration::getInstance(); if (!$config->getBoolean('enable.saml20-idp', false)) { - throw new \SimpleSAML\Error\Error('NOACCESS'); + throw new Error\Error('NOACCESS'); } -$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); +$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); $idpMetadata = $metadata->getMetaDataConfig($idpEntityId, 'saml20-idp-hosted'); if (!$idpMetadata->getBoolean('saml20.sendartifact', false)) { - throw new \SimpleSAML\Error\Error('NOACCESS'); + throw new Error\Error('NOACCESS'); } -$store = \SimpleSAML\Store::getInstance(); +$store = Store::getInstance(); if ($store === false) { throw new Exception('Unable to send artifact without a datastore configured.'); } -$binding = new \SAML2\SOAP(); +$binding = new SOAP(); try { $request = $binding->receive(); } catch (Exception $e) { @@ -37,12 +48,12 @@ try { // an specific exception when the binding is unknown, and we should capture that here. Also note that the exception // message here is bogus! if ($e->getMessage() === 'Invalid message received to AssertionConsumerService endpoint.') { - throw new \SimpleSAML\Error\Error('ARSPARAMS', $e, 400); + throw new Error\Error('ARSPARAMS', $e, 400); } else { throw $e; // do not ignore other exceptions! } } -if (!($request instanceof \SAML2\ArtifactResolve)) { +if (!($request instanceof ArtifactResolve)) { throw new Exception('Message received on ArtifactResolutionService wasn\'t a ArtifactResolve request.'); } @@ -55,15 +66,15 @@ $responseData = $store->get('artifact', $artifact); $store->delete('artifact', $artifact); if ($responseData !== null) { - $document = \SAML2\DOMDocumentFactory::fromString($responseData); + $document = DOMDocumentFactory::fromString($responseData); $responseXML = $document->firstChild; } else { $responseXML = null; } -$artifactResponse = new \SAML2\ArtifactResponse(); +$artifactResponse = new ArtifactResponse(); $artifactResponse->setIssuer($idpEntityId); $artifactResponse->setInResponseTo($request->getId()); $artifactResponse->setAny($responseXML); -\SimpleSAML\Module\saml\Message::addSign($idpMetadata, $spMetadata, $artifactResponse); +Module\saml\Message::addSign($idpMetadata, $spMetadata, $artifactResponse); $binding->send($artifactResponse); diff --git a/www/saml2/idp/SSOService.php b/www/saml2/idp/SSOService.php index 61b472ece..c0679790c 100644 --- a/www/saml2/idp/SSOService.php +++ b/www/saml2/idp/SSOService.php @@ -11,19 +11,25 @@ require_once('../../_include.php'); -use Webmozart\Assert\Assert; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Error; +use SimpleSAML\Idp; +use SimpleSAML\Logger; +use SimpleSAML\Metadata; +use SimpleSAML\Module; -\SimpleSAML\Logger::info('SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService'); +Logger::info('SAML2.0 - IdP.SSOService: Accessing SAML 2.0 IdP endpoint SSOService'); -$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); +$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); -$idp = \SimpleSAML\IdP::getById('saml2:' . $idpEntityId); +$idp = IdP::getById('saml2:' . $idpEntityId); try { - \SimpleSAML\Module\saml\IdP\SAML2::receiveAuthnRequest($idp); -} catch (\Exception $e) { + Module\saml\IdP\SAML2::receiveAuthnRequest($idp); +} catch (Exception $e) { if ($e->getMessage() === "Unable to find the current binding.") { - throw new \SimpleSAML\Error\Error('SSOPARAMS', $e, 400); + throw new Error\Error('SSOPARAMS', $e, 400); } else { throw $e; // do not ignore other exceptions! } diff --git a/www/saml2/idp/SingleLogoutService.php b/www/saml2/idp/SingleLogoutService.php index ab4a49b0f..8ff5872d1 100644 --- a/www/saml2/idp/SingleLogoutService.php +++ b/www/saml2/idp/SingleLogoutService.php @@ -10,27 +10,34 @@ require_once('../../_include.php'); -use Webmozart\Assert\Assert; +use Exception; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Error; +use SimpleSAML\Idp; +use SimpleSAML\Logger; +use SimpleSAML\Metadata; +use SimpleSAML\Module; +use SimpleSAML\Utils; -\SimpleSAML\Logger::info('SAML2.0 - IdP.SingleLogoutService: Accessing SAML 2.0 IdP endpoint SingleLogoutService'); +Logger::info('SAML2.0 - IdP.SingleLogoutService: Accessing SAML 2.0 IdP endpoint SingleLogoutService'); -$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); +$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); -$idp = \SimpleSAML\IdP::getById('saml2:' . $idpEntityId); +$idp = IdP::getById('saml2:' . $idpEntityId); if (isset($_REQUEST['ReturnTo'])) { - $idp->doLogoutRedirect(\SimpleSAML\Utils\HTTP::checkURLAllowed((string) $_REQUEST['ReturnTo'])); + $idp->doLogoutRedirect(Utils\HTTP::checkURLAllowed((string) $_REQUEST['ReturnTo'])); } else { try { - \SimpleSAML\Module\saml\IdP\SAML2::receiveLogoutMessage($idp); - } catch (\Exception $e) { + Module\saml\IdP\SAML2::receiveLogoutMessage($idp); + } catch (Exception $e) { // TODO: look for a specific exception /* * This is dirty. Instead of checking the message of the exception, \SAML2\Binding::getCurrentBinding() should * throw an specific exception when the binding is unknown, and we should capture that here */ if ($e->getMessage() === 'Unable to find the current binding.') { - throw new \SimpleSAML\Error\Error('SLOSERVICEPARAMS', $e, 400); + throw new Error\Error('SLOSERVICEPARAMS', $e, 400); } else { throw $e; // do not ignore other exceptions! } diff --git a/www/saml2/idp/initSLO.php b/www/saml2/idp/initSLO.php index 24e6748f8..24f27c470 100644 --- a/www/saml2/idp/initSLO.php +++ b/www/saml2/idp/initSLO.php @@ -2,17 +2,22 @@ require_once('../../_include.php'); -use Webmozart\Assert\Assert; +use SimpleSAML\Assert\Assert; +use SimpleSAML\Error; +use SimpleSAML\Idp; +use SimpleSAML\Logger; +use SimpleSAML\Metadata; +use SimpleSAML\Utils; -$metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler(); +$metadata = Metadata\MetaDataStorageHandler::getMetadataHandler(); $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); -$idp = \SimpleSAML\IdP::getById('saml2:' . $idpEntityId); +$idp = IdP::getById('saml2:' . $idpEntityId); -\SimpleSAML\Logger::info('SAML2.0 - IdP.initSLO: Accessing SAML 2.0 IdP endpoint init Single Logout'); +Logger::info('SAML2.0 - IdP.initSLO: Accessing SAML 2.0 IdP endpoint init Single Logout'); if (!isset($_GET['RelayState'])) { - throw new \SimpleSAML\Error\Error('NORELAYSTATE'); + throw new Error\Error('NORELAYSTATE'); } -$idp->doLogoutRedirect(\SimpleSAML\Utils\HTTP::checkURLAllowed((string) $_GET['RelayState'])); +$idp->doLogoutRedirect(Utils\HTTP::checkURLAllowed((string) $_GET['RelayState'])); Assert::true(false); diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php index cdfa430f1..f8e49d881 100644 --- a/www/saml2/idp/metadata.php +++ b/www/saml2/idp/metadata.php @@ -5,12 +5,12 @@ require_once('../../_include.php'); use Symfony\Component\VarExporter\VarExporter; use SAML2\Constants; +use SimpleSAML\Assert\Assert; use SimpleSAML\Module; use SimpleSAML\Utils\Auth as Auth; use SimpleSAML\Utils\Crypto as Crypto; use SimpleSAML\Utils\HTTP as HTTP; use SimpleSAML\Utils\Config\Metadata as Metadata; -use Webmozart\Assert\Assert; // load SimpleSAMLphp configuration and metadata $config = \SimpleSAML\Configuration::getInstance(); -- GitLab