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 47 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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ jobs:
fail-fast: false
matrix:
php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
symfony:
- '2.*'
- '3.*'
- '4.*'
- '5.*'
- '6.*'
dependency:
- 'highest'
- 'lowest'
Expand All @@ -49,10 +43,13 @@ jobs:
with:
dependency-versions: ${{ matrix.dependency }}

- name: Clear cache (optional)
- name: Clear cache
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.dependency }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.dependency }}

- name: Run all tests
run: composer test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
vendor/
composer.lock
build/
bin/
cache.*
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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
- Dropped support for PHP 5.5 and Symfony 2.x and 3.x
- Renamed Paysera\BearerAuthenticationBundle\DependencyInjection\Security\Factory\BearerFactory to Paysera\BearerAuthenticationBundle\DependencyInjection\Security\Factory\BearerSecurityFactory
- Added Paysera\BearerAuthenticationBundle\DependencyInjection\Security\Factory\BearerAuthenticatorFactory for Symfony 5

## 1.0.2
### Added
- Deprecated \Symfony\Component\DependencyInjection\DefinitionDecorator class removed and
Expand Down
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,52 @@ $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
provider: bearer_user
```

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' }
```
22 changes: 19 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{
"name": "paysera/lib-bearer-authentication-bundle",
"description": "Bearer Authentication Bundle",
"version": "2.0.0",
"autoload": {
"psr-4": {
"Paysera\\BearerAuthenticationBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Paysera\\BearerAuthenticationBundle\\Tests\\": "tests/"
}
},
"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": "^v4.0 || ^v5.4",
"symfony/http-kernel": "^v4.0 || ^v5.4",
"paysera/lib-dependency-injection": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^9.6|^10.0"
},
"scripts": {
"phpunit": "vendor/bin/phpunit",
"test": [
"@phpunit"
]
}
}
17 changes: 17 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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>
8 changes: 3 additions & 5 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Paysera\BearerAuthenticationBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -15,18 +17,14 @@ 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;
}
}
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
Original file line number Diff line number Diff line change
@@ -0,0 +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\ContainerBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;

class BearerAuthenticatorFactory implements AuthenticatorFactoryInterface
{
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 getPriority(): int
{
return -10;
}

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

public function addConfiguration(NodeDefinition $builder): void
{

}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
<?php

declare(strict_types=1);

namespace Paysera\BearerAuthenticationBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
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
/**
* @deprecated since symfony 5.4.x, use BearerAuthenticatorFactory instead
*/
class BearerSecurityFactory implements SecurityFactoryInterface
{
public function create(
ContainerBuilder $container,
$id,
$config,
$userProvider,
$defaultEntryPoint
) {
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array
{
$providerId = 'security.authentication.provider.bearer.'.$id;
$container
->setDefinition(
$providerId,
new ChildDefinition('paysera_bearer_authentication.security_authentication_provider.bearer_provider')
)
->replaceArgument(0, new Reference($userProvider));
->replaceArgument(0, new Reference($userProvider))
;

$listenerId = 'security.authentication.listener.bearer.'.$id;
$listener = $container->setDefinition(

$container->setDefinition(
$listenerId,
new ChildDefinition('paysera_bearer_authentication.listener.bearer_listener')
);

return [$providerId, $listenerId, $defaultEntryPoint];
return [
$providerId,
$listenerId,
$defaultEntryPoint,
];
}

public function getPosition()
public function getPosition(): string
{
return 'pre_auth';
}

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
Loading
Loading