Skip to content
Open
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
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ matrix:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
- php: 7.0
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"

# Test the latest stable release
- php: 7.0
- php: 7.1
- php: 7.2
env: COVERAGE=true PHPUNIT_FLAGS="-v --testsuite main --coverage-text --coverage-clover=build/coverage.xml"

- php: 7.1
env: DEPENDENCIES="dunglas/symfony-lock:^3"
- php: 7.1
- php: 7.3
env: DEPENDENCIES="dunglas/symfony-lock:^4"
- php: 7.4

# Latest commit to master
- php: 7.2
- php: 7.3
env: STABILITY="dev"

allow_failures:
Expand Down
17 changes: 14 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## 0.6.0

### Added

- Support for Symfony 5

### Removed

- Support for Symfony < 4.4
- Support for PHP < 7.2

## 0.5.0

Expand All @@ -13,7 +24,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee

### Added

- Support for PHP 7.0
- Support for PHP 7.0

## 0.4.1

Expand All @@ -23,7 +34,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee

## 0.4.0

### Added
### Added

- Support for Symfony 4

Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('happyr_api');
$treeBuilder = new TreeBuilder('happyr_api');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand Down
11 changes: 7 additions & 4 deletions DependencyInjection/HappyrApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Happyr\ApiBundle\DependencyInjection;

use Happyr\ApiBundle\EventListener\ExceptionListener;
use Happyr\ApiBundle\Security\Authentication\Provider\DebugProvider;
use Happyr\ApiBundle\Security\Authentication\Provider\DummyProvider;
use Happyr\ApiBundle\Security\Authentication\Provider\WsseProvider;
use Happyr\ApiBundle\Security\Firewall\DebugListener;
use Happyr\ApiBundle\Security\Firewall\WsseListener;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
Expand All @@ -28,7 +31,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.yml');

// add the error map to the error handler
$wsseProviderId = 'happyr_api.wsse.security.authentication.provider';
$wsseProviderId = WsseProvider::class;
if (!$config['wsse']['enabled']) {
$container->removeDefinition($wsseProviderId);
$container->register($wsseProviderId, DummyProvider::class)
Expand All @@ -38,7 +41,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->register($wsseProviderId, DebugProvider::class)
->addArgument(null)
->addMethodCall('setDebugRoles', [empty($config['wsse']['debug_roles']) ? ['ROLE_USER', 'ROLE_API_USER'] : $config['wsse']['debug_roles']]);
$container->getDefinition('happyr_api.wsse.security.authentication.listener')
$container->getDefinition(WsseListener::class)
->setClass(DebugListener::class);
} else {
$definition = $container->getDefinition($wsseProviderId);
Expand All @@ -50,7 +53,7 @@ public function load(array $configs, ContainerBuilder $container)
if ($config['exception_listener']['enabled']) {
$this->enabledExceptionHandler($container, $config);
} else {
$container->removeDefinition('happyr_api.exception_listener');
$container->removeDefinition(ExceptionListener::class);
}
}

Expand All @@ -62,7 +65,7 @@ public function load(array $configs, ContainerBuilder $container)
*/
private function enabledExceptionHandler(ContainerBuilder $container, $config)
{
$def = $container->getDefinition('happyr_api.exception_listener');
$def = $container->getDefinition(ExceptionListener::class);
$def->replaceArgument(1, $config['exception_listener']['path_prefix']);
if ('dev' !== $container->getParameter('kernel.environment')) {
$def->addTag(
Expand Down
17 changes: 5 additions & 12 deletions DependencyInjection/Security/Factory/WsseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Happyr\ApiBundle\DependencyInjection\Security\Factory;

use Happyr\ApiBundle\Security\Authentication\Provider\WsseProvider;
use Happyr\ApiBundle\Security\Firewall\WsseListener;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -15,25 +17,16 @@
*/
class WsseFactory implements SecurityFactoryInterface
{
/**
* @param ContainerBuilder $container
* @param int $id
* @param array $config
* @param string $userProvider
* @param string $defaultEntryPoint
*
* @return array
*/
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint)
{
$providerId = 'security.authentication.provider.wsse.'.$id;
$container
->setDefinition($providerId, new ChildDefinition('happyr_api.wsse.security.authentication.provider'))
->setDefinition($providerId, new ChildDefinition(WsseProvider::class))
->replaceArgument(0, new Reference($userProvider))
;

$listenerId = 'security.authentication.listener.wsse.'.$id;
$container->setDefinition($listenerId, new ChildDefinition('happyr_api.wsse.security.authentication.listener'));
$container->setDefinition($listenerId, new ChildDefinition(WsseListener::class));

return [$providerId, $listenerId, $defaultEntryPoint];
}
Expand Down
11 changes: 4 additions & 7 deletions EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Happyr\ApiBundle\EventListener;

use Fervo\ValidatedMessage\ValidationFailedException as FervoValaidationFailed;
use Happyr\ApiBundle\Service\ResponseFactory;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
Expand Down Expand Up @@ -41,17 +40,15 @@ public function __construct(ResponseFactory $responseFactory, $pathPrefix)

/**
* Make sure we print a nice error message to the user when we encounter an exception.
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(ExceptionEvent $event)
{
// Make sure to match uri before we start to catch exceptions
if (!preg_match('|^'.$this->pathPrefix.'.*|sim', $event->getRequest()->getPathInfo())) {
return;
}

$exception = $event->getException();
$exception = $event->getThrowable();
if ($exception instanceof AccessDeniedException || $exception instanceof AccessDeniedHttpException) {
$response = $this->responseFactory->createForbidden();
} elseif ($exception instanceof AuthenticationException) {
Expand All @@ -62,7 +59,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
$response = $this->responseFactory->createWithError('Method not allowed', 405, 'GEN-METHOD');
} elseif ($exception instanceof NotFoundHttpException) {
$response = $this->responseFactory->createNotFound();
} elseif ($exception instanceof FervoValaidationFailed || $exception instanceof ValidationFailedException) {
} elseif ($exception instanceof ValidationFailedException) {
$response = $this->responseFactory->createValidationFailed($exception->getViolations());
} else {
$response = $this->responseFactory->createInternalError();
Expand Down
47 changes: 20 additions & 27 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
services:
happyr_api.wsse.security.authentication.provider:
class: Happyr\ApiBundle\Security\Authentication\Provider\WsseProvider
arguments:
- ~
- ~
- ~
public: false
calls:
- ['setLogger', ['@?logger']]
Happyr\ApiBundle\Security\Authentication\Provider\WsseProvider:
arguments:
- ~
- ~
- ~
public: false
calls:
- ['setLogger', ['@?logger']]

happyr_api.wsse.security.authentication.listener:
class: Happyr\ApiBundle\Security\Firewall\WsseListener
arguments: ["@security.token_storage", "@security.authentication.manager"]
public: false
calls:
- ['setResponseFactory', ['@happyr_api.response_factory']]
Happyr\ApiBundle\Security\Firewall\WsseListener:
arguments: ['@security.token_storage', '@security.authentication.manager', '@Happyr\ApiBundle\Service\ResponseFactory']

happyr_api.response_factory:
class: Happyr\ApiBundle\Service\ResponseFactory
arguments: ['@happyr_api.fractal']
Happyr\ApiBundle\Service\ResponseFactory:
arguments: ['@happyr_api.fractal']

happyr_api.fractal:
class: League\Fractal\Manager
calls:
- [setSerializer, ['@happyr_api.fractal.serializer']]
happyr_api.fractal:
class: League\Fractal\Manager
calls:
- [setSerializer, ['@happyr_api.fractal.serializer']]

happyr_api.fractal.serializer:
class: League\Fractal\Serializer\DataArraySerializer
happyr_api.fractal.serializer:
class: League\Fractal\Serializer\DataArraySerializer

happyr_api.exception_listener:
class: Happyr\ApiBundle\EventListener\ExceptionListener
arguments: ['@happyr_api.response_factory', ~]
Happyr\ApiBundle\EventListener\ExceptionListener:
arguments: ['@Happyr\ApiBundle\Service\ResponseFactory', ~]
10 changes: 3 additions & 7 deletions Security/Firewall/DebugListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace Happyr\ApiBundle\Security\Firewall;

use Happyr\ApiBundle\Service\ResponseFactory;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
use Happyr\ApiBundle\Security\Authentication\Token\WsseUserToken;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class DebugListener implements ListenerInterface
class DebugListener
{
/**
* @var TokenStorageInterface
Expand All @@ -36,10 +35,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
$this->authenticationManager = $authenticationManager;
}

/**
* @param GetResponseEvent $event
*/
public function handle(GetResponseEvent $event)
public function __invoke(RequestEvent $event)
{
$token = new WsseUserToken();
$token->setUser('api_user');
Expand Down
23 changes: 4 additions & 19 deletions Security/Firewall/WsseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace Happyr\ApiBundle\Security\Firewall;

use Happyr\ApiBundle\Service\ResponseFactory;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
use Happyr\ApiBundle\Security\Authentication\Token\WsseUserToken;

/**
Expand All @@ -17,7 +16,7 @@
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class WsseListener implements ListenerInterface
class WsseListener
{
/**
* @var TokenStorageInterface
Expand All @@ -34,28 +33,14 @@ class WsseListener implements ListenerInterface
*/
private $responseFactory;

/**
* @param TokenStorageInterface $tokenStorage
* @param AuthenticationManagerInterface $authenticationManager
*/
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager)
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, ResponseFactory $responseFactory)
{
$this->tokenStorage = $tokenStorage;
$this->authenticationManager = $authenticationManager;
}

/**
* @param ResponseFactory $responseFactory
**/
public function setResponseFactory(ResponseFactory $responseFactory)
{
$this->responseFactory = $responseFactory;
}

/**
* @param GetResponseEvent $event
*/
public function handle(GetResponseEvent $event)
public function __invoke(RequestEvent $event)
{
$request = $event->getRequest();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getBundleClass()
return HappyrApiBundle::class;
}

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->addCompilerPass(new PublicServicePass('|happyr_api.*|'));
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.2",
"psr/cache": "^1.0",
"symfony/security-bundle": "^3.3 || ^4.0",
"symfony/http-foundation": "^3.3 || ^4.0",
"symfony/framework-bundle": "^3.3 || ^4.0",
"symfony/security-bundle": "^4.4 || ^5.0",
"symfony/http-foundation": "^4.4 || ^5.0",
"symfony/framework-bundle": "^4.4 || ^5.0",
"league/fractal": "^0.16.0",
"symfony/validator": "^3.3 || ^4.0"
"symfony/validator": "^4.4 || ^5.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.0.4",
"matthiasnoback/symfony-dependency-injection-test": "^2.3",
"nyholm/symfony-bundle-test": "^1.3.1",
"symfony/phpunit-bridge": "^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"nyholm/symfony-bundle-test": "^1.6.1",
"cache/void-adapter": "^1.0"
},
"autoload": {
Expand Down