Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/orbitale/permissionsbundle

Use expression based permissions instead of roles or voters to simplify your security in Symfony. Feel free to contribute ! :+1: Project was initiated after this discussion: https://github.com/symfony/symfony/issues/21029
https://github.com/orbitale/permissionsbundle

bundle permissions security symfony symfony-bundle

Last synced: 3 months ago
JSON representation

Use expression based permissions instead of roles or voters to simplify your security in Symfony. Feel free to contribute ! :+1: Project was initiated after this discussion: https://github.com/symfony/symfony/issues/21029

Awesome Lists containing this project

README

        

Permissions bundle
==================

The goal of this bundle is to add simple ExpressionLanguage based permissions to Symfony,
to rely on something with more logic than Roles and less heavy than creating Voters.

## Install

* Require it with composer

```bash
$ composer require orbitale/permissions-bundle
```

* Add the bundle to your kernel

```php
denyAccessUnlessGranted('CHUCK_NORRIS');

// ...
}
}
```

## Configuration reference

```yaml
permissions:
defaults:
# Variables to add to ExpressionLanguage, for easier access if you need
expression_variables: []

# Will be added to all not already set "supports" attributes
supports: null
rules:
# Full prototype
# Key names *must* be uppercase
PERMISSION_KEY_NAME:
supports: null
on_vote: null # Required

# Allow expression with a single string, if you don't care of "supports":
PERMISSION_KEY_NAME: 'on_vote expression'
```

## Real life example

```yaml
permissions:
defaults:
expression_variables:
user_class: AppBundle\Entity\User
post_class: AppBundle\Entity\Post
supports: 'instanceof(user, user_class)'
rules:
ADMIN: 'user.isAdmin()'
EDIT_POST:
supports: 'instanceof(user, user_class) and instanceof(subject, post_class)'
on_vote: 'user.isAdmin() and subject.getAuthor().getId() === user.getId()'
```