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
- Host: GitHub
- URL: https://github.com/effective-solutions/security-bundle
- Owner: effective-solutions
- Created: 2015-07-22T10:06:51.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-02T06:53:58.000Z (over 9 years ago)
- Last Synced: 2024-11-18T09:12:32.837Z (over 1 year ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)