{"id":25504591,"url":"https://github.com/effective-solutions/security-bundle","last_synced_at":"2025-07-15T13:08:49.970Z","repository":{"id":35239736,"uuid":"39499214","full_name":"effective-solutions/security-bundle","owner":"effective-solutions","description":"Effective Solutions Security Bundle","archived":false,"fork":false,"pushed_at":"2017-02-02T06:53:58.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-18T09:12:32.837Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/effective-solutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-22T10:06:51.000Z","updated_at":"2015-07-22T10:10:27.000Z","dependencies_parsed_at":"2022-09-16T20:00:22.688Z","dependency_job_id":null,"html_url":"https://github.com/effective-solutions/security-bundle","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effective-solutions%2Fsecurity-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effective-solutions%2Fsecurity-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effective-solutions%2Fsecurity-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/effective-solutions%2Fsecurity-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/effective-solutions","download_url":"https://codeload.github.com/effective-solutions/security-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239605126,"owners_count":19666996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-19T05:41:18.686Z","updated_at":"2025-02-19T05:41:19.263Z","avatar_url":"https://github.com/effective-solutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Effective Solutions - Security Bundle\n\n## Installation\n\nUse following command in command line to install Effective Solutions Security Bundle\n\n`php composer.phar require effective-solutions/security-bundle`\n\nAfter the installation add following in your `AppKernel.php` file\n\n`new EffectiveSolutions\\SecurityBundle\\EffectiveSolutionsSecurityBundle(),`\n\nAdd following in `app/config/routing.yml` file\n\n```\neffective_solutions_security:\n    resource: \"@EffectiveSolutionsSecurityBundle/Resources/config/routing.yml\"\n    prefix:   /\n```\n\n## Usage\n\n- Create `User.php` file in your Entity folder and add following code.\n\n```\n\u003c?php\n\nnamespace Your\\AppBundle\\Entity;\nuse EffectiveSolutions\\SecurityBundle\\Model\\User as BaseUser;\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity\n * @ORM\\Table()\n */\nclass User extends BaseUser\n{\n    public function __construct()\n    {\n        parent::__construct();\n    }\n\n    /**\n     * @ORM\\ManyToOne(targetEntity=\"Role\",cascade={\"persist\"})\n     * @ORM\\JoinColumn(name=\"role_id\", referencedColumnName=\"id\")\n     **/\n    private $role;\n\n    /**\n     * Set role\n     *\n     * @param \\Base\\DataAccessBundle\\Entity\\Role $role\n     * @return User\n     */\n    public function setRole(\\Base\\DataAccessBundle\\Entity\\Role $role = null)\n    {\n        $this-\u003erole = $role;\n\n        return $this;\n    }\n\n    /**\n     * Get role\n     *\n     * @return \\Base\\DataAccessBundle\\Entity\\Role\n     */\n    public function getRole()\n    {\n        return $this-\u003erole;\n    }\n\n    /**\n     * @return array\n     */\n    public function getRoles()\n    {\n        $roles =  array();\n        if($this-\u003egetRole() != null)\n            $roles[] = $this-\u003egetRole()-\u003egetMetacode();\n        return $roles;\n    }\n}\n```\n\n- Create `Role.php` file in your Entity folder and add following code.\n\n```\n\u003c?php\n\nnamespace Your\\AppBundle\\Entity;\nuse EffectiveSolutions\\SecurityBundle\\Model\\Role as BaseRole;\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity\n * @ORM\\Table()\n */\nclass Role extends BaseRole\n{\n\n}\n\n```\n\n- Run following code to create your user and role tables in your database\n\n`php app/console doctrine:schema:update --force`\n\n- Add following code in your `security.yml` file\n\n```\nsecurity:\n    encoders:\n        Base\\DataAccessBundle\\Entity\\User:\n            algorithm: sha512\n            cost: 10\n\n    providers:\n        in_db:\n            entity:\n                class: Base\\DataAccessBundle\\Entity\\User\n                property: username\n        in_memory:\n            memory:\n                users:\n                    user:  { password: userpass, roles: [ 'ROLE_USER' ] }\n                    admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }\n\n\n    firewalls:\n        dev:\n            pattern:  ^/(_(profiler|wdt)|css|images|js)/\n            security: false\n\n\n        secured_area:\n            pattern:    ^/\n            form_login:\n                login_path: login_route\n                check_path: login_check\n                default_target_path: /\n                failure_path: login_route\n                csrf_provider: form.csrf_provider\n            logout:\n                path:   logout\n                target: login_route\n            anonymous: ~\n\n\n    access_control:\n        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}\n\n```\n\n- Run following code in your command line to configure admin user. Admin username is admin and password is admin\n\n`php app/console register`\n\n- Then go to `http://localhost/YourAppName/web/app_dev.php/login`\n\n## With Sonata Admin Bundle\n\nIf you are using `Sonata Admin Bundle`, create BaseAdmin class and extend your admin classes from BaseAdmin class.\nOveride `isGranted` method in the BaseAdmin class as follows.\n\n```\npublic function isGranted($name,$object=null){\n\n        // overridden by effective security bundle\n        if(!$this-\u003egetService('effective_security.role_handler')-\u003eisRouteGranted($this-\u003egetBaseRouteName()))\n            return false;\n        if(is_array($name))\n        {\n            foreach($name as $element)\n            {\n                if(!$this-\u003egetService('effective_security.role_handler')-\u003eisRouteGranted($this-\u003egetBaseRouteName().'_'.strtolower($element)))\n                    return false;\n            }\n        }\n        else\n        {\n            if(!$this-\u003egetService('effective_security.role_handler')-\u003eisRouteGranted($this-\u003egetBaseRouteName().'_'.strtolower($name)))\n                return false;\n        }\n\n        return parent::isGranted($name,$object);\n    }\n```\n\nCreate `roles_access_config.yml` in your app/config folder and you can write access control logic in that. For example,\n\n```\nadmin_base_dataaccess_customer_create:\n  - ROLE_SUPER_ADMIN\n```\n\nIf you want to secure a controller, you can write route alias as above and call `secure()` in the Controller or `isSecure()`\nto check if the user has permission to access that controller.\n\nThank you for using Effective Solutions Security Bundle. Powered By [EffectiveSolutions.lk](http://effectivesolutions.lk)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffective-solutions%2Fsecurity-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feffective-solutions%2Fsecurity-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feffective-solutions%2Fsecurity-bundle/lists"}