2020
2121use Surfnet \SamlBundle \Entity \IdentityProvider ;
2222use Surfnet \SamlBundle \Entity \ServiceProvider ;
23+ use Surfnet \SamlBundle \Entity \StaticIdentityProviderRepository ;
2324use Surfnet \SamlBundle \Entity \StaticServiceProviderRepository ;
2425use Surfnet \SamlBundle \Exception \SamlInvalidConfigurationException ;
2526use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
@@ -149,20 +150,46 @@ private function parseMetadataConfiguration(array $configuration, ContainerBuild
149150 */
150151 private function parseRemoteConfiguration (array $ remoteConfiguration , ContainerBuilder $ container )
151152 {
152- $ this ->parseRemoteIdentityProviderConfiguration ($ remoteConfiguration ['identity_provider ' ], $ container );
153153 $ this ->parseRemoteServiceProviderConfigurations ($ remoteConfiguration ['service_providers ' ], $ container );
154+
155+ // Parse a configuration where multiple remote IDPs are configured (identity_providers:)
156+ $ this ->parseRemoteIdentityProviderConfigurations ($ remoteConfiguration ['identity_providers ' ], $ container );
157+
158+ // Parse a single remote IDP configuration (identity_provider:)
159+ if (!empty ($ remoteConfiguration ['identity_provider ' ]['enabled ' ])) {
160+ $ definition = $ this ->parseRemoteIdentityProviderConfiguration ($ remoteConfiguration ['identity_provider ' ]);
161+
162+ if ($ definition !== null ) {
163+ $ container ->setDefinition ('surfnet_saml.remote.idp ' , $ definition );
164+ }
165+ }
154166 }
155167
156168 /**
157- * @param array $identityProvider
158- * @param ContainerBuilder $container
169+ * @param array $identityProviders
170+ * @param $container
171+ * @throws \Surfnet\SamlBundle\Exception\SamlInvalidConfigurationException
159172 */
160- private function parseRemoteIdentityProviderConfiguration (array $ identityProvider , ContainerBuilder $ container )
173+ private function parseRemoteIdentityProviderConfigurations (array $ identityProviders , ContainerBuilder $ container )
161174 {
162- if (!$ identityProvider ['enabled ' ]) {
163- return ;
164- }
175+ $ definitions = array_map (function ($ config ) {
176+ return $ this ->parseRemoteIdentityProviderConfiguration ($ config );
177+ }, $ identityProviders );
178+
179+ $ definition = new Definition (StaticIdentityProviderRepository::class, [
180+ $ definitions
181+ ]);
182+ $ definition ->setPublic (true );
183+ $ container ->setDefinition ('surfnet_saml.remote.identity_providers ' , $ definition );
184+ }
165185
186+ /**
187+ * @param array $identityProvider
188+ *
189+ * @return Definition
190+ */
191+ private function parseRemoteIdentityProviderConfiguration (array $ identityProvider )
192+ {
166193 $ definition = new Definition (IdentityProvider::class);
167194 $ configuration = [
168195 'entityId ' => $ identityProvider ['entity_id ' ],
@@ -175,7 +202,9 @@ private function parseRemoteIdentityProviderConfiguration(array $identityProvide
175202 );
176203
177204 $ definition ->setArguments ([$ configuration ]);
178- $ container ->setDefinition ('surfnet_saml.remote.idp ' , $ definition );
205+ $ definition ->setPublic (true );
206+
207+ return $ definition ;
179208 }
180209
181210 /**
@@ -192,6 +221,7 @@ private function parseRemoteServiceProviderConfigurations(array $serviceProvider
192221 $ definition = new Definition (StaticServiceProviderRepository::class, [
193222 $ definitions
194223 ]);
224+ $ definition ->setPublic (true );
195225 $ container ->setDefinition ('surfnet_saml.remote.service_providers ' , $ definition );
196226 }
197227
0 commit comments