Skip to content

Commit

Permalink
Service definitions not compatible with Symfony 2.3 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos committed Feb 11, 2016
1 parent b95b54f commit d56ada3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"symfony/framework-bundle": "~2.3|~3.0",
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0",
"lightsaml/lightsaml": "~1.0"
"lightsaml/lightsaml": "^1.0.7"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ public function load(array $config, ContainerBuilder $container)
$this->configureSystem($container, $config);
$this->configureParty($container, $config);
$this->configureStore($container, $config);
$this->configureCredential($container, $config);
$this->configureService($container, $config);
}

private function configureCredential(ContainerBuilder $container, array $config)
{
$this->configureCredentialStore($container, $config);
}

private function configureCredentialStore(ContainerBuilder $container, array $config)
{
$factoryReference = $container->getDefinition('lightsaml.credential.credential_store_factory');
$definition = $container->getDefinition('lightsaml.credential.credential_store');
$this->setFactoryCompatibleWay($definition, $factoryReference, 'buildFromOwnCredentialStore');
}

private function configureService(ContainerBuilder $container, array $config)
{
$this->configureServiceCredentialResolver($container, $config);
}

private function configureServiceCredentialResolver(ContainerBuilder $container, array $config)
{
$factoryReference = $container->getDefinition('lightsaml.service.credential_resolver_factory');
$definition = $container->getDefinition('lightsaml.service.credential_resolver');
$this->setFactoryCompatibleWay($definition, $factoryReference, 'build');
}

private function configureOwn(ContainerBuilder $container, array $config)
Expand All @@ -71,21 +97,11 @@ private function configureOwnEntityDescriptor(ContainerBuilder $container, array
$definition
->addArgument($config['own']['entity_descriptor_provider']['filename'])
->addArgument($config['own']['entity_descriptor_provider']['entity_id']);
if (method_exists($definition, 'setFactory')) {
$definition->setFactory(['LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntitiesDescriptorFile']);
} else {
$definition->setFactoryClass('LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory');
$definition->setFactoryMethod('fromEntitiesDescriptorFile');
}
$this->setFactoryCompatibleWay($definition, 'LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntitiesDescriptorFile');
} else {
$definition = $container->setDefinition('lightsaml.own.entity_descriptor_provider', new Definition())
->addArgument($config['own']['entity_descriptor_provider']['filename']);
if (method_exists($definition, 'setFactory')) {
$definition->setFactory(['LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntityDescriptorFile']);
} else {
$definition->setFactoryClass('LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory');
$definition->setFactoryMethod('fromEntityDescriptorFile');
}
$this->setFactoryCompatibleWay($definition, 'LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory', 'fromEntityDescriptorFile');
}
} else {
$definition = $container->getDefinition('lightsaml.own.entity_descriptor_provider');
Expand All @@ -96,12 +112,7 @@ private function configureOwnEntityDescriptor(ContainerBuilder $container, array
->addArgument(null)
->addArgument(new Reference('lightsaml.own.credential_store'))
;
if (method_exists($definition, 'setFactory')) {
$definition->setFactory(['LightSaml\SymfonyBridgeBundle\Factory\OwnEntityDescriptorProviderFactory', 'build']);
} else {
$definition->setFactoryClass('LightSaml\SymfonyBridgeBundle\Factory\OwnEntityDescriptorProviderFactory');
$definition->setFactoryMethod('build');
}
$this->setFactoryCompatibleWay($definition, 'LightSaml\SymfonyBridgeBundle\Factory\OwnEntityDescriptorProviderFactory', 'build');
}
}

Expand All @@ -113,7 +124,7 @@ private function configureOwnCredentials(ContainerBuilder $container, array $con

foreach ($config['own']['credentials'] as $id => $data) {
$definition = new Definition(
\LightSaml\Store\Credential\X509FileCredentialStore::class,
'LightSaml\Store\Credential\X509FileCredentialStore',
[
$config['own']['entity_id'],
$data['certificate'],
Expand Down Expand Up @@ -165,4 +176,23 @@ private function configureStore(ContainerBuilder $container, array $config)
$container->setAlias('lightsaml.store.sso_state', $config['store']['sso_state']);
}
}

/**
* @param Definition $definition
* @param string $classOrReference
* @param string $method
*/
private function setFactoryCompatibleWay(Definition $definition, $classOrReference, $method)
{
if (method_exists($definition, 'setFactory')) {
$definition->setFactory([$classOrReference, $method]);
} else {
if ($classOrReference instanceof Reference) {
$definition->setFactoryService((string) $classOrReference);
} else {
$definition->setFactoryClass($classOrReference);
}
$definition->setFactoryMethod($method);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
lightsaml.credential.credential_store:
class: LightSaml\Store\Credential\CompositeCredentialStore
factory: [LightSaml\SymfonyBridgeBundle\Factory\CredentialStoreFactory, build]
# factory: ["@lightsaml.credential.credential_store_factory", buildFromOwnCredentialStore] # set in extension, differently based on symfony version
arguments:
- "@lightsaml.party.idp_entity_descriptor_store"
- "@lightsaml.party.sp_entity_descriptor_store"
Expand Down
4 changes: 3 additions & 1 deletion src/LightSaml/SymfonyBridgeBundle/Resources/config/own.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ services:

lightsaml.own.entity_descriptor_provider:
class: LightSaml\Builder\EntityDescriptor\SimpleEntityDescriptorBuilder
# factory set in extension, differently based on symfony version
# factory set in extension, all with arguments, differently based on symfony version
# factory: ["@LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory", "fromEntitiesDescriptorFile"]
# factory: ["@LightSaml\Provider\EntityDescriptor\FileEntityDescriptorProviderFactory", "fromEntityDescriptorFile"]
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ services:

lightsaml.service.credential_resolver:
class: LightSaml\Resolver\Credential\CompositeFilterResolver
factory: ["@lightsaml.service.credential_resolver_factory", build]
# factory: ["@lightsaml.service.credential_resolver_factory", build] # set in extension, differently based on symfony version

lightsaml.service.signature_resolver:
class: LightSaml\Resolver\Signature\OwnSignatureResolver
Expand Down

0 comments on commit d56ada3

Please sign in to comment.