diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a5104296..e528e23a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1006,11 +1006,6 @@ parameters: count: 1 path: src/Bundle/Serializer/JWESerializer.php - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWESerializer\\:\\:getSupportedTypes\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWESerializer.php - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWESerializer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -1046,11 +1041,6 @@ parameters: count: 1 path: src/Bundle/Serializer/JWSSerializer.php - - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSSerializer\\:\\:getSupportedTypes\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Bundle/Serializer/JWSSerializer.php - - message: "#^Method Jose\\\\Bundle\\\\JoseFramework\\\\Serializer\\\\JWSSerializer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -1288,16 +1278,86 @@ parameters: count: 1 path: src/Library/Checker/IssuerChecker.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\AddKeyIntoKeysetCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/AddKeyIntoKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\AddKeyIntoKeysetCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/AddKeyIntoKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\EcKeyGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/EcKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\EcKeyGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/EcKeyGeneratorCommand.php + - message: "#^Cannot cast mixed to int\\.$#" count: 1 path: src/Library/Console/EcKeysetGeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\EcKeysetGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/EcKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\EcKeysetGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/EcKeysetGeneratorCommand.php + - message: "#^Method Jose\\\\Component\\\\Console\\\\GeneratorCommand\\:\\:getOptions\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: src/Library/Console/GeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\GetThumbprintCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/GetThumbprintCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\GetThumbprintCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/GetThumbprintCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\JKULoaderCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/JKULoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\JKULoaderCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/JKULoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\KeyAnalyzerCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/KeyAnalyzerCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\KeyAnalyzerCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/KeyAnalyzerCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\KeyFileLoaderCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/KeyFileLoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\KeyFileLoaderCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/KeyFileLoaderCommand.php + - message: "#^Parameter \\#1 \\$jwk of method Jose\\\\Component\\\\KeyManagement\\\\Analyzer\\\\KeyAnalyzerManager\\:\\:analyze\\(\\) expects Jose\\\\Component\\\\Core\\\\JWK, mixed given\\.$#" count: 1 @@ -1308,31 +1368,211 @@ parameters: count: 1 path: src/Library/Console/KeysetAnalyzerCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\KeysetAnalyzerCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/KeysetAnalyzerCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\KeysetAnalyzerCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/KeysetAnalyzerCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\MergeKeysetCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/MergeKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\MergeKeysetCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/MergeKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\NoneKeyGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/NoneKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\NoneKeyGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/NoneKeyGeneratorCommand.php + - message: "#^Cannot cast mixed to int\\.$#" count: 1 path: src/Library/Console/OctKeyGeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OctKeyGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/OctKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OctKeyGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/OctKeyGeneratorCommand.php + - message: "#^Cannot cast mixed to int\\.$#" count: 2 path: src/Library/Console/OctKeysetGeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OctKeysetGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/OctKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OctKeysetGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/OctKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OkpKeyGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/OkpKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OkpKeyGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/OkpKeyGeneratorCommand.php + - message: "#^Cannot cast mixed to int\\.$#" count: 1 path: src/Library/Console/OkpKeysetGeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OkpKeysetGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/OkpKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OkpKeysetGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/OkpKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OptimizeRsaKeyCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/OptimizeRsaKeyCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\OptimizeRsaKeyCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/OptimizeRsaKeyCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\P12CertificateLoaderCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/P12CertificateLoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\P12CertificateLoaderCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/P12CertificateLoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\PemConverterCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/PemConverterCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\PemConverterCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/PemConverterCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\PublicKeyCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/PublicKeyCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\PublicKeyCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/PublicKeyCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\PublicKeysetCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/PublicKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\PublicKeysetCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/PublicKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\RotateKeysetCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/RotateKeysetCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\RotateKeysetCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/RotateKeysetCommand.php + - message: "#^Cannot cast mixed to int\\.$#" count: 1 path: src/Library/Console/RsaKeyGeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\RsaKeyGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/RsaKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\RsaKeyGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/RsaKeyGeneratorCommand.php + - message: "#^Cannot cast mixed to int\\.$#" count: 2 path: src/Library/Console/RsaKeysetGeneratorCommand.php + - + message: "#^Property Jose\\\\Component\\\\Console\\\\RsaKeysetGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/RsaKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\RsaKeysetGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/RsaKeysetGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\SecretKeyGeneratorCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/SecretKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\SecretKeyGeneratorCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/SecretKeyGeneratorCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\X509CertificateLoaderCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/X509CertificateLoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\X509CertificateLoaderCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/X509CertificateLoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\X5ULoaderCommand\\:\\:\\$defaultDescription has no type specified\\.$#" + count: 1 + path: src/Library/Console/X5ULoaderCommand.php + + - + message: "#^Property Jose\\\\Component\\\\Console\\\\X5ULoaderCommand\\:\\:\\$defaultName has no type specified\\.$#" + count: 1 + path: src/Library/Console/X5ULoaderCommand.php + - message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#" count: 1 diff --git a/src/Bundle/DependencyInjection/Source/Encryption/AbstractEncryptionSource.php b/src/Bundle/DependencyInjection/Source/Encryption/AbstractEncryptionSource.php index 461a1db2..2bdffaf6 100644 --- a/src/Bundle/DependencyInjection/Source/Encryption/AbstractEncryptionSource.php +++ b/src/Bundle/DependencyInjection/Source/Encryption/AbstractEncryptionSource.php @@ -17,22 +17,60 @@ public function getNodeDefinition(NodeDefinition $node): void ->arrayNode($this->name()) ->useAttributeAsKey('name') ->arrayPrototype() + ->beforeNormalization() + ->ifTrue( + static fn (array $v) => isset($v['key_encryption_algorithms']) || isset($v['content_encryption_algorithms']) + ) + ->then(static function (array $v) { + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'] ?? [], + $v['key_encryption_algorithms'] ?? [] + ); + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'], + $v['content_encryption_algorithms'] ?? [] + ); + unset($v['key_encryption_algorithms'], $v['content_encryption_algorithms']); + $v['encryption_algorithms'] = array_values(array_unique($v['encryption_algorithms'])); + + return $v; + }) + ->end() ->children() ->booleanNode('is_public') ->info('If true, the service will be public, else private.') ->defaultTrue() ->end() - ->arrayNode('key_encryption_algorithms') - ->info('A list of supported key encryption algorithms.') + ->arrayNode('encryption_algorithms') + ->info('A list of key or content encryption algorithm aliases.') ->useAttributeAsKey('name') ->isRequired() ->requiresAtLeastOneElement() ->scalarPrototype() ->end() ->end() + ->arrayNode('key_encryption_algorithms') + ->info('A list of supported key encryption algorithms.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) + ->useAttributeAsKey('name') + ->treatNullLike([]) + ->treatFalseLike([]) + ->defaultValue([]) + ->scalarPrototype() + ->end() + ->end() ->arrayNode('content_encryption_algorithms') ->info('A list of supported content encryption algorithms.') ->useAttributeAsKey('name') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->treatNullLike([]) ->treatFalseLike([]) ->defaultValue([]) @@ -41,6 +79,11 @@ public function getNodeDefinition(NodeDefinition $node): void ->end() ->arrayNode('compression_methods') ->info('A list of supported compression methods.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) diff --git a/src/Bundle/DependencyInjection/Source/Encryption/JWEBuilder.php b/src/Bundle/DependencyInjection/Source/Encryption/JWEBuilder.php index 2e5c8fe4..1e5ae344 100644 --- a/src/Bundle/DependencyInjection/Source/Encryption/JWEBuilder.php +++ b/src/Bundle/DependencyInjection/Source/Encryption/JWEBuilder.php @@ -25,8 +25,8 @@ public function load(array $configs, ContainerBuilder $container): void $definition ->setFactory([new Reference(JWEBuilderFactory::class), 'create']) ->setArguments([ - $itemConfig['key_encryption_algorithms'], - $itemConfig['content_encryption_algorithms'] === [] ? null : $itemConfig['content_encryption_algorithms'], + $itemConfig['encryption_algorithms'], + null, $itemConfig['compression_methods'] === [] ? null : $itemConfig['compression_methods'], ]) ->addTag('jose.jwe_builder') diff --git a/src/Bundle/DependencyInjection/Source/Encryption/JWEDecrypter.php b/src/Bundle/DependencyInjection/Source/Encryption/JWEDecrypter.php index 66588aa4..45fd3682 100644 --- a/src/Bundle/DependencyInjection/Source/Encryption/JWEDecrypter.php +++ b/src/Bundle/DependencyInjection/Source/Encryption/JWEDecrypter.php @@ -25,8 +25,8 @@ public function load(array $configs, ContainerBuilder $container): void $definition ->setFactory([new Reference(JWEDecrypterFactory::class), 'create']) ->setArguments([ - $itemConfig['key_encryption_algorithms'], - $itemConfig['content_encryption_algorithms'] === [] ? null : $itemConfig['content_encryption_algorithms'], + $itemConfig['encryption_algorithms'], + null, $itemConfig['compression_methods'] === [] ? null : $itemConfig['compression_methods'], ]) ->addTag('jose.jwe_decrypter') diff --git a/src/Bundle/DependencyInjection/Source/Encryption/JWELoader.php b/src/Bundle/DependencyInjection/Source/Encryption/JWELoader.php index dde501ea..3a1956dd 100644 --- a/src/Bundle/DependencyInjection/Source/Encryption/JWELoader.php +++ b/src/Bundle/DependencyInjection/Source/Encryption/JWELoader.php @@ -28,8 +28,8 @@ public function load(array $configs, ContainerBuilder $container): void ->setFactory([new Reference(JWELoaderFactory::class), 'create']) ->setArguments([ $itemConfig['serializers'], - $itemConfig['key_encryption_algorithms'], - $itemConfig['content_encryption_algorithms'] === [] ? null : $itemConfig['content_encryption_algorithms'], + $itemConfig['encryption_algorithms'], + null, $itemConfig['compression_methods'] === [] ? null : $itemConfig['compression_methods'], $itemConfig['header_checkers'], ]) @@ -52,20 +52,59 @@ public function getNodeDefinition(NodeDefinition $node): void ->requiresAtLeastOneElement() ->useAttributeAsKey('name') ->arrayPrototype() + ->beforeNormalization() + ->ifTrue( + static fn (array $v) => isset($v['key_encryption_algorithms']) || isset($v['content_encryption_algorithms']) + ) + ->then(static function (array $v) { + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'] ?? [], + $v['key_encryption_algorithms'] ?? [] + ); + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'], + $v['content_encryption_algorithms'] ?? [] + ); + unset($v['key_encryption_algorithms'], $v['content_encryption_algorithms']); + $v['encryption_algorithms'] = array_values(array_unique($v['encryption_algorithms'])); + + return $v; + }) + ->end() ->children() ->booleanNode('is_public') ->info('If true, the service will be public, else private.') ->defaultTrue() ->end() + ->arrayNode('encryption_algorithms') + ->info('A list of key or content encryption algorithm aliases.') + ->useAttributeAsKey('name') + ->isRequired() + ->requiresAtLeastOneElement() + ->scalarPrototype() + ->end() + ->end() ->arrayNode('key_encryption_algorithms') ->info('A list of key encryption algorithm aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->useAttributeAsKey('name') - ->isRequired() + ->treatNullLike([]) + ->treatFalseLike([]) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() ->arrayNode('content_encryption_algorithms') ->info('A list of key encryption algorithm aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) @@ -75,6 +114,11 @@ public function getNodeDefinition(NodeDefinition $node): void ->end() ->arrayNode('compression_methods') ->info('A list of compression method aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) diff --git a/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenBuilder.php b/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenBuilder.php index 05c03f53..ae048fe3 100644 --- a/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenBuilder.php +++ b/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenBuilder.php @@ -28,8 +28,8 @@ public function load(array $configs, ContainerBuilder $container): void ->setFactory([new Reference(NestedTokenBuilderFactory::class), 'create']) ->setArguments([ $itemConfig['jwe_serializers'], - $itemConfig['key_encryption_algorithms'], - $itemConfig['content_encryption_algorithms'] === [] ? null : $itemConfig['content_encryption_algorithms'], + $itemConfig['encryption_algorithms'], + null, $itemConfig['compression_methods'] === [] ? null : $itemConfig['compression_methods'], $itemConfig['jws_serializers'], $itemConfig['signature_algorithms'], @@ -52,6 +52,25 @@ public function getNodeDefinition(NodeDefinition $node): void ->treatFalseLike([]) ->useAttributeAsKey('name') ->arrayPrototype() + ->beforeNormalization() + ->ifTrue( + static fn (array $v) => isset($v['key_encryption_algorithms']) || isset($v['content_encryption_algorithms']) + ) + ->then(static function (array $v) { + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'] ?? [], + $v['key_encryption_algorithms'] ?? [] + ); + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'], + $v['content_encryption_algorithms'] ?? [] + ); + unset($v['key_encryption_algorithms'], $v['content_encryption_algorithms']); + $v['encryption_algorithms'] = array_unique(array_values($v['encryption_algorithms'])); + + return $v; + }) + ->end() ->children() ->booleanNode('is_public') ->info('If true, the service will be public, else private.') @@ -64,15 +83,35 @@ public function getNodeDefinition(NodeDefinition $node): void ->scalarPrototype() ->end() ->end() + ->arrayNode('encryption_algorithms') + ->info('A list of key or content encryption algorithm aliases.') + ->useAttributeAsKey('name') + ->isRequired() + ->requiresAtLeastOneElement() + ->scalarPrototype() + ->end() + ->end() ->arrayNode('key_encryption_algorithms') ->info('A list of key encryption algorithm aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->useAttributeAsKey('name') - ->isRequired() + ->treatNullLike([]) + ->treatFalseLike([]) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() ->arrayNode('content_encryption_algorithms') ->info('A list of key encryption algorithm aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) @@ -82,6 +121,11 @@ public function getNodeDefinition(NodeDefinition $node): void ->end() ->arrayNode('compression_methods') ->info('A list of compression method aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) diff --git a/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenLoader.php b/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenLoader.php index 077f35ef..6009dcdb 100644 --- a/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenLoader.php +++ b/src/Bundle/DependencyInjection/Source/NestedToken/NestedTokenLoader.php @@ -28,8 +28,8 @@ public function load(array $configs, ContainerBuilder $container): void ->setFactory([new Reference(NestedTokenLoaderFactory::class), 'create']) ->setArguments([ $itemConfig['jwe_serializers'], - $itemConfig['key_encryption_algorithms'], - $itemConfig['content_encryption_algorithms'] === [] ? null : $itemConfig['content_encryption_algorithms'], + $itemConfig['encryption_algorithms'], + null, $itemConfig['compression_methods'] === [] ? null : $itemConfig['compression_methods'], $itemConfig['jwe_header_checkers'], $itemConfig['jws_serializers'], @@ -54,6 +54,25 @@ public function getNodeDefinition(NodeDefinition $node): void ->treatFalseLike([]) ->useAttributeAsKey('name') ->arrayPrototype() + ->beforeNormalization() + ->ifTrue( + static fn (array $v) => isset($v['key_encryption_algorithms']) || isset($v['content_encryption_algorithms']) + ) + ->then(static function (array $v) { + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'] ?? [], + $v['key_encryption_algorithms'] ?? [] + ); + $v['encryption_algorithms'] = array_merge( + $v['encryption_algorithms'], + $v['content_encryption_algorithms'] ?? [] + ); + unset($v['key_encryption_algorithms'], $v['content_encryption_algorithms']); + $v['encryption_algorithms'] = array_values(array_unique($v['encryption_algorithms'])); + + return $v; + }) + ->end() ->children() ->booleanNode('is_public') ->info('If true, the service will be public, else private.') @@ -66,15 +85,35 @@ public function getNodeDefinition(NodeDefinition $node): void ->scalarPrototype() ->end() ->end() + ->arrayNode('encryption_algorithms') + ->info('A list of key or content encryption algorithm aliases.') + ->useAttributeAsKey('name') + ->isRequired() + ->requiresAtLeastOneElement() + ->scalarPrototype() + ->end() + ->end() ->arrayNode('key_encryption_algorithms') ->info('A list of key encryption algorithm aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->useAttributeAsKey('name') - ->isRequired() + ->treatNullLike([]) + ->treatFalseLike([]) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() ->arrayNode('content_encryption_algorithms') ->info('A list of key encryption algorithm aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0. Please use "encryption_algorithms" instead.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) @@ -84,6 +123,11 @@ public function getNodeDefinition(NodeDefinition $node): void ->end() ->arrayNode('compression_methods') ->info('A list of compression method aliases.') + ->setDeprecated( + 'web-token/jwt-bundle', + '3.3.0', + 'The child node "%node%" at path "%path%" is deprecated and will be removed in 4.0.0.' + ) ->useAttributeAsKey('name') ->treatNullLike([]) ->treatFalseLike([]) diff --git a/src/Library/NestedToken/NestedTokenLoaderFactory.php b/src/Library/NestedToken/NestedTokenLoaderFactory.php index 04455d95..632ff5e8 100644 --- a/src/Library/NestedToken/NestedTokenLoaderFactory.php +++ b/src/Library/NestedToken/NestedTokenLoaderFactory.php @@ -31,7 +31,7 @@ public function __construct( public function create( array $jweSerializers, array $keyEncryptionAlgorithms, - array $contentEncryptionAlgorithms, + null|array $contentEncryptionAlgorithms, null|array $compressionMethods, array $jweHeaderCheckers, array $jwsSerializers, diff --git a/tests/Bundle/JoseFramework/Functional/Encryption/JweBuilderConfigurationTest.php b/tests/Bundle/JoseFramework/Functional/Encryption/JweBuilderConfigurationTest.php index db97ba94..d1c8f119 100644 --- a/tests/Bundle/JoseFramework/Functional/Encryption/JweBuilderConfigurationTest.php +++ b/tests/Bundle/JoseFramework/Functional/Encryption/JweBuilderConfigurationTest.php @@ -77,7 +77,7 @@ public function theConfigurationIsInvalidIfNotKeyEncryptionAlgorithmIsSet(): voi ], ], ], - 'The child config "key_encryption_algorithms" under "jose.jwe.builders.foo" must be configured:' + 'The child config "encryption_algorithms" under "jose.jwe.builders.foo" must be configured:' ); } @@ -96,7 +96,7 @@ public function theConfigurationIsInvalidIfTheKeyEncryptionAlgorithmIsEmpty(): v ], ], ], - 'The path "jose.jwe.builders.foo.key_encryption_algorithms" should have at least 1 element(s) defined.' + 'The path "jose.jwe.builders.foo.encryption_algorithms" should have at least 1 element(s) defined.' ); } diff --git a/tests/Bundle/JoseFramework/Functional/Encryption/JweDecrypterConfigurationTest.php b/tests/Bundle/JoseFramework/Functional/Encryption/JweDecrypterConfigurationTest.php index b04588ae..019821ea 100644 --- a/tests/Bundle/JoseFramework/Functional/Encryption/JweDecrypterConfigurationTest.php +++ b/tests/Bundle/JoseFramework/Functional/Encryption/JweDecrypterConfigurationTest.php @@ -77,7 +77,7 @@ public function theConfigurationIsInvalidIfNotKeyEncryptionAlgorithmIsSet(): voi ], ], ], - 'The child config "key_encryption_algorithms" under "jose.jwe.decrypters.foo" must be configured:' + 'The child config "encryption_algorithms" under "jose.jwe.decrypters.foo" must be configured:' ); } @@ -96,7 +96,7 @@ public function theConfigurationIsInvalidIfTheKeyEncryptionAlgorithmIsEmpty(): v ], ], ], - 'The path "jose.jwe.decrypters.foo.key_encryption_algorithms" should have at least 1 element(s) defined.' + 'The path "jose.jwe.decrypters.foo.encryption_algorithms" should have at least 1 element(s) defined.' ); } diff --git a/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenBuilderConfigurationTest.php b/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenBuilderConfigurationTest.php index 55d9e955..dde5359f 100644 --- a/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenBuilderConfigurationTest.php +++ b/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenBuilderConfigurationTest.php @@ -99,7 +99,7 @@ public function theConfigurationIsInvalidIfNoKeyEncryptionAlgorithmIsSet(): void ], ], ], - 'The child config "key_encryption_algorithms" under "jose.nested_token.builders.foo" must be configured:' + 'The child config "encryption_algorithms" under "jose.nested_token.builders.foo" must be configured:' ); } diff --git a/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenLoaderConfigurationTest.php b/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenLoaderConfigurationTest.php index 879fa5b8..808b2b09 100644 --- a/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenLoaderConfigurationTest.php +++ b/tests/Bundle/JoseFramework/Functional/NestedToken/NestedTokenLoaderConfigurationTest.php @@ -99,7 +99,7 @@ public function theConfigurationIsInvalidIfNoKeyEncryptionAlgorithmIsSet(): void ], ], ], - 'The child config "key_encryption_algorithms" under "jose.nested_token.loaders.foo" must be configured:' + 'The child config "encryption_algorithms" under "jose.nested_token.loaders.foo" must be configured:' ); }