PHPackages                             elenyum/authorization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. elenyum/authorization

ActiveSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

elenyum/authorization
=====================

This bundle oauth authorization in controller.

1.0(10mo ago)021MITPHPPHP &gt;=8.1

Since Jul 8Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/app-elenyum/ElenyumAuthorizationBundle)[ Packagist](https://packagist.org/packages/elenyum/authorization)[ RSS](/packages/elenyum-authorization/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (15)Versions (2)Used By (0)

ElenyumAuthorizationBundle
==========================

[](#elenyumauthorizationbundle)

**ElenyumAuthorizationBundle** provides a mechanism for creating the `User` entity, configuring user authorization, and adding attributes to controllers to manage access to methods.

Installation
------------

[](#installation)

Install the package using Composer:

```
composer require elenyum/authorization
```

### Requirements

[](#requirements)

This package requires the following dependencies:

- PHP &gt;= 8.1
- Symfony components:
    - `symfony/console` ^5.4|^6.0|^7.0
    - `symfony/framework-bundle` ^5.4.24|^6.0|^7.0
    - `symfony/options-resolver` ^7.0
    - `symfony/property-info` ^7.0
    - `symfony/validator` ^7.0
- `zircote/swagger-php` ^4.2.15
- `lexik/jwt-authentication-bundle` v3.1.0

Configuration
-------------

[](#configuration)

No additional configuration is required. However, before use, you need to add configuration to `doctrine.yaml` to activate entity mapping:

```
doctrine:
    orm:
        mappings:
            ElenyumAuthorizationBundle:
                is_bundle: true
                alias: ElenyumAuthorizationBundle
```

Then run migrations to create the necessary tables:

```
php bin/console doctrine:migrations:migrate
```

Using the `Auth` Attribute
--------------------------

[](#using-the-auth-attribute)

This package adds the `Auth` attribute, which can be used in controllers to restrict access:

```
use Elenyum\Authorization\Attribute\Auth;
use App\Entity\Figure;

#[Auth(name: 'Bearer', model: Figure::class)]
public function someAction()
{
    // Action logic
}
```

- `name`: The name of the authorization method (used in documentation).
- `model`: The entity class to which the access restriction will be applied based on roles.

Configuring Business Logic Access with Voter
--------------------------------------------

[](#configuring-business-logic-access-with-voter)

For more flexible access rules to entities, it is recommended to use a `Voter` in Symfony. This allows you to implement checks that go beyond basic role verification and can consider additional business rules, such as restricting access to records created by the current user.

Example of creating a Voter to check record ownership:

```
namespace App\Security\Voter;

use App\Entity\Figure;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class FigureVoter extends Voter
{
    private $security;

    public function __construct(Security $security)
    {
        $this->security = $security;
    }

    protected function supports(string $attribute, $subject): bool
    {
        return in_array($attribute, ['VIEW', 'EDIT']) && $subject instanceof Figure;
    }

    protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
    {
        $user = $token->getUser();
        if (!$user instanceof UserInterface) {
            return false;
        }

        // Check if the user is the owner of the record
        return $subject->getOwnerId() === $user->getId();
    }
}
```

### Applying Voter

[](#applying-voter)

To use the `Voter`, call it via `isGranted` in the controller or configure the attribute for verification:

```
if (!$this->isGranted('EDIT', $figure)) {
    throw $this->createAccessDeniedException('Access denied.');
}
```

Using a `Voter` helps separate business access logic from the main authorization mechanism, adhering to the single responsibility principle and improving code readability and scalability.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance54

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

314d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c87ff5822d69887fc220a47f558378be0c15fe58a21027cb0385e2672aba2c6?d=identicon)[boottaa](/maintainers/boottaa)

---

Top Contributors

[![boottaa](https://avatars.githubusercontent.com/u/11735354?v=4)](https://github.com/boottaa "boottaa (11 commits)")

---

Tags

creatorautogenerated-code

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elenyum-authorization/health.svg)

```
[![Health](https://phpackages.com/badges/elenyum-authorization/health.svg)](https://phpackages.com/packages/elenyum-authorization)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
