Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function addConfiguration(NodeDefinition $node)
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->prototype('variable')->end()
->variablePrototype()->end()
->end()
->end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getNodeDefinition(NodeDefinition $node)
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->prototype('variable')
->variablePrototype()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getNodeDefinition(NodeDefinition $node)
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->prototype('variable')
->variablePrototype()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ public function getNodeDefinition(NodeDefinition $node)
->info('A list of supported compression methods.')
->useAttributeAsKey('name')
->defaultValue(['DEF'])
->requiresAtLeastOneElement()
->scalarPrototype()->end()
->end()
->arrayNode('tags')
->info('A list of tags to be associated to the service.')
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->prototype('variable')->end()
->variablePrototype()->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getNodeDefinition(NodeDefinition $node)
->arrayNode($this->name())
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->arrayPrototype()
->children()
->booleanNode('is_public')
->info('If true, the service will be public, else private.')
Expand All @@ -75,39 +75,39 @@ public function getNodeDefinition(NodeDefinition $node)
->info('A list of key encryption algorithm aliases.')
->useAttributeAsKey('name')
->isRequired()
->prototype('scalar')->end()
->scalarPrototype()->end()
->end()
->arrayNode('content_encryption_algorithms')
->info('A list of key encryption algorithm aliases.')
->useAttributeAsKey('name')
->isRequired()
->prototype('scalar')->end()
->scalarPrototype()->end()
->end()
->arrayNode('compression_methods')
->info('A list of compression method aliases.')
->useAttributeAsKey('name')
->isRequired()
->prototype('scalar')->end()
->defaultValue(['DEF'])
->scalarPrototype()->end()
->end()
->arrayNode('serializers')
->info('A list of signature serializer aliases.')
->useAttributeAsKey('name')
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->scalarPrototype()->end()
->end()
->arrayNode('header_checkers')
->info('A list of header checker aliases.')
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->prototype('scalar')->end()
->scalarPrototype()->end()
->end()
->arrayNode('tags')
->info('A list of tags to be associated to the service.')
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->prototype('variable')->end()
->variablePrototype()->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

declare(strict_types=1);

/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2018 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption;

use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
use Jose\Component\Checker\HeaderCheckerManagerFactory;
use Jose\Component\Encryption\JWEDecrypterFactory;
use Jose\Component\Signature\JWSVerifierFactory;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class NestedToken implements Source
{
/**
* @var Source[]
*/
private $sources;

/**
* EncryptionSource constructor.
*/
public function __construct()
{
$this->sources = [
new NestedTokenLoader(),
new NestedTokenBuilder(),
];
}

/**
* {@inheritdoc}
*/
public function name(): string
{
return 'nested_token';
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
if (!$this->isEnabled()) {
return;
}
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('nested_token.yml');

if (array_key_exists('nested_token', $configs)) {
foreach ($this->sources as $source) {
$source->load($configs['nested_token'], $container);
}
}
}

public function getNodeDefinition(NodeDefinition $node)
{
if (!$this->isEnabled()) {
return;
}
$childNode = $node->children()
->arrayNode($this->name())
->treatNullLike([])
->treatFalseLike([]);

foreach ($this->sources as $source) {
$source->getNodeDefinition($childNode);
}
}

/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container, array $config): array
{
if (!$this->isEnabled()) {
return [];
}
$result = [];
foreach ($this->sources as $source) {
$prepend = $source->prepend($container, $config);
if (!empty($prepend)) {
$result[$source->name()] = $prepend;
}
}

return $result;
}

/**
* @return bool
*/
private function isEnabled(): bool
{
return class_exists(JWEDecrypterFactory::class)
&& class_exists(JWSVerifierFactory::class)
&& class_exists(HeaderCheckerManagerFactory::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

declare(strict_types=1);

/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2018 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption;

use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source;
use Jose\Component\Encryption\NestedTokenBuilderFactory;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class NestedTokenBuilder implements Source
{
/**
* {@inheritdoc}
*/
public function name(): string
{
return 'builders';
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
foreach ($configs[$this->name()] as $name => $itemConfig) {
$service_id = sprintf('jose.nested_token_builder.%s', $name);
$definition = new Definition(self::class);
$definition
->setFactory([new Reference(NestedTokenBuilderFactory::class), 'create'])
->setArguments([
$itemConfig['jwe_serializers'],
$itemConfig['key_encryption_algorithms'],
$itemConfig['content_encryption_algorithms'],
$itemConfig['compression_methods'],
$itemConfig['jws_serializers'],
$itemConfig['signature_algorithms'],
])
->addTag('jose.nested_token_builder')
->setPublic($itemConfig['is_public']);
foreach ($itemConfig['tags'] as $id => $attributes) {
$definition->addTag($id, $attributes);
}
$container->setDefinition($service_id, $definition);
}
}

public function getNodeDefinition(NodeDefinition $node)
{
$node->children()
->arrayNode($this->name())
->treatNullLike([])
->treatFalseLike([])
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->booleanNode('is_public')
->info('If true, the service will be public, else private.')
->defaultTrue()
->end()
->arrayNode('signature_algorithms')
->info('A list of signature algorithm aliases.')
->useAttributeAsKey('name')
->isRequired()
->scalarPrototype()->end()
->end()
->arrayNode('key_encryption_algorithms')
->info('A list of key encryption algorithm aliases.')
->useAttributeAsKey('name')
->isRequired()
->scalarPrototype()->end()
->end()
->arrayNode('content_encryption_algorithms')
->info('A list of key encryption algorithm aliases.')
->useAttributeAsKey('name')
->isRequired()
->scalarPrototype()->end()
->end()
->arrayNode('compression_methods')
->info('A list of compression method aliases.')
->useAttributeAsKey('name')
->defaultValue(['DEF'])
->scalarPrototype()->end()
->end()
->arrayNode('jws_serializers')
->info('A list of JWS serializer aliases.')
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->isRequired()
->requiresAtLeastOneElement()
->scalarPrototype()->end()
->end()
->arrayNode('jwe_serializers')
->info('A list of JWE serializer aliases.')
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->isRequired()
->requiresAtLeastOneElement()
->scalarPrototype()->end()
->end()
->arrayNode('tags')
->info('A list of tags to be associated to the service.')
->useAttributeAsKey('name')
->treatNullLike([])
->treatFalseLike([])
->variablePrototype()->end()
->end()
->end()
->end()
->end();
}

/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container, array $config): array
{
return [];
}
}
Loading