Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Symfony 5.4 #3

Merged
merged 52 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
07c9fe6
SUPPORT-91253: wip
maruf-paysera Feb 8, 2024
7c9aa56
SUPPORT-91253: init CI
maruf-paysera Feb 8, 2024
3128a21
SUPPORT-91253: updated gitignore
maruf-paysera Feb 8, 2024
6b7ac8e
SUPPORT-91253: renamed
maruf-paysera Feb 8, 2024
641260f
SUPPORT-91253: updated CI
maruf-paysera Feb 8, 2024
cf6b4dd
SUPPORT-91253: updated CI
maruf-paysera Feb 8, 2024
3ab8ce9
SUPPORT-91253: updated CI
maruf-paysera Feb 8, 2024
e04b85c
SUPPORT-91253: updated CI
maruf-paysera Feb 8, 2024
f59c515
SUPPORT-91253: added test branch on push
maruf-paysera Feb 8, 2024
0832913
SUPPORT-91253: removed ci
maruf-paysera Feb 8, 2024
e61c90c
SUPPORT-91253: Added support for Symfony 5.4
maruf-paysera Feb 13, 2024
2746eac
SUPPORT-91253: removed support for Symfony 4
maruf-paysera Feb 13, 2024
33a28ca
SUPPORT-91253: added phpunit 10
maruf-paysera Feb 13, 2024
4b4b258
Merge remote-tracking branch 'origin/SUPPORT-91253' into SUPPORT-91253
maruf-paysera Feb 13, 2024
d87c27d
SUPPORT-91253: code styles
maruf-paysera Feb 13, 2024
39323e5
SUPPORT-91253: updated readme
maruf-paysera Feb 14, 2024
2b3b6eb
SUPPORT-91253: code style
maruf-paysera Feb 14, 2024
8082697
SUPPORT-91253: added support for Symfony 4.0.x
maruf-paysera Feb 23, 2024
89e6a1f
SUPPORT-91253: fix tests
maruf-paysera Feb 23, 2024
cc5032b
SUPPORT-91253: fix
maruf-paysera Feb 23, 2024
bc3fb7c
SUPPORT-91253: added back SF 3 classes
maruf-paysera Feb 23, 2024
b133539
SUPPORT-91253: code style
maruf-paysera Feb 23, 2024
4b80fa1
SUPPORT-91253: added CI
maruf-paysera Feb 13, 2024
51f5a24
SUPPORT-91253: code style
maruf-paysera Feb 14, 2024
e51956d
SUPPORT-91253: removed php 5.5
maruf-paysera Feb 14, 2024
fa26009
SUPPORT-91253: removed test branch
maruf-paysera Feb 14, 2024
1ef8a2e
SUPPORT-91253: rebase master
maruf-paysera Feb 27, 2024
423340f
SUPPORT-91253: updated gitignore
maruf-paysera Feb 8, 2024
ce93c6b
SUPPORT-91253: code review
maruf-paysera Feb 27, 2024
3bbb962
SUPPORT-91253: updated CI
maruf-paysera Feb 27, 2024
684ec5c
Merge branch 'master' into SUPPORT-91253
maruf-paysera Feb 27, 2024
05d0d72
SUPPORT-91253: updated CI
maruf-paysera Feb 27, 2024
4e670f8
SUPPORT-91253: updated composer
maruf-paysera Feb 27, 2024
da8958d
SUPPORT-91253: updated composer
maruf-paysera Feb 27, 2024
1596aee
SUPPORT-91253: removed support for SF 6 from the CI
maruf-paysera Feb 27, 2024
9f0694a
SUPPORT-91253: added test steps
maruf-paysera Feb 27, 2024
6a18903
SUPPORT-91253: added test steps
maruf-paysera Feb 27, 2024
02ecffe
SUPPORT-91253: updated CI and composer
maruf-paysera Feb 27, 2024
c8f0efb
SUPPORT-91253: updated test dir
maruf-paysera Feb 27, 2024
03a671a
SUPPORT-91253: skipping tests for below SF 5
maruf-paysera Feb 27, 2024
b4c6fd6
SUPPORT-91253: code style
maruf-paysera Feb 27, 2024
1eaf778
SUPPORT-91253: code review fix
maruf-paysera Mar 4, 2024
fd1fc6f
SUPPORT-91253: added symfony 4 test
maruf-paysera Mar 4, 2024
3144529
SUPPORT-91253: updated backward compatibility
maruf-paysera Mar 4, 2024
e055c1f
SUPPORT-91253: updated backward compatibility for symfony 4
maruf-paysera Mar 4, 2024
6e24946
SUPPORT-91253: updated kernel version check
maruf-paysera Mar 4, 2024
da565ea
SUPPORT-91253: code style
maruf-paysera Mar 5, 2024
0bb3524
SUPPORT-91253: code review fix
maruf-paysera Mar 6, 2024
f33cef9
SUPPORT-91253: code review fix
maruf-paysera Mar 8, 2024
fb915b7
SUPPORT-91253: fix tests
maruf-paysera Mar 8, 2024
4f50e08
SUPPORT-91253: removed unused code
maruf-paysera Mar 8, 2024
bbdcfce
SUPPORT-91253: updated readme
maruf-paysera Mar 15, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
composer.lock
.phpunit.result.cache
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.0.0 2024-02-08
### Added
- Added support for Symfony ^5.4

## 1.0.2
### Added
- Deprecated \Symfony\Component\DependencyInjection\DefinitionDecorator class removed and
Expand Down
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,51 @@ $bundles = [

## Samples

Sample `security.yml`
```yml
Sample `security.yml` for symfony 3/4
```yaml
security:
providers:
bearer_user:
id: paysera_bearer_authentication.security_user.bearer_user_provider

firewalls:
bearer_secured:
patter: ^/api/
pattern: ^/api/
stateless: true
bearer: true
```

Sample security.yml for Symfony 5
```yaml
security:
enable_authenticator_manager: true
providers:
bearer_user:
id: paysera_bearer_authentication.security_user.bearer_user_provider

firewalls:
bearer_secured:
pattern: ^/api
stateless: true
custom_authenticators:
- paysera_bearer_authentication.authenticator.bearer_passport
provider: bearer_user
maruf-paysera marked this conversation as resolved.
Show resolved Hide resolved

access_control:
# require ROLE_ADMIN for /admin*
- { path: '^/api', roles: ROLE_ADMIN }
```

All bearer handlers must be tagged with:
```xml
<tag name="paysera_bearer_authentication.handler" />
```
and implement `\Paysera\BearerAuthenticationBundle\Security\User\HandlerInterface`

Example of a handler services.yaml
```yaml
paysera_auth_token.security.auth_token_handler:
class: 'App\Services\BearerHandler'
tags:
- { name: 'paysera_bearer_authentication.handler' }
```
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
}
},
"require": {
"php": ">=5.5",
"symfony/symfony": "^2.8 || ^3.0 || ^4.0",
maruf-paysera marked this conversation as resolved.
Show resolved Hide resolved
"paysera/lib-dependency-injection": "^1.0"
"php": ">= 7.4",
"symfony/security-bundle": "^v5.4",
"symfony/http-kernel": "^v5.4",
"paysera/lib-dependency-injection": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^9.6|^10.0"
}
}
9 changes: 9 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" cacheResult="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
<testsuites>
<testsuite name="Package test suite">
<directory>Tests</directory>
<directory>Tests/*</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 2 additions & 12 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('paysera_bearer_authentication');
$rootNode = method_exists($treeBuilder, 'getRootNode')
? $treeBuilder->getRootNode()
: $treeBuilder->root('paysera_bearer_authentication')
;

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
return new TreeBuilder('paysera_bearer_authentication');
}
}
11 changes: 4 additions & 7 deletions src/DependencyInjection/PayseraBearerAuthenticationExtension.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
<?php

declare(strict_types=1);

namespace Paysera\BearerAuthenticationBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class PayseraBearerAuthenticationExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
Expand Down
45 changes: 17 additions & 28 deletions src/DependencyInjection/Security/Factory/BearerFactory.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
<?php

declare(strict_types=1);

namespace Paysera\BearerAuthenticationBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;

class BearerFactory implements SecurityFactoryInterface
class BearerFactory implements AuthenticatorFactoryInterface
{
public function create(
ContainerBuilder $container,
$id,
$config,
$userProvider,
$defaultEntryPoint
) {
$providerId = 'security.authentication.provider.bearer.'.$id;
$container
->setDefinition(
$providerId,
new ChildDefinition('paysera_bearer_authentication.security_authentication_provider.bearer_provider')
)
->replaceArgument(0, new Reference($userProvider));

$listenerId = 'security.authentication.listener.bearer.'.$id;
$listener = $container->setDefinition(
$listenerId,
new ChildDefinition('paysera_bearer_authentication.listener.bearer_listener')
);

return [$providerId, $listenerId, $defaultEntryPoint];
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
{
$authenticatorId = 'security.authentication.provider.bearer.' . $firewallName;

$authenticator = (new ChildDefinition('paysera_bearer_authentication.authenticator.bearer_passport'));

$container->setDefinition($authenticatorId, $authenticator);

return $authenticatorId;
}

public function getPosition()
public function getPriority(): int
{
return 'pre_auth';
return -10;
maruf-paysera marked this conversation as resolved.
Show resolved Hide resolved
}

public function getKey()
public function getKey(): string
{
return 'bearer';
}

public function addConfiguration(NodeDefinition $node)
public function addConfiguration(NodeDefinition $builder): void
{

}
Expand Down
23 changes: 14 additions & 9 deletions src/Entity/BearerUser.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

declare(strict_types=1);

namespace Paysera\BearerAuthenticationBundle\Entity;

class BearerUser implements BearerUserInterface
{
private $username;
private $token;
private $roles;
private string $username;
private string $token;
private array $roles;

public function __construct($username, $token, array $roles = [])
{
Expand All @@ -15,32 +17,35 @@ public function __construct($username, $token, array $roles = [])
$this->roles = $roles;
}

public function getRoles()
public function getRoles(): array
{
return $this->roles;
}

public function getPassword()
public function getPassword(): ?string
{
// bearer has token
return null;
}

public function getSalt()
public function getSalt(): ?string
{
// no salt

return null;
}

public function getUsername()
public function getUsername(): string
{
return $this->username;
}

public function eraseCredentials()
public function eraseCredentials(): void
{

}

public function getToken()
public function getToken(): string
{
return $this->token;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Entity/BearerUserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface BearerUserInterface extends UserInterface
{
/**
* @return string
*/
public function getToken();
public function getToken(): string;
}
73 changes: 0 additions & 73 deletions src/Listener/BearerListener.php

This file was deleted.

6 changes: 4 additions & 2 deletions src/PayseraBearerAuthenticationBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Paysera\BearerAuthenticationBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -9,12 +11,12 @@

class PayseraBearerAuthenticationBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

$extension = $container->getExtension('security');
$extension->addSecurityListenerFactory(new BearerFactory());
$extension->addAuthenticatorFactory(new BearerFactory());
maruf-paysera marked this conversation as resolved.
Show resolved Hide resolved

$container->addCompilerPass(new AddTaggedCompilerPass(
'paysera_bearer_authentication.security_user.bearer_user_provider',
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@

<imports>
<import resource="services/security.xml"/>
<import resource="services/listeners.xml"/>
</imports>
</container>
Loading