├── .scrutinizer.yml ├── tests └── LightSaml │ └── SymfonyBridgeBundle │ └── Tests │ ├── Functional │ ├── routing.yml │ ├── TestKernel.php │ ├── config.yml │ └── FunctionalTest.php │ ├── Bridge │ └── Container │ │ ├── CredentialContainerTest.php │ │ ├── OwnContainerTest.php │ │ ├── PartyContainerTest.php │ │ ├── StoreContainerTest.php │ │ ├── ProviderContainerTest.php │ │ ├── SystemContainerTest.php │ │ ├── BuildContainerTest.php │ │ └── ServiceContainerTest.php │ ├── Factory │ ├── CredentialStoreFactoryTest.php │ └── OwnEntityDescriptorProviderFactoryTest.php │ ├── LightSamlSymfonyBridgeBundleTest.php │ └── DependencyInjection │ ├── Compiler │ └── AddMethodCallCompilerPassTest.php │ ├── ConfigurationTest.php │ └── LightSamlSymfonyBridgeExtensionTest.php ├── autoload.php ├── src └── LightSaml │ └── SymfonyBridgeBundle │ ├── Resources │ └── config │ │ ├── provider.yml │ │ ├── system.yml │ │ ├── party.yml │ │ ├── credential.yml │ │ ├── profile.yml │ │ ├── own.yml │ │ ├── store.yml │ │ ├── container.yml │ │ └── service.yml │ ├── Bridge │ └── Container │ │ ├── CredentialContainer.php │ │ ├── OwnContainer.php │ │ ├── StoreContainer.php │ │ ├── ProviderContainer.php │ │ ├── PartyContainer.php │ │ ├── SystemContainer.php │ │ ├── BuildContainer.php │ │ └── ServiceContainer.php │ ├── LightSamlSymfonyBridgeBundle.php │ ├── Factory │ ├── CredentialStoreFactory.php │ └── OwnEntityDescriptorProviderFactory.php │ └── DependencyInjection │ ├── Compiler │ └── AddMethodCallCompilerPass.php │ ├── Configuration.php │ └── LightSamlSymfonyBridgeExtension.php ├── CHANGELOG.md ├── contrib ├── setup.sh └── pre-commit ├── .php_cs ├── README.md ├── .gitignore ├── .travis.yml ├── LICENSE ├── phpunit.xml.dist └── composer.json /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | tools: 2 | external_code_coverage: true 3 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/routing.yml: -------------------------------------------------------------------------------- 1 | lightsaml.login_check: 2 | path: /login_check 3 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | &2 "I require wget or curl but they are not installed. Aborting."; exit 1; } 6 | fi 7 | 8 | # Copy the pre-commit hook to the current repository hooks directory. 9 | cp contrib/pre-commit .git/hooks/pre-commit 10 | 11 | # Add execution permission for pre-commit file. 12 | chmod +x .git/hooks/pre-commit -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/CredentialContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(CredentialStoreInterface::class)->getMock() 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/party.yml: -------------------------------------------------------------------------------- 1 | services: 2 | lightsaml.party.sp_entity_descriptor_store: 3 | class: LightSaml\Store\EntityDescriptor\CompositeEntityDescriptorStore 4 | 5 | lightsaml.party.idp_entity_descriptor_store: 6 | class: LightSaml\Store\EntityDescriptor\CompositeEntityDescriptorStore 7 | 8 | lightsaml.party.idp_entity_descriptor_store.file: 9 | class: LightSaml\Store\EntityDescriptor\FileEntityDescriptorStore 10 | arguments: 11 | - ~ # filename 12 | abstract: true 13 | 14 | lightsaml.party.trust_options_store: 15 | class: LightSaml\Store\TrustOptions\CompositeTrustOptionsStore 16 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | in('src') 5 | ; 6 | 7 | $header = << 11 | 12 | This source file is subject to the MIT license that is bundled 13 | with this source code in the file LICENSE. 14 | EOT; 15 | 16 | return PhpCsFixer\Config::create() 17 | ->setRules(array( 18 | '@Symfony' => true, 19 | 'simplified_null_return' => false, 20 | 'phpdoc_no_empty_return' => false, 21 | 'no_mixed_echo_print' => ['use' => 'print'], 22 | 'header_comment' => ['header' => $header], 23 | )) 24 | ->setUsingCache(false) 25 | ->setFinder($finder) 26 | ; 27 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/credential.yml: -------------------------------------------------------------------------------- 1 | services: 2 | lightsaml.credential.credential_store: 3 | class: LightSaml\Store\Credential\CompositeCredentialStore 4 | # factory: ["@lightsaml.credential.credential_store_factory", buildFromOwnCredentialStore] # set in extension, differently based on symfony version 5 | arguments: 6 | - "@lightsaml.party.idp_entity_descriptor_store" 7 | - "@lightsaml.party.sp_entity_descriptor_store" 8 | - "%lightsaml.own.entity_id%" 9 | - "@lightsaml.own.credential_store" 10 | - [] 11 | 12 | lightsaml.credential.credential_store_factory: 13 | class: LightSaml\Store\Credential\Factory\CredentialFactory 14 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/profile.yml: -------------------------------------------------------------------------------- 1 | services: 2 | ligthsaml.profile.metadata: 3 | class: LightSaml\Builder\Profile\Metadata\MetadataProfileBuilder 4 | public: true 5 | arguments: 6 | - "@lightsaml.container.build" 7 | 8 | ligthsaml.profile.login_factory: 9 | class: LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpSendAuthnRequestProfileBuilderFactory 10 | public: true 11 | arguments: 12 | - "@lightsaml.container.build" 13 | 14 | ligthsaml.profile.acs: 15 | class: LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpReceiveResponseProfileBuilder 16 | public: true 17 | arguments: 18 | - "@lightsaml.container.build" 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LightSAML Symfony Bridge Bundle 2 | =============================== 3 | 4 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) 5 | [![Build Status](https://travis-ci.org/lightSAML/SymfonyBridgeBundle.svg?branch=master)](https://travis-ci.org/lightSAML/SymfonyBridgeBundle) 6 | [![Coverage Status](https://coveralls.io/repos/lightSAML/SymfonyBridgeBundle/badge.svg?branch=master&service=github)](https://coveralls.io/github/lightSAML/SymfonyBridgeBundle?branch=master) 7 | [![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/tmilos77) 8 | 9 | LightSAML Symfony Bridge Bundle implements LightSAML build container bridge to the Symfony container. 10 | 11 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/own.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | lightsaml.own.entity_id: ~ 3 | lightsaml.route.login_check: lightsaml.login_check 4 | 5 | services: 6 | lightsaml.own.credential_store: 7 | class: LightSaml\Store\Credential\CompositeCredentialStore 8 | 9 | lightsaml.own.entity_descriptor_provider: 10 | class: LightSaml\Builder\EntityDescriptor\SimpleEntityDescriptorBuilder 11 | # factory set in extension, all with arguments, differently based on symfony version 12 | # factory: ["@LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory", "fromEntitiesDescriptorFile"] 13 | # factory: ["@LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory", "fromEntityDescriptorFile"] 14 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/OwnContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(EntityDescriptorProviderInterface::class)->getMock(), 16 | $this->getMockBuilder(CredentialStoreInterface::class)->getMock(), 17 | "string" 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Cache and logs (Symfony2) 2 | /app/cache/* 3 | /app/logs/* 4 | !app/cache/.gitkeep 5 | !app/logs/.gitkeep 6 | 7 | # Cache and logs (Symfony3) 8 | /var/cache/* 9 | /var/logs/* 10 | !var/cache/.gitkeep 11 | !var/logs/.gitkeep 12 | 13 | # Parameters 14 | /app/config/parameters.yml 15 | /app/config/parameters.ini 16 | 17 | # Managed by Composer 18 | /app/bootstrap.php.cache 19 | /var/bootstrap.php.cache 20 | /bin/* 21 | !bin/console 22 | !bin/symfony_requirements 23 | /vendor/ 24 | 25 | # Assets and user uploads 26 | /web/bundles/ 27 | /web/uploads/ 28 | 29 | # PHPUnit 30 | /app/phpunit.xml 31 | /phpunit.xml 32 | 33 | # Build data 34 | /build/ 35 | 36 | # Composer PHAR 37 | /composer.phar 38 | /composer.lock 39 | /*.phar 40 | /*.cache 41 | 42 | tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/cache/* -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/store.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | lightsaml.store.request_session_prefix: main 3 | lightsaml.store.request_session_sufix: saml_request_state_ 4 | lightsaml.store.sso_state_session_key: samlsso 5 | 6 | services: 7 | lightsaml.store.request: 8 | class: LightSaml\Store\Request\RequestStateSessionStore 9 | arguments: 10 | - "@session" 11 | - "%lightsaml.store.request_session_prefix%" 12 | - "%lightsaml.store.request_session_sufix%" 13 | 14 | lightsaml.store.id_state: 15 | class: LightSaml\Store\Id\NullIdStore 16 | 17 | lightsaml.store.sso_state: 18 | class: LightSaml\Store\Sso\SsoStateSessionStore 19 | arguments: 20 | - "@session" 21 | - "%lightsaml.store.sso_state_session_key%" 22 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/PartyContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), 16 | $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), 17 | $this->getMockBuilder(TrustOptionsStoreInterface::class)->getMock() 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/StoreContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(RequestStateStoreInterface::class)->getMock(), 17 | $this->getMockBuilder(IdStoreInterface::class)->getMock(), 18 | $this->getMockBuilder(SsoStateStoreInterface::class)->getMock() 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ProviderContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(AttributeValueProviderInterface::class)->getMock(), 17 | $this->getMockBuilder(SessionInfoProviderInterface::class)->getMock(), 18 | $this->getMockBuilder(NameIdProviderInterface::class)->getMock() 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/TestKernel.php: -------------------------------------------------------------------------------- 1 | load(__DIR__.'/config.yml'); 33 | } 34 | 35 | 36 | } -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/SystemContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(RequestStack::class)->getMock(), 19 | $this->getMockBuilder(SessionInterface::class)->getMock(), 20 | $this->getMockBuilder(TimeProviderInterface::class)->getMock(), 21 | $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 22 | $this->getMockBuilder(LoggerInterface::class)->getMock() 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/CredentialContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\CredentialContainerInterface; 15 | use LightSaml\Store\Credential\CredentialStoreInterface; 16 | 17 | class CredentialContainer implements CredentialContainerInterface 18 | { 19 | /** @var CredentialStoreInterface */ 20 | private $credentialStore; 21 | 22 | /** 23 | * @param CredentialStoreInterface $credentialStore 24 | */ 25 | public function __construct(CredentialStoreInterface $credentialStore) 26 | { 27 | $this->credentialStore = $credentialStore; 28 | } 29 | 30 | /** 31 | * @return CredentialStoreInterface 32 | */ 33 | public function getCredentialStore() 34 | { 35 | return $this->credentialStore; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | 8 | matrix: 9 | include: 10 | - php: 5.6 11 | env: COMPOSER_FLAGS="--prefer-lowest" 12 | 13 | before_install: 14 | - composer self-update 15 | - composer --version 16 | - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer.phar; fi 17 | - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then php php-cs-fixer.phar --version; fi 18 | - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar; fi 19 | 20 | install: 21 | - COMPOSER_ROOT_VERSION=dev-master composer update --prefer-source $COMPOSER_FLAGS 22 | 23 | script: 24 | - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then php php-cs-fixer.phar fix --dry-run -v; fi 25 | - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then bin/phpunit --coverage-clover build/logs/clover.xml; fi 26 | - if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then bin/phpunit; fi 27 | 28 | after_script: 29 | - if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then php php-coveralls.phar -v; fi 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Milos Tomic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /contrib/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Pre-commit Git hook. 3 | # Runs PHP CS Fixer on PHP files. 4 | # 5 | # If you absolutely must commit without testing, 6 | # use: git commit --no-verify 7 | 8 | # This will check only staged files to be commited. 9 | filenames=($(git diff --staged --name-only HEAD)) 10 | 11 | # This will set text to red in terminal. 12 | text_red=`tput setaf 1` 13 | # This will set the text to green in terminal. 14 | text_green=`tput setaf 2` 15 | # This will reset the terminal text to normal. 16 | text_reset=`tput sgr0` 17 | 18 | numberFilesChanged="${#filenames[@]}" 19 | 20 | if [[ $numberFilesChanged > 0 ]]; 21 | then 22 | echo "$numberFilesChanged files were changed, running php-cs-fixer" 23 | # PHP CS Fixer. 24 | for i in "${filenames[@]}" 25 | do 26 | if [[ $i == *.php ]]; 27 | then 28 | php php-cs-fixer.phar fix $i 29 | 30 | if [ $? -ne 0 ]; 31 | then 32 | # File had some issues. Now it is fine. Add this file to git again. 33 | git add $i 34 | fi 35 | fi 36 | done 37 | fi 38 | 39 | echo "${text_green}PHP CS Fixer finished execution successfully.${text_reset}" 40 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | tests 24 | 25 | 26 | 27 | 32 | 33 | 34 | 35 | src 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/CredentialStoreFactoryTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(CredentialStoreInterface::class)->getMock(); 18 | $credentialStoreMock->method('getByEntityId') 19 | ->willReturn([$this->getMockBuilder(CredentialInterface::class)->getMock()]); 20 | 21 | $value = $factory->build( 22 | $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), 23 | $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), 24 | 'own-id', 25 | $credentialStoreMock 26 | ); 27 | 28 | $this->assertInstanceOf(CredentialStoreInterface::class, $value); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/config.yml: -------------------------------------------------------------------------------- 1 | framework: 2 | secret: secret 3 | test: ~ 4 | router: { resource: "%kernel.root_dir%/routing.yml" } 5 | csrf_protection: false 6 | templating: false 7 | session: 8 | storage_id: session.mock_storage 9 | 10 | services: 11 | session.mock_storage: 12 | class: Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage 13 | 14 | light_saml_symfony_bridge: 15 | own: 16 | entity_id: https://localhost/lightSAML/SymfonyBridgeBundle 17 | credentials: 18 | - 19 | certificate: "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/saml.crt" 20 | key: "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/saml.key" 21 | password: ~ 22 | party: 23 | idp: 24 | files: 25 | - "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/openidp.feide.no.xml" 26 | - "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/localhost-lightsaml-lightsaml-idp.xml" 27 | - "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/testshib-providers.xml" 28 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lightsaml/symfony-bridge", 3 | "license": "MIT", 4 | "type": "symfony-bundle", 5 | "description": "Light SAML Symfony bridge bundle", 6 | "homepage": "http://www.lightsaml.com", 7 | "authors": [ 8 | { 9 | "name": "Milos Tomic", 10 | "email": "tmilos@gmail.com", 11 | "homepage": "http://github.com/tmilos", 12 | "role": "Developer" 13 | } 14 | ], 15 | "autoload": { 16 | "psr-0": { 17 | "LightSaml\\SymfonyBridgeBundle\\Tests\\": "tests/", 18 | "LightSaml\\SymfonyBridgeBundle\\": "src/" 19 | } 20 | }, 21 | "require": { 22 | "php": ">=5.5.1", 23 | "symfony/framework-bundle": "~2.7|~3.0|~4.0", 24 | "symfony/dependency-injection": "~2.7|~3.0|~4.0", 25 | "symfony/yaml": "~2.7|~3.0|~4.0", 26 | "lightsaml/lightsaml": "~1.1" 27 | }, 28 | "require-dev": { 29 | "symfony/browser-kit": "~2.7|~3.0|~4.0", 30 | "symfony/finder": "~2.7|~3.0|~4.0", 31 | "symfony/filesystem": "~2.7|~3.0|~4.0", 32 | "symfony/routing": "~2.7|~3.0|~4.0", 33 | "phpunit/phpunit": "^5.7" 34 | }, 35 | "config": { 36 | "bin-dir": "bin" 37 | }, 38 | "prefer-stable": true, 39 | "minimum-stability": "stable" 40 | } 41 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/BuildContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(SystemContainerInterface::class)->getMock(), 21 | $this->getMockBuilder(PartyContainerInterface::class)->getMock(), 22 | $this->getMockBuilder(StoreContainerInterface::class)->getMock(), 23 | $this->getMockBuilder(ProviderContainerInterface::class)->getMock(), 24 | $this->getMockBuilder(CredentialContainerInterface::class)->getMock(), 25 | $this->getMockBuilder(ServiceContainerInterface::class)->getMock(), 26 | $this->getMockBuilder(OwnContainerInterface::class)->getMock() 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/LightSamlSymfonyBridgeBundle.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle; 13 | 14 | use LightSaml\SymfonyBridgeBundle\DependencyInjection\Compiler\AddMethodCallCompilerPass; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | use Symfony\Component\HttpKernel\Bundle\Bundle; 17 | 18 | class LightSamlSymfonyBridgeBundle extends Bundle 19 | { 20 | public function build(ContainerBuilder $container) 21 | { 22 | parent::build($container); 23 | 24 | $container->addCompilerPass(new AddMethodCallCompilerPass( 25 | 'lightsaml.own.credential_store', 26 | 'lightsaml.own_credential_store', 27 | 'add' 28 | )); 29 | $container->addCompilerPass(new AddMethodCallCompilerPass( 30 | 'lightsaml.party.trust_options_store', 31 | 'lightsaml.trust_options_store', 32 | 'add' 33 | )); 34 | $container->addCompilerPass(new AddMethodCallCompilerPass( 35 | 'lightsaml.party.idp_entity_descriptor_store', 36 | 'lightsaml.idp_entity_store', 37 | 'add' 38 | )); 39 | $container->addCompilerPass(new AddMethodCallCompilerPass( 40 | 'lightsaml.credential.credential_store_factory', 41 | 'lightsaml.credential', 42 | 'addExtraCredential' 43 | )); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Factory/CredentialStoreFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Factory; 13 | 14 | use LightSaml\Credential\CredentialInterface; 15 | use LightSaml\Store\Credential\CredentialStoreInterface; 16 | use LightSaml\Store\Credential\Factory\CredentialFactory; 17 | use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface; 18 | 19 | class CredentialStoreFactory 20 | { 21 | /** 22 | * @param EntityDescriptorStoreInterface $idpEntityDescriptorStore 23 | * @param EntityDescriptorStoreInterface $spEntityDescriptorStore 24 | * @param string $ownEntityId 25 | * @param CredentialStoreInterface $ownCredentialStore 26 | * @param CredentialInterface[] $extraCredentials 27 | * 28 | * @return \LightSaml\Store\Credential\CompositeCredentialStore 29 | */ 30 | public static function build( 31 | EntityDescriptorStoreInterface $idpEntityDescriptorStore, 32 | EntityDescriptorStoreInterface $spEntityDescriptorStore, 33 | $ownEntityId, 34 | CredentialStoreInterface $ownCredentialStore, 35 | array $extraCredentials = null 36 | ) { 37 | $factory = new CredentialFactory(); 38 | 39 | return $factory->build( 40 | $idpEntityDescriptorStore, 41 | $spEntityDescriptorStore, 42 | $ownCredentialStore->getByEntityId($ownEntityId), 43 | $extraCredentials 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ServiceContainerTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(AssertionValidatorInterface::class)->getMock(), 23 | $this->getMockBuilder(AssertionTimeValidatorInterface::class)->getMock(), 24 | $this->getMockBuilder(SignatureResolverInterface::class)->getMock(), 25 | $this->getMockBuilder(EndpointResolverInterface::class)->getMock(), 26 | $this->getMockBuilder(NameIdValidatorInterface::class)->getMock(), 27 | $this->getMockBuilder(BindingFactoryInterface::class)->getMock(), 28 | $this->getMockBuilder(SignatureValidatorInterface::class)->getMock(), 29 | $this->getMockBuilder(CredentialResolverInterface::class)->getMock(), 30 | $this->getMockBuilder(SessionProcessorInterface::class)->getMock() 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Factory/OwnEntityDescriptorProviderFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Factory; 13 | 14 | use LightSaml\Builder\EntityDescriptor\SimpleEntityDescriptorBuilder; 15 | use LightSaml\Credential\X509Credential; 16 | use LightSaml\Store\Credential\CredentialStoreInterface; 17 | use Symfony\Component\Routing\RouterInterface; 18 | 19 | class OwnEntityDescriptorProviderFactory 20 | { 21 | /** 22 | * @param string $ownEntityId 23 | * @param RouterInterface $router 24 | * @param string $acsRouteName 25 | * @param string $ssoRouteName 26 | * @param CredentialStoreInterface $ownCredentialStore 27 | * 28 | * @return SimpleEntityDescriptorBuilder 29 | */ 30 | public static function build( 31 | $ownEntityId, 32 | RouterInterface $router, 33 | $acsRouteName, 34 | $ssoRouteName, 35 | CredentialStoreInterface $ownCredentialStore 36 | ) { 37 | /** @var X509Credential[] $arrOwnCredentials */ 38 | $arrOwnCredentials = $ownCredentialStore->getByEntityId($ownEntityId); 39 | $builder = new SimpleEntityDescriptorBuilder( 40 | $ownEntityId, 41 | $acsRouteName ? $router->generate($acsRouteName, [], RouterInterface::ABSOLUTE_URL) : null, 42 | $ssoRouteName ? $router->generate($ssoRouteName, [], RouterInterface::ABSOLUTE_URL) : null, 43 | $arrOwnCredentials[0]->getCertificate() 44 | ); 45 | 46 | return $builder; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/OwnEntityDescriptorProviderFactoryTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder(RouterInterface::class)->getMock(); 20 | $routerMock->expects($this->exactly(2)) 21 | ->method('generate') 22 | ->with($this->isType('string'), [], RouterInterface::ABSOLUTE_URL) 23 | ->willReturn('http://localhost'); 24 | 25 | $credentialStoreMock = $this->getMockBuilder(CredentialStoreInterface::class)->getMock(); 26 | $credentialStoreMock->method('getByEntityId') 27 | ->with($ownEntityId = 'own-id') 28 | ->willReturn([$credentialMock = $this->getMockBuilder(X509CredentialInterface::class)->getMock()]); 29 | 30 | $credentialMock->method('getCertificate') 31 | ->willReturn($this->getMockBuilder(X509Certificate::class)->getMock()); 32 | 33 | $value = $factory->build( 34 | $ownEntityId, 35 | $routerMock, 36 | 'acs', 37 | 'sso', 38 | $credentialStoreMock 39 | ); 40 | 41 | $this->assertInstanceOf(EntityDescriptorProviderInterface::class, $value); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/OwnContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\OwnContainerInterface; 15 | use LightSaml\Credential\CredentialInterface; 16 | use LightSaml\Provider\EntityDescriptor\EntityDescriptorProviderInterface; 17 | use LightSaml\Store\Credential\CredentialStoreInterface; 18 | 19 | class OwnContainer implements OwnContainerInterface 20 | { 21 | /** @var EntityDescriptorProviderInterface */ 22 | private $entityDescriptorProvider; 23 | 24 | /** @var CredentialStoreInterface */ 25 | private $credentialStore; 26 | 27 | /** @var string */ 28 | private $entityId; 29 | 30 | /** 31 | * @param EntityDescriptorProviderInterface $entityDescriptorProvider 32 | * @param CredentialStoreInterface $credentialStore 33 | * @param string $entityId 34 | */ 35 | public function __construct( 36 | EntityDescriptorProviderInterface $entityDescriptorProvider, 37 | CredentialStoreInterface $credentialStore, 38 | $entityId 39 | ) { 40 | $this->entityDescriptorProvider = $entityDescriptorProvider; 41 | $this->credentialStore = $credentialStore; 42 | $this->entityId = $entityId; 43 | } 44 | 45 | /** 46 | * @return EntityDescriptorProviderInterface 47 | */ 48 | public function getOwnEntityDescriptorProvider() 49 | { 50 | return $this->entityDescriptorProvider; 51 | } 52 | 53 | /** 54 | * @return CredentialInterface[] 55 | */ 56 | public function getOwnCredentials() 57 | { 58 | return $this->credentialStore->getByEntityId( 59 | $this->entityId 60 | ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/StoreContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\StoreContainerInterface; 15 | use LightSaml\Store\Id\IdStoreInterface; 16 | use LightSaml\Store\Request\RequestStateStoreInterface; 17 | use LightSaml\Store\Sso\SsoStateStoreInterface; 18 | 19 | class StoreContainer implements StoreContainerInterface 20 | { 21 | /** @var RequestStateStoreInterface */ 22 | private $requestStateStore; 23 | 24 | /** @var IdStoreInterface */ 25 | private $idStateStore; 26 | 27 | /** @var SsoStateStoreInterface */ 28 | private $ssoStateStore; 29 | 30 | /** 31 | * @param RequestStateStoreInterface $requestStateStore 32 | * @param IdStoreInterface $idStateStore 33 | * @param SsoStateStoreInterface $ssoStateStore 34 | */ 35 | public function __construct( 36 | RequestStateStoreInterface $requestStateStore, 37 | IdStoreInterface $idStateStore, 38 | SsoStateStoreInterface $ssoStateStore 39 | ) { 40 | $this->requestStateStore = $requestStateStore; 41 | $this->idStateStore = $idStateStore; 42 | $this->ssoStateStore = $ssoStateStore; 43 | } 44 | 45 | /** 46 | * @return RequestStateStoreInterface 47 | */ 48 | public function getRequestStateStore() 49 | { 50 | return $this->requestStateStore; 51 | } 52 | 53 | /** 54 | * @return IdStoreInterface 55 | */ 56 | public function getIdStateStore() 57 | { 58 | return $this->idStateStore; 59 | } 60 | 61 | /** 62 | * @return SsoStateStoreInterface 63 | */ 64 | public function getSsoStateStore() 65 | { 66 | return $this->ssoStateStore; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/LightSamlSymfonyBridgeBundleTest.php: -------------------------------------------------------------------------------- 1 | build($containerBuilder); 37 | 38 | $passes = $containerBuilder->getCompilerPassConfig()->getPasses(); 39 | 40 | foreach ($passes as $pass) { 41 | if ($pass instanceof AddMethodCallCompilerPass) { 42 | if ($pass->getServiceId() == $serviceId && 43 | $pass->getTagName() == $tagName && 44 | $pass->getMethodName() == $methodName 45 | ) { 46 | return; 47 | } 48 | } 49 | } 50 | 51 | $this->fail(sprintf('AddMethodCallCompilerPass with arguments "%s", "%s", "%s" not found', $serviceId, $tagName, $methodName)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ProviderContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\ProviderContainerInterface; 15 | use LightSaml\Provider\Attribute\AttributeValueProviderInterface; 16 | use LightSaml\Provider\NameID\NameIdProviderInterface; 17 | use LightSaml\Provider\Session\SessionInfoProviderInterface; 18 | 19 | class ProviderContainer implements ProviderContainerInterface 20 | { 21 | /** @var AttributeValueProviderInterface */ 22 | private $attributeValueProvider; 23 | 24 | /** @var SessionInfoProviderInterface */ 25 | private $sessionInfoProvider; 26 | 27 | /** @var NameIdProviderInterface */ 28 | private $nameIdProvider; 29 | 30 | /** 31 | * @param AttributeValueProviderInterface $attributeValueProvider 32 | * @param SessionInfoProviderInterface $sessionInfoProvider 33 | * @param NameIdProviderInterface $nameIdProvider 34 | */ 35 | public function __construct( 36 | AttributeValueProviderInterface $attributeValueProvider, 37 | SessionInfoProviderInterface $sessionInfoProvider, 38 | NameIdProviderInterface $nameIdProvider 39 | ) { 40 | $this->attributeValueProvider = $attributeValueProvider; 41 | $this->sessionInfoProvider = $sessionInfoProvider; 42 | $this->nameIdProvider = $nameIdProvider; 43 | } 44 | 45 | /** 46 | * @return AttributeValueProviderInterface 47 | */ 48 | public function getAttributeValueProvider() 49 | { 50 | return $this->attributeValueProvider; 51 | } 52 | 53 | /** 54 | * @return SessionInfoProviderInterface 55 | */ 56 | public function getSessionInfoProvider() 57 | { 58 | return $this->sessionInfoProvider; 59 | } 60 | 61 | /** 62 | * @return NameIdProviderInterface 63 | */ 64 | public function getNameIdProvider() 65 | { 66 | return $this->nameIdProvider; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/Compiler/AddMethodCallCompilerPassTest.php: -------------------------------------------------------------------------------- 1 | process($containerBuilder); 24 | 25 | $this->assertFalse($containerBuilder->hasDefinition($serviceId)); 26 | } 27 | 28 | public function test_process_adds_calls_to_service_with_argument_reference_to_all_tagged_services() 29 | { 30 | $pass = new AddMethodCallCompilerPass($serviceId = 'service.id', $tagName = 'tag', $methodName = 'method'); 31 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 32 | 33 | $containerBuilder->setDefinition($serviceId, $serviceDefinition = new Definition()); 34 | $containerBuilder->setDefinition($t1 = 't1', (new Definition())->addTag($tagName)); 35 | $containerBuilder->setDefinition('x', new Definition()); 36 | $containerBuilder->setDefinition($t2 = 't2', (new Definition())->addTag($tagName)); 37 | 38 | $pass->process($containerBuilder); 39 | 40 | $calls = $serviceDefinition->getMethodCalls(); 41 | $this->assertCount(2, $calls); 42 | 43 | $this->assertEquals($methodName, $calls[0][0]); 44 | $this->assertEquals($methodName, $calls[1][0]); 45 | 46 | $this->assertEquals($t1, (string) $calls[0][1][0]); 47 | $this->assertEquals($t2, (string) $calls[1][1][0]); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/PartyContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\PartyContainerInterface; 15 | use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface; 16 | use LightSaml\Store\TrustOptions\TrustOptionsStoreInterface; 17 | 18 | class PartyContainer implements PartyContainerInterface 19 | { 20 | /** @var EntityDescriptorStoreInterface */ 21 | private $idpEntityDescriptorStore; 22 | 23 | /** @var EntityDescriptorStoreInterface */ 24 | private $spEntityDescriptorStore; 25 | 26 | /** @var TrustOptionsStoreInterface */ 27 | private $trustOptionsStore; 28 | 29 | /** 30 | * @param EntityDescriptorStoreInterface $idpEntityDescriptorStore 31 | * @param EntityDescriptorStoreInterface $spEntityDescriptorStore 32 | * @param TrustOptionsStoreInterface $trustOptionsStore 33 | */ 34 | public function __construct( 35 | EntityDescriptorStoreInterface $idpEntityDescriptorStore, 36 | EntityDescriptorStoreInterface $spEntityDescriptorStore, 37 | TrustOptionsStoreInterface $trustOptionsStore 38 | ) { 39 | $this->idpEntityDescriptorStore = $idpEntityDescriptorStore; 40 | $this->spEntityDescriptorStore = $spEntityDescriptorStore; 41 | $this->trustOptionsStore = $trustOptionsStore; 42 | } 43 | 44 | /** 45 | * @return EntityDescriptorStoreInterface 46 | */ 47 | public function getIdpEntityDescriptorStore() 48 | { 49 | return $this->idpEntityDescriptorStore; 50 | } 51 | 52 | /** 53 | * @return EntityDescriptorStoreInterface 54 | */ 55 | public function getSpEntityDescriptorStore() 56 | { 57 | return $this->spEntityDescriptorStore; 58 | } 59 | 60 | /** 61 | * @return TrustOptionsStoreInterface 62 | */ 63 | public function getTrustOptionsStore() 64 | { 65 | return $this->trustOptionsStore; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/DependencyInjection/Compiler/AddMethodCallCompilerPass.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\DependencyInjection\Compiler; 13 | 14 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | use Symfony\Component\DependencyInjection\Reference; 17 | 18 | class AddMethodCallCompilerPass implements CompilerPassInterface 19 | { 20 | /** @var string */ 21 | private $serviceId; 22 | 23 | /** @var string */ 24 | private $tagName; 25 | 26 | /** @var string */ 27 | private $methodName; 28 | 29 | /** 30 | * @param $serviceId 31 | * @param $tagName 32 | * @param $methodName 33 | */ 34 | public function __construct($serviceId, $tagName, $methodName) 35 | { 36 | $this->serviceId = $serviceId; 37 | $this->tagName = $tagName; 38 | $this->methodName = $methodName; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getServiceId() 45 | { 46 | return $this->serviceId; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getTagName() 53 | { 54 | return $this->tagName; 55 | } 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function getMethodName() 61 | { 62 | return $this->methodName; 63 | } 64 | 65 | /** 66 | * @param ContainerBuilder $container 67 | */ 68 | public function process(ContainerBuilder $container) 69 | { 70 | if (false === $container->has($this->serviceId)) { 71 | return; 72 | } 73 | 74 | $definition = $container->findDefinition($this->serviceId); 75 | 76 | $taggedServices = $container->findTaggedServiceIds($this->tagName); 77 | 78 | foreach ($taggedServices as $id => $tags) { 79 | $definition->addMethodCall($this->methodName, [new Reference($id)]); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/SystemContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\SystemContainerInterface; 15 | use LightSaml\Provider\TimeProvider\TimeProviderInterface; 16 | use Psr\Log\LoggerInterface; 17 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; 18 | use Symfony\Component\HttpFoundation\Request; 19 | use Symfony\Component\HttpFoundation\RequestStack; 20 | use Symfony\Component\HttpFoundation\Session\SessionInterface; 21 | 22 | class SystemContainer implements SystemContainerInterface 23 | { 24 | /** @var RequestStack */ 25 | private $requestStack; 26 | 27 | /** @var SessionInterface */ 28 | private $session; 29 | 30 | /** @var TimeProviderInterface */ 31 | private $timeProvider; 32 | 33 | /** @var EventDispatcherInterface */ 34 | private $eventDispatcher; 35 | 36 | /** @var LoggerInterface */ 37 | private $logger; 38 | 39 | /** 40 | * @param RequestStack $requestStack 41 | * @param SessionInterface $session 42 | * @param TimeProviderInterface $timeProvider 43 | * @param EventDispatcherInterface $eventDispatcher 44 | * @param LoggerInterface $logger 45 | */ 46 | public function __construct( 47 | RequestStack $requestStack, 48 | SessionInterface $session, 49 | TimeProviderInterface $timeProvider, 50 | EventDispatcherInterface $eventDispatcher, 51 | LoggerInterface $logger 52 | ) { 53 | $this->requestStack = $requestStack; 54 | $this->session = $session; 55 | $this->timeProvider = $timeProvider; 56 | $this->eventDispatcher = $eventDispatcher; 57 | $this->logger = $logger; 58 | } 59 | 60 | /** 61 | * @return Request 62 | */ 63 | public function getRequest() 64 | { 65 | return $this->requestStack->getCurrentRequest(); 66 | } 67 | 68 | /** 69 | * @return SessionInterface 70 | */ 71 | public function getSession() 72 | { 73 | return $this->session; 74 | } 75 | 76 | /** 77 | * @return TimeProviderInterface 78 | */ 79 | public function getTimeProvider() 80 | { 81 | return $this->timeProvider; 82 | } 83 | 84 | /** 85 | * @return EventDispatcherInterface 86 | */ 87 | public function getEventDispatcher() 88 | { 89 | return $this->eventDispatcher; 90 | } 91 | 92 | /** 93 | * @return LoggerInterface 94 | */ 95 | public function getLogger() 96 | { 97 | return $this->logger; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/container.yml: -------------------------------------------------------------------------------- 1 | services: 2 | lightsaml.container.build: 3 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\BuildContainer 4 | public: true 5 | arguments: 6 | - "@lightsaml.container.system" 7 | - "@lightsaml.container.party" 8 | - "@lightsaml.container.store" 9 | - "@lightsaml.container.provider" 10 | - "@lightsaml.container.credential" 11 | - "@lightsaml.container.service" 12 | - "@lightsaml.container.own" 13 | 14 | lightsaml.container.system: 15 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\SystemContainer 16 | arguments: 17 | - "@request_stack" 18 | - "@session" 19 | - "@lightsaml.system.time_provider" 20 | - "@lightsaml.system.event_dispatcher" 21 | - "@lightsaml.system.logger" 22 | 23 | lightsaml.container.party: 24 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\PartyContainer 25 | arguments: 26 | - "@lightsaml.party.idp_entity_descriptor_store" 27 | - "@lightsaml.party.sp_entity_descriptor_store" 28 | - "@lightsaml.party.trust_options_store" 29 | 30 | lightsaml.container.store: 31 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\StoreContainer 32 | arguments: 33 | - "@lightsaml.store.request" 34 | - "@lightsaml.store.id_state" 35 | - "@lightsaml.store.sso_state" 36 | 37 | lightsaml.container.provider: 38 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\ProviderContainer 39 | arguments: 40 | - "@lightsaml.provider.attribute_value" 41 | - "@lightsaml.provider.session_info" 42 | - "@lightsaml.provider.name_id" 43 | 44 | lightsaml.container.credential: 45 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\CredentialContainer 46 | arguments: 47 | - "@lightsaml.credential.credential_store" 48 | 49 | lightsaml.container.service: 50 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\ServiceContainer 51 | arguments: 52 | - "@lightsaml.service.assertion_validator" 53 | - "@lightsaml.service.assertion_time_validator" 54 | - "@lightsaml.service.signature_resolver" 55 | - "@lightsaml.service.endpoint_resolver" 56 | - "@lightsaml.service.name_id_validator" 57 | - "@lightsaml.service.binding_factory" 58 | - "@lightsaml.service.signature_validator" 59 | - "@lightsaml.service.credential_resolver" 60 | - "@lightsaml.service.session_processor" 61 | 62 | lightsaml.container.own: 63 | class: LightSaml\SymfonyBridgeBundle\Bridge\Container\OwnContainer 64 | arguments: 65 | - "@lightsaml.own.entity_descriptor_provider" 66 | - "@lightsaml.own.credential_store" 67 | - "%lightsaml.own.entity_id%" 68 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\DependencyInjection; 13 | 14 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; 15 | use Symfony\Component\Config\Definition\ConfigurationInterface; 16 | 17 | class Configuration implements ConfigurationInterface 18 | { 19 | /** 20 | * Generates the configuration tree builder. 21 | * 22 | * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder 23 | */ 24 | public function getConfigTreeBuilder() 25 | { 26 | $treeBuilder = new TreeBuilder(); 27 | $root = $treeBuilder->root('light_saml_symfony_bridge'); 28 | 29 | $root->children() 30 | ->arrayNode('own') 31 | ->isRequired() 32 | ->children() 33 | ->scalarNode('entity_id')->isRequired()->cannotBeEmpty()->end() 34 | ->arrayNode('entity_descriptor_provider') 35 | ->children() 36 | ->scalarNode('id')->end() 37 | ->scalarNode('filename')->end() 38 | ->scalarNode('entity_id')->end() 39 | ->end() 40 | ->end() 41 | ->arrayNode('credentials') 42 | ->prototype('array') 43 | ->children() 44 | ->scalarNode('certificate')->end() 45 | ->scalarNode('key')->end() 46 | ->scalarNode('password')->end() 47 | ->end() 48 | ->end() 49 | ->end() 50 | ->end() 51 | ->end() 52 | ->arrayNode('system') 53 | ->children() 54 | ->scalarNode('event_dispatcher')->defaultValue(null)->end() 55 | ->scalarNode('logger')->defaultValue(null)->end() 56 | ->end() 57 | ->end() 58 | ->arrayNode('store') 59 | ->children() 60 | ->scalarNode('request')->end() 61 | ->scalarNode('id_state')->end() 62 | ->scalarNode('sso_state')->end() 63 | ->end() 64 | ->end() 65 | ->arrayNode('party') 66 | ->children() 67 | ->arrayNode('idp') 68 | ->children() 69 | ->arrayNode('files') 70 | ->prototype('scalar')->end() 71 | ->end() 72 | ->end() 73 | ->end() 74 | ->end() 75 | ->end() 76 | ->end(); 77 | 78 | return $treeBuilder; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Resources/config/service.yml: -------------------------------------------------------------------------------- 1 | services: 2 | lightsaml.service.name_id_validator: 3 | class: LightSaml\Validator\Model\NameId\NameIdValidator 4 | 5 | lightsaml.service.statement_validator: 6 | class: LightSaml\Validator\Model\Statement\StatementValidator 7 | 8 | lightsaml.service.subject_validator: 9 | class: LightSaml\Validator\Model\Subject\SubjectValidator 10 | arguments: 11 | - "@lightsaml.service.name_id_validator" 12 | 13 | lightsaml.service.assertion_time_validator: 14 | class: LightSaml\Validator\Model\Assertion\AssertionTimeValidator 15 | 16 | lightsaml.service.assertion_validator: 17 | class: LightSaml\Validator\Model\Assertion\AssertionValidator 18 | arguments: 19 | - "@lightsaml.service.name_id_validator" 20 | - "@lightsaml.service.subject_validator" 21 | - "@lightsaml.service.statement_validator" 22 | 23 | lightsaml.service.endpoint_resolver.binding: 24 | class: LightSaml\Resolver\Endpoint\BindingEndpointResolver 25 | 26 | lightsaml.service.endpoint_resolver.descriptor_type: 27 | class: LightSaml\Resolver\Endpoint\DescriptorTypeEndpointResolver 28 | 29 | lightsaml.service.endpoint_resolver.service_type: 30 | class: LightSaml\Resolver\Endpoint\ServiceTypeEndpointResolver 31 | 32 | lightsaml.service.endpoint_resolver.index: 33 | class: LightSaml\Resolver\Endpoint\IndexEndpointResolver 34 | 35 | lightsaml.service.endpoint_resolver.location: 36 | class: LightSaml\Resolver\Endpoint\LocationEndpointResolver 37 | 38 | lightsaml.service.endpoint_resolver: 39 | class: LightSaml\Resolver\Endpoint\CompositeEndpointResolver 40 | calls: 41 | - [add, ["@lightsaml.service.endpoint_resolver.binding"]] 42 | - [add, ["@lightsaml.service.endpoint_resolver.descriptor_type"]] 43 | - [add, ["@lightsaml.service.endpoint_resolver.service_type"]] 44 | - [add, ["@lightsaml.service.endpoint_resolver.index"]] 45 | - [add, ["@lightsaml.service.endpoint_resolver.location"]] 46 | 47 | lightsaml.service.binding_factory: 48 | class: LightSaml\Binding\BindingFactory 49 | arguments: 50 | - "@lightsaml.system.event_dispatcher" 51 | 52 | lightsaml.service.credential_resolver_factory: 53 | class: LightSaml\Resolver\Credential\Factory\CredentialResolverFactory 54 | arguments: 55 | - "@lightsaml.credential.credential_store" 56 | 57 | lightsaml.service.credential_resolver: 58 | class: LightSaml\Resolver\Credential\CompositeFilterResolver 59 | # factory: ["@lightsaml.service.credential_resolver_factory", build] # set in extension, differently based on symfony version 60 | 61 | lightsaml.service.signature_resolver: 62 | class: LightSaml\Resolver\Signature\OwnSignatureResolver 63 | arguments: 64 | - "@lightsaml.service.credential_resolver" 65 | 66 | lightsaml.service.signature_validator: 67 | class: LightSaml\Validator\Model\Signature\SignatureValidator 68 | arguments: 69 | - "@lightsaml.service.credential_resolver" 70 | 71 | lightsaml.service.session_processor: 72 | class: LightSaml\Resolver\Session\SessionProcessor 73 | arguments: 74 | - "@lightsaml.store.sso_state" 75 | - "@lightsaml.system.time_provider" 76 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/BuildContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Build\Container\BuildContainerInterface; 15 | use LightSaml\Build\Container\CredentialContainerInterface; 16 | use LightSaml\Build\Container\OwnContainerInterface; 17 | use LightSaml\Build\Container\PartyContainerInterface; 18 | use LightSaml\Build\Container\ProviderContainerInterface; 19 | use LightSaml\Build\Container\ServiceContainerInterface; 20 | use LightSaml\Build\Container\StoreContainerInterface; 21 | use LightSaml\Build\Container\SystemContainerInterface; 22 | 23 | class BuildContainer implements BuildContainerInterface 24 | { 25 | /** @var SystemContainerInterface */ 26 | private $systemsystemContainer; 27 | 28 | /** @var PartyContainerInterface */ 29 | private $partypartyContainer; 30 | 31 | /** @var StoreContainerInterface */ 32 | private $storeContainer; 33 | 34 | /** @var OwnContainerInterface */ 35 | private $ownContainer; 36 | 37 | /** @var ProviderContainerInterface */ 38 | private $providerContainer; 39 | 40 | /** @var ServiceContainerInterface */ 41 | private $serviceContainer; 42 | 43 | /** @var CredentialContainerInterface */ 44 | private $credentialContainer; 45 | 46 | /** 47 | * @param SystemContainerInterface $systemContainer 48 | * @param PartyContainerInterface $partyContainer 49 | * @param StoreContainerInterface $storeContainer 50 | * @param ProviderContainerInterface $providerContainer 51 | * @param CredentialContainerInterface $credentialContainer 52 | * @param ServiceContainerInterface $serviceContainer 53 | * @param OwnContainerInterface $ownContainer 54 | */ 55 | public function __construct( 56 | SystemContainerInterface $systemContainer, 57 | PartyContainerInterface $partyContainer, 58 | StoreContainerInterface $storeContainer, 59 | ProviderContainerInterface $providerContainer, 60 | CredentialContainerInterface $credentialContainer, 61 | ServiceContainerInterface $serviceContainer, 62 | OwnContainerInterface $ownContainer 63 | ) { 64 | $this->systemsystemContainer = $systemContainer; 65 | $this->partypartyContainer = $partyContainer; 66 | $this->storeContainer = $storeContainer; 67 | $this->providerContainer = $providerContainer; 68 | $this->credentialContainer = $credentialContainer; 69 | $this->serviceContainer = $serviceContainer; 70 | $this->ownContainer = $ownContainer; 71 | } 72 | 73 | /** 74 | * @return SystemContainerInterface 75 | */ 76 | public function getSystemContainer() 77 | { 78 | return $this->systemsystemContainer; 79 | } 80 | 81 | /** 82 | * @return PartyContainerInterface 83 | */ 84 | public function getPartyContainer() 85 | { 86 | return $this->partypartyContainer; 87 | } 88 | 89 | /** 90 | * @return StoreContainerInterface 91 | */ 92 | public function getStoreContainer() 93 | { 94 | return $this->storeContainer; 95 | } 96 | 97 | /** 98 | * @return ProviderContainerInterface 99 | */ 100 | public function getProviderContainer() 101 | { 102 | return $this->providerContainer; 103 | } 104 | 105 | /** 106 | * @return CredentialContainerInterface 107 | */ 108 | public function getCredentialContainer() 109 | { 110 | return $this->credentialContainer; 111 | } 112 | 113 | /** 114 | * @return ServiceContainerInterface 115 | */ 116 | public function getServiceContainer() 117 | { 118 | return $this->serviceContainer; 119 | } 120 | 121 | /** 122 | * @return OwnContainerInterface 123 | */ 124 | public function getOwnContainer() 125 | { 126 | return $this->ownContainer; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ServiceContainer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; 13 | 14 | use LightSaml\Binding\BindingFactoryInterface; 15 | use LightSaml\Build\Container\ServiceContainerInterface; 16 | use LightSaml\Resolver\Credential\CredentialResolverInterface; 17 | use LightSaml\Resolver\Endpoint\EndpointResolverInterface; 18 | use LightSaml\Resolver\Session\SessionProcessorInterface; 19 | use LightSaml\Resolver\Signature\SignatureResolverInterface; 20 | use LightSaml\Validator\Model\Assertion\AssertionTimeValidatorInterface; 21 | use LightSaml\Validator\Model\Assertion\AssertionValidatorInterface; 22 | use LightSaml\Validator\Model\NameId\NameIdValidatorInterface; 23 | use LightSaml\Validator\Model\Signature\SignatureValidatorInterface; 24 | 25 | class ServiceContainer implements ServiceContainerInterface 26 | { 27 | /** @var AssertionValidatorInterface */ 28 | private $assertionValidator; 29 | 30 | /** @var AssertionTimeValidatorInterface */ 31 | private $assertionTimeValidator; 32 | 33 | /** @var SignatureResolverInterface */ 34 | private $signatureResolver; 35 | 36 | /** @var EndpointResolverInterface */ 37 | private $endpointResolver; 38 | 39 | /** @var NameIdValidatorInterface */ 40 | private $nameIdValidator; 41 | 42 | /** @var BindingFactoryInterface */ 43 | private $bindingFactory; 44 | 45 | /** @var SignatureValidatorInterface */ 46 | private $signatureValidator; 47 | 48 | /** @var CredentialResolverInterface */ 49 | private $credentialResolver; 50 | 51 | /** @var SessionProcessorInterface */ 52 | private $sessionProcessor; 53 | 54 | /** 55 | * @param AssertionValidatorInterface $assertionValidator 56 | * @param AssertionTimeValidatorInterface $assertionTimeValidator 57 | * @param SignatureResolverInterface $signatureResolver 58 | * @param EndpointResolverInterface $endpointResolver 59 | * @param NameIdValidatorInterface $nameIdValidator 60 | * @param BindingFactoryInterface $bindingFactory 61 | * @param SignatureValidatorInterface $signatureValidator 62 | * @param CredentialResolverInterface $credentialResolver 63 | * @param SessionProcessorInterface $sessionProcessor 64 | */ 65 | public function __construct( 66 | AssertionValidatorInterface $assertionValidator, 67 | AssertionTimeValidatorInterface $assertionTimeValidator, 68 | SignatureResolverInterface $signatureResolver, 69 | EndpointResolverInterface $endpointResolver, 70 | NameIdValidatorInterface $nameIdValidator, 71 | BindingFactoryInterface $bindingFactory, 72 | SignatureValidatorInterface $signatureValidator, 73 | CredentialResolverInterface $credentialResolver, 74 | SessionProcessorInterface $sessionProcessor 75 | ) { 76 | $this->assertionValidator = $assertionValidator; 77 | $this->assertionTimeValidator = $assertionTimeValidator; 78 | $this->signatureResolver = $signatureResolver; 79 | $this->endpointResolver = $endpointResolver; 80 | $this->nameIdValidator = $nameIdValidator; 81 | $this->bindingFactory = $bindingFactory; 82 | $this->signatureValidator = $signatureValidator; 83 | $this->credentialResolver = $credentialResolver; 84 | $this->sessionProcessor = $sessionProcessor; 85 | } 86 | 87 | /** 88 | * @return AssertionValidatorInterface 89 | */ 90 | public function getAssertionValidator() 91 | { 92 | return $this->assertionValidator; 93 | } 94 | 95 | /** 96 | * @return AssertionTimeValidatorInterface 97 | */ 98 | public function getAssertionTimeValidator() 99 | { 100 | return $this->assertionTimeValidator; 101 | } 102 | 103 | /** 104 | * @return SignatureResolverInterface 105 | */ 106 | public function getSignatureResolver() 107 | { 108 | return $this->signatureResolver; 109 | } 110 | 111 | /** 112 | * @return EndpointResolverInterface 113 | */ 114 | public function getEndpointResolver() 115 | { 116 | return $this->endpointResolver; 117 | } 118 | 119 | /** 120 | * @return NameIdValidatorInterface 121 | */ 122 | public function getNameIdValidator() 123 | { 124 | return $this->nameIdValidator; 125 | } 126 | 127 | /** 128 | * @return BindingFactoryInterface 129 | */ 130 | public function getBindingFactory() 131 | { 132 | return $this->bindingFactory; 133 | } 134 | 135 | /** 136 | * @return SignatureValidatorInterface 137 | */ 138 | public function getSignatureValidator() 139 | { 140 | return $this->signatureValidator; 141 | } 142 | 143 | /** 144 | * @return CredentialResolverInterface 145 | */ 146 | public function getCredentialResolver() 147 | { 148 | return $this->credentialResolver; 149 | } 150 | 151 | /** 152 | * @return \LightSaml\Resolver\Logout\LogoutSessionResolverInterface 153 | */ 154 | public function getLogoutSessionResolver() 155 | { 156 | throw new \LogicException('Not implemented'); 157 | } 158 | 159 | /** 160 | * @return SessionProcessorInterface 161 | */ 162 | public function getSessionProcessor() 163 | { 164 | return $this->sessionProcessor; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/ConfigurationTest.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'own' => [ 16 | 'entity_id' => 'http://own.id', 17 | ], 18 | ], 19 | ]; 20 | $this->processConfiguration($config); 21 | } 22 | 23 | /** 24 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException 25 | * @expectedExceptionMessage The child node "own" at path "light_saml_symfony_bridge" must be configured 26 | */ 27 | public function test_does_not_allow_empty_config() 28 | { 29 | $config = [ 30 | 'light_saml_symfony_bridge' => [ 31 | 32 | ], 33 | ]; 34 | $this->processConfiguration($config); 35 | } 36 | 37 | public function test_allows_own_entity_descriptor_provider_from_file() 38 | { 39 | $config = [ 40 | 'light_saml_symfony_bridge' => [ 41 | 'own' => [ 42 | 'entity_id' => 'http://own.id', 43 | 'entity_descriptor_provider' => [ 44 | 'filename' => '/some/path', 45 | ], 46 | ], 47 | ], 48 | ]; 49 | $this->processConfiguration($config); 50 | } 51 | 52 | public function test_allows_own_entity_descriptor_provider_from_file_with_entity_id() 53 | { 54 | $config = [ 55 | 'light_saml_symfony_bridge' => [ 56 | 'own' => [ 57 | 'entity_id' => 'http://own.id', 58 | 'entity_descriptor_provider' => [ 59 | 'filename' => '/some/path', 60 | 'entity_id' => 'id', 61 | ], 62 | ], 63 | ], 64 | ]; 65 | $this->processConfiguration($config); 66 | } 67 | 68 | public function test_allows_own_entity_descriptor_provider_from_service() 69 | { 70 | $config = [ 71 | 'light_saml_symfony_bridge' => [ 72 | 'own' => [ 73 | 'entity_id' => 'http://own.id', 74 | 'entity_descriptor_provider' => [ 75 | 'id' => 'some.service', 76 | ], 77 | ], 78 | ], 79 | ]; 80 | $this->processConfiguration($config); 81 | } 82 | 83 | public function test_allows_own_credentials_from_files() 84 | { 85 | $config = [ 86 | 'light_saml_symfony_bridge' => [ 87 | 'own' => [ 88 | 'entity_id' => 'http://own.id', 89 | 'credentials' => [ 90 | [ 91 | 'certificate' => '/some/path.crt', 92 | 'key' => '/some/path.pem', 93 | 'password' => 'aaa', 94 | ], 95 | [ 96 | 'certificate' => '/other/path.crt', 97 | 'key' => '/other/path.pem', 98 | ], 99 | ], 100 | ], 101 | ], 102 | ]; 103 | $this->processConfiguration($config); 104 | } 105 | 106 | public function test_allows_system_event_dispatcher() 107 | { 108 | $config = [ 109 | 'light_saml_symfony_bridge' => [ 110 | 'own' => [ 111 | 'entity_id' => 'http://own.id', 112 | ], 113 | 'system' => [ 114 | 'event_dispatcher' => 'some.id', 115 | ], 116 | ], 117 | ]; 118 | $this->processConfiguration($config); 119 | } 120 | 121 | public function test_allows_system_logger() 122 | { 123 | $config = [ 124 | 'light_saml_symfony_bridge' => [ 125 | 'own' => [ 126 | 'entity_id' => 'http://own.id', 127 | ], 128 | 'system' => [ 129 | 'logger' => 'some.id', 130 | ], 131 | ], 132 | ]; 133 | $this->processConfiguration($config); 134 | } 135 | 136 | public function test_allows_store_request() 137 | { 138 | $config = [ 139 | 'light_saml_symfony_bridge' => [ 140 | 'own' => [ 141 | 'entity_id' => 'http://own.id', 142 | ], 143 | 'store' => [ 144 | 'request' => 'some.id', 145 | ], 146 | ], 147 | ]; 148 | $this->processConfiguration($config); 149 | } 150 | 151 | public function test_allows_store_id_state() 152 | { 153 | $config = [ 154 | 'light_saml_symfony_bridge' => [ 155 | 'own' => [ 156 | 'entity_id' => 'http://own.id', 157 | ], 158 | 'store' => [ 159 | 'id_state' => 'some.id', 160 | ], 161 | ], 162 | ]; 163 | $this->processConfiguration($config); 164 | } 165 | 166 | public function test_allows_store_sso_state() 167 | { 168 | $config = [ 169 | 'light_saml_symfony_bridge' => [ 170 | 'own' => [ 171 | 'entity_id' => 'http://own.id', 172 | ], 173 | 'store' => [ 174 | 'sso_state' => 'some.id', 175 | ], 176 | ], 177 | ]; 178 | $this->processConfiguration($config); 179 | } 180 | 181 | public function test_allows_party_idp_from_files() 182 | { 183 | $config = [ 184 | 'light_saml_symfony_bridge' => [ 185 | 'own' => [ 186 | 'entity_id' => 'http://own.id', 187 | ], 188 | 'party' => [ 189 | 'idp' => [ 190 | 'files' => [ 191 | 'first.xml', 192 | 'second.xml', 193 | ], 194 | ], 195 | ], 196 | ], 197 | ]; 198 | $this->processConfiguration($config); 199 | } 200 | 201 | /** 202 | * @param array $configs 203 | * 204 | * @return array 205 | */ 206 | protected function processConfiguration(array $configs) 207 | { 208 | $configuration = new Configuration(); 209 | $processor = new Processor(); 210 | 211 | return $processor->processConfiguration($configuration, $configs); 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/FunctionalTest.php: -------------------------------------------------------------------------------- 1 | remove(__DIR__.'/cache'); 45 | } 46 | 47 | protected static function getKernelClass() 48 | { 49 | return TestKernel::class; 50 | } 51 | 52 | public function test_build_container() 53 | { 54 | static::createClient(); 55 | /** @var BuildContainerInterface $buildContainer */ 56 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 57 | $this->assertInstanceOf(BuildContainerInterface::class, $buildContainer); 58 | $this->assertInstanceOf(SystemContainerInterface::class, $buildContainer->getSystemContainer()); 59 | $this->assertInstanceOf(OwnContainerInterface::class, $buildContainer->getOwnContainer()); 60 | $this->assertInstanceOf(PartyContainerInterface::class, $buildContainer->getPartyContainer()); 61 | $this->assertInstanceOf(StoreContainerInterface::class, $buildContainer->getStoreContainer()); 62 | } 63 | 64 | public function test_system_container() { 65 | static::createClient(); 66 | /** @var BuildContainerInterface $buildContainer */ 67 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 68 | $systemContainer = $buildContainer->getSystemContainer(); 69 | $this->assertInstanceOf(EventDispatcherInterface::class, $systemContainer->getEventDispatcher()); 70 | $this->assertInstanceOf(LoggerInterface::class, $systemContainer->getLogger()); 71 | $this->assertInstanceOf(TimeProviderInterface::class, $systemContainer->getTimeProvider()); 72 | } 73 | 74 | public function test_party_container() 75 | { 76 | static::createClient(); 77 | /** @var BuildContainerInterface $buildContainer */ 78 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 79 | $partyContainer = $buildContainer->getPartyContainer(); 80 | $this->assertInstanceOf(EntityDescriptorStoreInterface::class, $partyContainer->getIdpEntityDescriptorStore()); 81 | $this->assertInstanceOf(EntityDescriptorStoreInterface::class, $partyContainer->getSpEntityDescriptorStore()); 82 | $this->assertInstanceOf(TrustOptionsStoreInterface::class, $partyContainer->getTrustOptionsStore()); 83 | } 84 | 85 | public function test_store_container() 86 | { 87 | static::createClient(); 88 | /** @var BuildContainerInterface $buildContainer */ 89 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 90 | $storeContainer = $buildContainer->getStoreContainer(); 91 | $this->assertInstanceOf(RequestStateStoreInterface::class, $storeContainer->getRequestStateStore()); 92 | $this->assertInstanceOf(IdStoreInterface::class, $storeContainer->getIdStateStore()); 93 | $this->assertInstanceOf(SsoStateStoreInterface::class, $storeContainer->getSsoStateStore()); 94 | } 95 | 96 | public function test_provider_container() 97 | { 98 | static::createClient(); 99 | /** @var BuildContainerInterface $buildContainer */ 100 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 101 | $providerContainer = $buildContainer->getProviderContainer(); 102 | $this->assertInstanceOf(AttributeValueProviderInterface::class, $providerContainer->getAttributeValueProvider()); 103 | $this->assertInstanceOf(SessionInfoProviderInterface::class, $providerContainer->getSessionInfoProvider()); 104 | $this->assertInstanceOf(NameIdProviderInterface::class, $providerContainer->getNameIdProvider()); 105 | } 106 | 107 | public function test_credential_container() 108 | { 109 | static::createClient(); 110 | /** @var BuildContainerInterface $buildContainer */ 111 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 112 | $credentialContainer = $buildContainer->getCredentialContainer(); 113 | $this->assertInstanceOf(CredentialStoreInterface::class, $credentialContainer->getCredentialStore()); 114 | } 115 | 116 | public function test_service_container() 117 | { 118 | static::createClient(); 119 | /** @var BuildContainerInterface $buildContainer */ 120 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 121 | $serviceContainer = $buildContainer->getServiceContainer(); 122 | $this->assertInstanceOf(AssertionValidatorInterface::class, $serviceContainer->getAssertionValidator()); 123 | $this->assertInstanceOf(AssertionTimeValidatorInterface::class, $serviceContainer->getAssertionTimeValidator()); 124 | $this->assertInstanceOf(SignatureResolverInterface::class, $serviceContainer->getSignatureResolver()); 125 | $this->assertInstanceOf(EndpointResolverInterface::class, $serviceContainer->getEndpointResolver()); 126 | $this->assertInstanceOf(NameIdValidatorInterface::class, $serviceContainer->getNameIdValidator()); 127 | $this->assertInstanceOf(BindingFactoryInterface::class, $serviceContainer->getBindingFactory()); 128 | $this->assertInstanceOf(SignatureValidatorInterface::class, $serviceContainer->getSignatureValidator()); 129 | $this->assertInstanceOf(CredentialResolverInterface::class, $serviceContainer->getCredentialResolver()); 130 | $this->assertInstanceOf(SessionProcessorInterface::class, $serviceContainer->getSessionProcessor()); 131 | } 132 | 133 | 134 | public function test_own_container() 135 | { 136 | static::createClient(); 137 | /** @var BuildContainerInterface $buildContainer */ 138 | $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); 139 | $ownContainer = $buildContainer->getOwnContainer(); 140 | $this->assertInstanceOf(EntityDescriptorProviderInterface::class, $ownContainer->getOwnEntityDescriptorProvider()); 141 | $this->assertInternalType('array', $ownContainer->getOwnCredentials()); 142 | array_map(function ($credential) { 143 | $this->assertInstanceOf(CredentialInterface::class, $credential); 144 | }, $ownContainer->getOwnCredentials()); 145 | } 146 | } -------------------------------------------------------------------------------- /src/LightSaml/SymfonyBridgeBundle/DependencyInjection/LightSamlSymfonyBridgeExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace LightSaml\SymfonyBridgeBundle\DependencyInjection; 13 | 14 | use Symfony\Component\DependencyInjection\ContainerBuilder; 15 | use Symfony\Component\Config\FileLocator; 16 | use Symfony\Component\DependencyInjection\ChildDefinition; 17 | use Symfony\Component\DependencyInjection\Definition; 18 | use Symfony\Component\DependencyInjection\DefinitionDecorator; 19 | use Symfony\Component\DependencyInjection\Reference; 20 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; 21 | use Symfony\Component\DependencyInjection\Loader; 22 | 23 | class LightSamlSymfonyBridgeExtension extends Extension 24 | { 25 | /** 26 | * Loads a specific configuration. 27 | * 28 | * @param array $config An array of configuration values 29 | * @param ContainerBuilder $container A ContainerBuilder instance 30 | * 31 | * @throws \InvalidArgumentException When provided tag is not defined in this extension 32 | * 33 | * @api 34 | */ 35 | public function load(array $config, ContainerBuilder $container) 36 | { 37 | $configuration = new Configuration(); 38 | $config = $this->processConfiguration($configuration, $config); 39 | 40 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 41 | $loader->load('container.yml'); 42 | $loader->load('own.yml'); 43 | $loader->load('system.yml'); 44 | $loader->load('party.yml'); 45 | $loader->load('store.yml'); 46 | $loader->load('credential.yml'); 47 | $loader->load('service.yml'); 48 | $loader->load('provider.yml'); 49 | $loader->load('profile.yml'); 50 | 51 | $this->configureOwn($container, $config); 52 | $this->configureSystem($container, $config); 53 | $this->configureParty($container, $config); 54 | $this->configureStore($container, $config); 55 | $this->configureCredential($container, $config); 56 | $this->configureService($container, $config); 57 | } 58 | 59 | private function configureCredential(ContainerBuilder $container, array $config) 60 | { 61 | $this->configureCredentialStore($container, $config); 62 | } 63 | 64 | private function configureCredentialStore(ContainerBuilder $container, array $config) 65 | { 66 | $factoryReference = new Reference('lightsaml.credential.credential_store_factory'); 67 | $definition = $container->getDefinition('lightsaml.credential.credential_store'); 68 | $this->setFactoryCompatibleWay($definition, $factoryReference, 'buildFromOwnCredentialStore'); 69 | } 70 | 71 | private function configureService(ContainerBuilder $container, array $config) 72 | { 73 | $this->configureServiceCredentialResolver($container, $config); 74 | } 75 | 76 | private function configureServiceCredentialResolver(ContainerBuilder $container, array $config) 77 | { 78 | $factoryReference = new Reference('lightsaml.service.credential_resolver_factory'); 79 | $definition = $container->getDefinition('lightsaml.service.credential_resolver'); 80 | $this->setFactoryCompatibleWay($definition, $factoryReference, 'build'); 81 | } 82 | 83 | private function configureOwn(ContainerBuilder $container, array $config) 84 | { 85 | $container->setParameter('lightsaml.own.entity_id', $config['own']['entity_id']); 86 | 87 | $this->configureOwnEntityDescriptor($container, $config); 88 | $this->configureOwnCredentials($container, $config); 89 | } 90 | 91 | private function configureOwnEntityDescriptor(ContainerBuilder $container, array $config) 92 | { 93 | if (isset($config['own']['entity_descriptor_provider']['id'])) { 94 | $container->setAlias('lightsaml.own.entity_descriptor_provider', $config['own']['entity_descriptor_provider']['id']); 95 | } elseif (isset($config['own']['entity_descriptor_provider']['filename'])) { 96 | if (isset($config['own']['entity_descriptor_provider']['entity_id'])) { 97 | $definition = $container->setDefinition('lightsaml.own.entity_descriptor_provider', new Definition()); 98 | $definition 99 | ->addArgument($config['own']['entity_descriptor_provider']['filename']) 100 | ->addArgument($config['own']['entity_descriptor_provider']['entity_id']); 101 | $this->setFactoryCompatibleWay($definition, 'LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntitiesDescriptorFile'); 102 | } else { 103 | $definition = $container->setDefinition('lightsaml.own.entity_descriptor_provider', new Definition()) 104 | ->addArgument($config['own']['entity_descriptor_provider']['filename']); 105 | $this->setFactoryCompatibleWay($definition, 'LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntityDescriptorFile'); 106 | } 107 | } else { 108 | $definition = $container->getDefinition('lightsaml.own.entity_descriptor_provider'); 109 | $definition 110 | ->addArgument('%lightsaml.own.entity_id%') 111 | ->addArgument(new Reference('router')) 112 | ->addArgument('%lightsaml.route.login_check%') 113 | ->addArgument(null) 114 | ->addArgument(new Reference('lightsaml.own.credential_store')) 115 | ; 116 | $this->setFactoryCompatibleWay($definition, 'LightSaml\SymfonyBridgeBundle\Factory\OwnEntityDescriptorProviderFactory', 'build'); 117 | } 118 | } 119 | 120 | private function configureOwnCredentials(ContainerBuilder $container, array $config) 121 | { 122 | if (false === isset($config['own']['credentials'])) { 123 | return; 124 | } 125 | 126 | foreach ($config['own']['credentials'] as $id => $data) { 127 | $definition = new Definition( 128 | 'LightSaml\Store\Credential\X509FileCredentialStore', 129 | [ 130 | $config['own']['entity_id'], 131 | $data['certificate'], 132 | $data['key'], 133 | $data['password'], 134 | ] 135 | ); 136 | $definition->addTag('lightsaml.own_credential_store'); 137 | $container->setDefinition('lightsaml.own.credential_store.'.$id, $definition); 138 | } 139 | } 140 | 141 | private function configureSystem(ContainerBuilder $container, array $config) 142 | { 143 | if (isset($config['system']['event_dispatcher'])) { 144 | $container->removeDefinition('lightsaml.system.event_dispatcher'); 145 | $container->setAlias('lightsaml.system.event_dispatcher', $config['system']['event_dispatcher']); 146 | } 147 | 148 | if (isset($config['system']['logger'])) { 149 | $container->setAlias('lightsaml.system.logger', $config['system']['logger']); 150 | } 151 | } 152 | 153 | private function configureParty(ContainerBuilder $container, array $config) 154 | { 155 | if (isset($config['party']['idp']['files'])) { 156 | $store = $container->getDefinition('lightsaml.party.idp_entity_descriptor_store'); 157 | foreach ($config['party']['idp']['files'] as $id => $file) { 158 | $id = sprintf('lightsaml.party.idp_entity_descriptor_store.file.%s', $id); 159 | 160 | if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) { 161 | // Symfony >= 3.3 162 | $container 163 | ->setDefinition($id, new ChildDefinition('lightsaml.party.idp_entity_descriptor_store.file')) 164 | ->replaceArgument(0, $file); 165 | } else { 166 | // Symfony < 3.3 167 | $container 168 | ->setDefinition($id, new DefinitionDecorator('lightsaml.party.idp_entity_descriptor_store.file')) 169 | ->replaceArgument(0, $file); 170 | } 171 | 172 | $store->addMethodCall('add', [new Reference($id)]); 173 | } 174 | } 175 | } 176 | 177 | private function configureStore(ContainerBuilder $container, array $config) 178 | { 179 | if (isset($config['store']['request'])) { 180 | $container->setAlias('lightsaml.store.request', $config['store']['request']); 181 | } 182 | if (isset($config['store']['id_state'])) { 183 | $container->setAlias('lightsaml.store.id_state', $config['store']['id_state']); 184 | } 185 | if (isset($config['store']['sso_state'])) { 186 | $container->setAlias('lightsaml.store.sso_state', $config['store']['sso_state']); 187 | } 188 | } 189 | 190 | /** 191 | * @param Definition $definition 192 | * @param string $classOrReference 193 | * @param string $method 194 | */ 195 | private function setFactoryCompatibleWay(Definition $definition, $classOrReference, $method) 196 | { 197 | if (method_exists($definition, 'setFactory')) { 198 | $definition->setFactory([$classOrReference, $method]); 199 | } else { 200 | if ($classOrReference instanceof Reference) { 201 | $definition->setFactoryService((string) $classOrReference); 202 | } else { 203 | $definition->setFactoryClass($classOrReference); 204 | } 205 | $definition->setFactoryMethod($method); 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/LightSamlSymfonyBridgeExtensionTest.php: -------------------------------------------------------------------------------- 1 | getDefaultConfig(); 17 | 18 | $extension->load($config, $containerBuilder); 19 | } 20 | 21 | public function test_loads_build_container() 22 | { 23 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 24 | $extension = new LightSamlSymfonyBridgeExtension(); 25 | $config = $this->getDefaultConfig(); 26 | $extension->load($config, $containerBuilder); 27 | 28 | $this->assertTrue($containerBuilder->hasDefinition('lightsaml.container.build')); 29 | $this->assertEquals('LightSaml\SymfonyBridgeBundle\Bridge\Container\BuildContainer', $containerBuilder->getDefinition('lightsaml.container.build')->getClass()); 30 | } 31 | 32 | public function test_set_entity_id_parameter_from_configuration() 33 | { 34 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 35 | $extension = new LightSamlSymfonyBridgeExtension(); 36 | $config = $this->getDefaultConfig(); 37 | $extension->load($config, $containerBuilder); 38 | 39 | $this->assertEquals($config['light_saml_symfony_bridge']['own']['entity_id'], $containerBuilder->getParameter('lightsaml.own.entity_id')); 40 | } 41 | 42 | public function test_sets_own_entity_descriptor_provider_factory_from_entity_descriptor_file() 43 | { 44 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 45 | $extension = new LightSamlSymfonyBridgeExtension(); 46 | $config = $this->getDefaultConfig(); 47 | $config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['filename'] = 'file.xml'; 48 | $extension->load($config, $containerBuilder); 49 | 50 | $this->assertTrue($containerBuilder->hasDefinition('lightsaml.own.entity_descriptor_provider')); 51 | $definition = $containerBuilder->getDefinition('lightsaml.own.entity_descriptor_provider'); 52 | if (method_exists($definition, 'getFactory')) { 53 | $this->assertEquals( 54 | ['LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntityDescriptorFile'], 55 | $definition->getFactory() 56 | ); 57 | } else { 58 | $this->assertEquals('LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', $definition->getFactoryClass()); 59 | $this->assertEquals('fromEntityDescriptorFile', $definition->getFactoryMethod()); 60 | } 61 | $this->assertCount(1, $definition->getArguments()); 62 | $this->assertEquals($config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['filename'], $definition->getArgument(0)); 63 | } 64 | 65 | public function test_sets_swn_entity_descriptor_provider_factory_from_entities_descriptor_file_and_entity_id() 66 | { 67 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 68 | $extension = new LightSamlSymfonyBridgeExtension(); 69 | $config = $this->getDefaultConfig(); 70 | $config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['filename'] = 'file.xml'; 71 | $config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['entity_id'] = 'some-id'; 72 | $extension->load($config, $containerBuilder); 73 | 74 | $this->assertTrue($containerBuilder->hasDefinition('lightsaml.own.entity_descriptor_provider')); 75 | $definition = $containerBuilder->getDefinition('lightsaml.own.entity_descriptor_provider'); 76 | if (method_exists($definition, 'getFactory')) { 77 | $this->assertEquals( 78 | ['LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntitiesDescriptorFile'], 79 | $definition->getFactory() 80 | ); 81 | } else { 82 | $this->assertEquals('LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', $definition->getFactoryClass()); 83 | $this->assertEquals('fromEntitiesDescriptorFile', $definition->getFactoryMethod()); 84 | } 85 | $this->assertCount(2, $definition->getArguments()); 86 | $this->assertEquals($config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['filename'], $definition->getArgument(0)); 87 | $this->assertEquals($config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['entity_id'], $definition->getArgument(1)); 88 | } 89 | 90 | public function test_sets_own_entity_descriptor_provider_to_custom_alias() 91 | { 92 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 93 | $extension = new LightSamlSymfonyBridgeExtension(); 94 | $config = $this->getDefaultConfig(); 95 | $config['light_saml_symfony_bridge']['own']['entity_descriptor_provider']['id'] = $expectedAlias = 'some.factory'; 96 | 97 | $extension->load($config, $containerBuilder); 98 | 99 | $this->assertTrue($containerBuilder->hasAlias('lightsaml.own.entity_descriptor_provider')); 100 | $this->assertEquals($expectedAlias, (string) $containerBuilder->getAlias('lightsaml.own.entity_descriptor_provider')); 101 | } 102 | 103 | public function test_adds_own_file_credentials() 104 | { 105 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 106 | $extension = new LightSamlSymfonyBridgeExtension(); 107 | $config = $this->getDefaultConfig(); 108 | $config['light_saml_symfony_bridge']['own']['credentials'] = [ 109 | [ 110 | 'certificate' => $firstCertificate = 'first.crt', 111 | 'key' => $firstKey = 'first.key', 112 | 'password' => $firstPassword = 'pw1', 113 | ], 114 | [ 115 | 'certificate' => $secondCertificate = 'second.crt', 116 | 'key' => $secondKey = 'second.key', 117 | 'password' => $secondPassword = null, 118 | ], 119 | ]; 120 | 121 | $extension->load($config, $containerBuilder); 122 | 123 | $taggedServices = $containerBuilder->findTaggedServiceIds('lightsaml.own_credential_store'); 124 | 125 | $this->assertCount(2, $taggedServices); 126 | 127 | $this->assertTrue($containerBuilder->has('lightsaml.own.credential_store.0')); 128 | $definition = $containerBuilder->getDefinition('lightsaml.own.credential_store.0'); 129 | $this->assertEquals(\LightSaml\Store\Credential\X509FileCredentialStore::class, $definition->getClass()); 130 | $this->assertCount(4, $definition->getArguments()); 131 | $this->assertEquals($config['light_saml_symfony_bridge']['own']['entity_id'], $definition->getArgument(0)); 132 | $this->assertEquals($firstCertificate, $definition->getArgument(1)); 133 | $this->assertEquals($firstKey, $definition->getArgument(2)); 134 | $this->assertEquals($firstPassword, $definition->getArgument(3)); 135 | 136 | $this->assertTrue($containerBuilder->has('lightsaml.own.credential_store.1')); 137 | $definition = $containerBuilder->getDefinition('lightsaml.own.credential_store.1'); 138 | $this->assertEquals(\LightSaml\Store\Credential\X509FileCredentialStore::class, $definition->getClass()); 139 | $this->assertCount(4, $definition->getArguments()); 140 | $this->assertEquals($config['light_saml_symfony_bridge']['own']['entity_id'], $definition->getArgument(0)); 141 | $this->assertEquals($secondCertificate, $definition->getArgument(1)); 142 | $this->assertEquals($secondKey, $definition->getArgument(2)); 143 | $this->assertEquals($secondPassword, $definition->getArgument(3)); 144 | } 145 | 146 | public function test_adds_idp_entities_from_file() 147 | { 148 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 149 | $extension = new LightSamlSymfonyBridgeExtension(); 150 | $config = $this->getDefaultConfig(); 151 | $config['light_saml_symfony_bridge']['party']['idp']['files'] = [ 152 | $idp1 = 'first.xml', 153 | $idp2 = 'second.xml', 154 | ]; 155 | 156 | $extension->load($config, $containerBuilder); 157 | 158 | $this->assertTrue($containerBuilder->has('lightsaml.party.idp_entity_descriptor_store.file.0')); 159 | $this->assertTrue($containerBuilder->has('lightsaml.party.idp_entity_descriptor_store.file.1')); 160 | 161 | $this->assertEquals($idp1, $containerBuilder->getDefinition('lightsaml.party.idp_entity_descriptor_store.file.0')->getArgument(0)); 162 | $this->assertEquals($idp2, $containerBuilder->getDefinition('lightsaml.party.idp_entity_descriptor_store.file.1')->getArgument(0)); 163 | 164 | $storeDefinition = $containerBuilder->getDefinition('lightsaml.party.idp_entity_descriptor_store'); 165 | $calls = $storeDefinition->getMethodCalls(); 166 | 167 | $this->assertCount(2, $calls); 168 | 169 | $this->assertEquals('add', $calls[0][0]); 170 | $this->assertEquals('lightsaml.party.idp_entity_descriptor_store.file.0', (string) $calls[0][1][0]); 171 | 172 | $this->assertEquals('add', $calls[1][0]); 173 | $this->assertEquals('lightsaml.party.idp_entity_descriptor_store.file.1', (string) $calls[1][1][0]); 174 | } 175 | 176 | public function test_sets_store_request_alias() 177 | { 178 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 179 | $extension = new LightSamlSymfonyBridgeExtension(); 180 | $config = $this->getDefaultConfig(); 181 | $config['light_saml_symfony_bridge']['store']['request'] = $expected = 'service.id'; 182 | 183 | $extension->load($config, $containerBuilder); 184 | 185 | $this->assertEquals($expected, (string) $containerBuilder->getAlias('lightsaml.store.request')); 186 | } 187 | 188 | public function test_sets_store_id_state_alias() 189 | { 190 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 191 | $extension = new LightSamlSymfonyBridgeExtension(); 192 | $config = $this->getDefaultConfig(); 193 | $config['light_saml_symfony_bridge']['store']['id_state'] = $expected = 'service.id'; 194 | 195 | $extension->load($config, $containerBuilder); 196 | 197 | $this->assertEquals($expected, (string) $containerBuilder->getAlias('lightsaml.store.id_state')); 198 | } 199 | 200 | public function test_sets_store_sso_state_alias() 201 | { 202 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 203 | $extension = new LightSamlSymfonyBridgeExtension(); 204 | $config = $this->getDefaultConfig(); 205 | $config['light_saml_symfony_bridge']['store']['sso_state'] = $expected = 'service.id'; 206 | 207 | $extension->load($config, $containerBuilder); 208 | 209 | $this->assertEquals($expected, (string) $containerBuilder->getAlias('lightsaml.store.sso_state')); 210 | } 211 | 212 | public function test_loads_own_credential_store() 213 | { 214 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 215 | $extension = new LightSamlSymfonyBridgeExtension(); 216 | $config = $this->getDefaultConfig(); 217 | 218 | $extension->load($config, $containerBuilder); 219 | 220 | $this->assertTrue($containerBuilder->hasDefinition('lightsaml.own.credential_store')); 221 | $definition = $containerBuilder->getDefinition('lightsaml.own.credential_store'); 222 | $this->assertEquals('LightSaml\Store\Credential\CompositeCredentialStore', $definition->getClass()); 223 | } 224 | 225 | public function testLoadsSystemTimeProvider() 226 | { 227 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 228 | $extension = new LightSamlSymfonyBridgeExtension(); 229 | $config = $this->getDefaultConfig(); 230 | 231 | $extension->load($config, $containerBuilder); 232 | 233 | $this->assertTrue($containerBuilder->hasDefinition('lightsaml.system.time_provider')); 234 | } 235 | 236 | public function test_loads_system_event_dispatcher() 237 | { 238 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 239 | $extension = new LightSamlSymfonyBridgeExtension(); 240 | $config = $this->getDefaultConfig(); 241 | 242 | $extension->load($config, $containerBuilder); 243 | 244 | $this->assertTrue($containerBuilder->hasDefinition('lightsaml.system.event_dispatcher')); 245 | } 246 | 247 | public function test_loads_system_custom_event_dispatcher() 248 | { 249 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 250 | $extension = new LightSamlSymfonyBridgeExtension(); 251 | $config = $this->getDefaultConfig(); 252 | $config['light_saml_symfony_bridge']['system']['event_dispatcher'] = $expectedAlias = 'some.service'; 253 | 254 | $extension->load($config, $containerBuilder); 255 | 256 | $this->assertTrue($containerBuilder->hasAlias('lightsaml.system.event_dispatcher')); 257 | $this->assertEquals($expectedAlias, (string) $containerBuilder->getAlias('lightsaml.system.event_dispatcher')); 258 | } 259 | 260 | public function test_loads_system_logger_when_given_in_config() 261 | { 262 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 263 | $extension = new LightSamlSymfonyBridgeExtension(); 264 | $config = $this->getDefaultConfig(); 265 | $config['light_saml_symfony_bridge']['system']['logger'] = 'some.logger'; 266 | 267 | $extension->load($config, $containerBuilder); 268 | 269 | $this->assertTrue($containerBuilder->hasAlias('lightsaml.system.logger')); 270 | } 271 | 272 | public function test_loads_system_custom_logger() 273 | { 274 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 275 | $extension = new LightSamlSymfonyBridgeExtension(); 276 | $config = $this->getDefaultConfig(); 277 | $config['light_saml_symfony_bridge']['system']['logger'] = $expectedAlias = 'some.service'; 278 | 279 | $extension->load($config, $containerBuilder); 280 | 281 | $this->assertTrue($containerBuilder->hasAlias('lightsaml.system.logger')); 282 | $this->assertEquals($expectedAlias, (string) $containerBuilder->getAlias('lightsaml.system.logger')); 283 | } 284 | 285 | public function profile_provider() 286 | { 287 | return [ 288 | ['ligthsaml.profile.metadata'], 289 | ['ligthsaml.profile.login_factory'], 290 | ['ligthsaml.profile.acs'], 291 | ]; 292 | } 293 | /** 294 | * @dataProvider profile_provider 295 | */ 296 | public function test_loads_public_profile($id) 297 | { 298 | $containerBuilder = new ContainerBuilder(new ParameterBag()); 299 | $extension = new LightSamlSymfonyBridgeExtension(); 300 | $config = $this->getDefaultConfig(); 301 | $extension->load($config, $containerBuilder); 302 | 303 | $this->assertTrue($containerBuilder->hasDefinition('ligthsaml.profile.metadata')); 304 | $defn = $containerBuilder->getDefinition('ligthsaml.profile.metadata'); 305 | $this->assertTrue($defn->isPublic()); 306 | } 307 | 308 | private function getDefaultConfig() 309 | { 310 | return [ 311 | 'light_saml_symfony_bridge' => [ 312 | 'own' => [ 313 | 'entity_id' => 'http://localhost/symfony-bridge', 314 | ], 315 | ], 316 | ]; 317 | } 318 | } 319 | --------------------------------------------------------------------------------