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

https://github.com/effective-solutions/security-bundle

Effective Solutions Security Bundle
https://github.com/effective-solutions/security-bundle

Last synced: about 1 year ago
JSON representation

Effective Solutions Security Bundle

Awesome Lists containing this project

README

          

# Effective Solutions - Security Bundle

## Installation

Use following command in command line to install Effective Solutions Security Bundle

`php composer.phar require effective-solutions/security-bundle`

After the installation add following in your `AppKernel.php` file

`new EffectiveSolutions\SecurityBundle\EffectiveSolutionsSecurityBundle(),`

Add following in `app/config/routing.yml` file

```
effective_solutions_security:
resource: "@EffectiveSolutionsSecurityBundle/Resources/config/routing.yml"
prefix: /
```

## Usage

- Create `User.php` file in your Entity folder and add following code.

```
role = $role;

return $this;
}

/**
* Get role
*
* @return \Base\DataAccessBundle\Entity\Role
*/
public function getRole()
{
return $this->role;
}

/**
* @return array
*/
public function getRoles()
{
$roles = array();
if($this->getRole() != null)
$roles[] = $this->getRole()->getMetacode();
return $roles;
}
}
```

- Create `Role.php` file in your Entity folder and add following code.

```
getService('effective_security.role_handler')->isRouteGranted($this->getBaseRouteName()))
return false;
if(is_array($name))
{
foreach($name as $element)
{
if(!$this->getService('effective_security.role_handler')->isRouteGranted($this->getBaseRouteName().'_'.strtolower($element)))
return false;
}
}
else
{
if(!$this->getService('effective_security.role_handler')->isRouteGranted($this->getBaseRouteName().'_'.strtolower($name)))
return false;
}

return parent::isGranted($name,$object);
}
```

Create `roles_access_config.yml` in your app/config folder and you can write access control logic in that. For example,

```
admin_base_dataaccess_customer_create:
- ROLE_SUPER_ADMIN
```

If you want to secure a controller, you can write route alias as above and call `secure()` in the Controller or `isSecure()`
to check if the user has permission to access that controller.

Thank you for using Effective Solutions Security Bundle. Powered By [EffectiveSolutions.lk](http://effectivesolutions.lk)