-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DE102-390 moved all bundles to match the PSR0 specification
- Loading branch information
clivez
committed
Nov 6, 2013
0 parents
commit 04b5493
Showing
34 changed files
with
3,623 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* @copyright 2013 Instaclick Inc. | ||
*/ | ||
|
||
namespace IC\Bundle\Base\SecurityBundle\Acl\Permission; | ||
|
||
use Symfony\Component\Security\Acl\Permission\MaskBuilder as SymfonyMaskBuilder; | ||
|
||
/** | ||
* Mask Builder | ||
* | ||
* @author John Cartwright <[email protected]> | ||
* @author Danilo Cabello <[email protected]> | ||
*/ | ||
class MaskBuilder extends SymfonyMaskBuilder | ||
{ | ||
const MASK_EXECUTE = 256; | ||
const MASK_CONSUME = 512; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @copyright 2013 Instaclick Inc. | ||
*/ | ||
namespace IC\Bundle\Base\SecurityBundle\Acl\Permission; | ||
|
||
use Symfony\Component\Security\Acl\Permission\BasicPermissionMap; | ||
|
||
/** | ||
* Map roles and entities with the associated permissions. | ||
* | ||
* @author John Cartwright <[email protected]> | ||
* @author Danilo Cabello <[email protected]> | ||
*/ | ||
class PermissionMap extends BasicPermissionMap | ||
{ | ||
const PERMISSION_EXECUTE = 'EXECUTE'; | ||
const PERMISSION_CONSUME = 'CONSUME'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $map = array( | ||
self::PERMISSION_EXECUTE => array( | ||
MaskBuilder::MASK_EXECUTE | ||
), | ||
self::PERMISSION_CONSUME => array( | ||
MaskBuilder::MASK_CONSUME | ||
) | ||
); | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMasks($permission, $object) | ||
{ | ||
if ( ! isset($this->map[$permission])) { | ||
return parent::getMasks($permission, $object); | ||
} | ||
|
||
return $this->map[$permission]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function contains($permission) | ||
{ | ||
return isset($this->map[$permission]) || parent::contains($permission); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* @copyright 2013 Instaclick Inc. | ||
*/ | ||
namespace IC\Bundle\Base\SecurityBundle\DataFixtures\ORM; | ||
|
||
use Doctrine\Common\DataFixtures\AbstractFixture; | ||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\Security\Core\Role\RoleInterface; | ||
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity; | ||
use Symfony\Component\Security\Acl\Domain\ObjectIdentity; | ||
use Symfony\Component\Security\Acl\Exception\AclNotFoundException; | ||
use IC\Bundle\Base\SecurityBundle\Acl\Permission\MaskBuilder; | ||
|
||
/** | ||
* Base class for ACLs data fixtures | ||
* | ||
* @author John Cartwright <[email protected]> | ||
* @author Danilo Cabello <[email protected]> | ||
*/ | ||
abstract class AbstractAclDataFixture extends AbstractFixture implements ContainerAwareInterface | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setContainer(ContainerInterface $container = null) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* Load the role list. | ||
* | ||
* @param string $resourceName | ||
* @param string $permissionName | ||
* @param array $roleList | ||
*/ | ||
protected function loadRoleList($resourceName, $permissionName, $roleList) | ||
{ | ||
foreach ($roleList as $roleName) { | ||
$this->grantPermission($resourceName, $permissionName, $this->getReference($roleName)); | ||
} | ||
} | ||
|
||
/** | ||
* Grant permission for a given resource and role. | ||
* | ||
* @param string $resourceName | ||
* @param string $permissionName | ||
* @param Symfony\Component\Security\Core\Role\RoleInterface $role | ||
*/ | ||
private function grantPermission($resourceName, $permissionName, RoleInterface $role) | ||
{ | ||
$aclProvider = $this->container->get('security.acl.provider'); | ||
$objectIdentity = new ObjectIdentity('class', $resourceName); | ||
|
||
try { | ||
$acl = $aclProvider->findAcl($objectIdentity); | ||
} catch (AclNotFoundException $exception) { | ||
$acl = $aclProvider->createAcl($objectIdentity); | ||
} | ||
|
||
$acl->insertClassAce(new RoleSecurityIdentity($role), $this->createMask($permissionName)); | ||
|
||
$aclProvider->updateAcl($acl); | ||
} | ||
|
||
/** | ||
* Create mask from array of permitted operations. | ||
* | ||
* @param string $permission | ||
* | ||
* @return integer | ||
*/ | ||
private function createMask($permission) | ||
{ | ||
$aclMaskBuilder = new MaskBuilder(); | ||
$aclPermissionMap = $this->container->get('security.acl.permission.map'); | ||
|
||
foreach ($aclPermissionMap->getMasks($permission, null) as $permission) { | ||
$aclMaskBuilder->add($permission); | ||
} | ||
|
||
return $aclMaskBuilder->get(); | ||
} | ||
|
||
/** | ||
* Retrieve the permission list. | ||
* | ||
* @return array | ||
*/ | ||
abstract public function getPermissionList(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @copyright 2013 Instaclick Inc. | ||
*/ | ||
namespace IC\Bundle\Base\SecurityBundle\DataFixtures\ORM; | ||
|
||
use Doctrine\Common\Persistence\ObjectManager; | ||
|
||
/** | ||
* Base class for ACLs permission data fixtures. | ||
* | ||
* @author John Cartwright <[email protected]> | ||
* @author Danilo Cabello <[email protected]> | ||
*/ | ||
abstract class AbstractAclPermissionDataFixture extends AbstractAclDataFixture | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(ObjectManager $manager) | ||
{ | ||
foreach ($this->getPermissionList() as $resourceName => $roleList) { | ||
$this->loadRoleList($resourceName, 'CONSUME', $roleList); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* @copyright 2013 Instaclick Inc. | ||
*/ | ||
namespace IC\Bundle\Base\SecurityBundle\DataFixtures\ORM; | ||
|
||
use Doctrine\Common\Persistence\ObjectManager; | ||
|
||
/** | ||
* Base class for ACLs resource data fixtures. | ||
* | ||
* @author John Cartwright <[email protected]> | ||
* @author Danilo Cabello <[email protected]> | ||
*/ | ||
abstract class AbstractAclResourceDataFixture extends AbstractAclDataFixture | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(ObjectManager $manager) | ||
{ | ||
foreach ($this->getPermissionList() as $resourceName => $permissionList) { | ||
$this->loadPermissionList($resourceName, $permissionList); | ||
} | ||
} | ||
|
||
/** | ||
* Load the permission list. | ||
* | ||
* @param string $resourceName | ||
* @param array $permissionList | ||
*/ | ||
private function loadPermissionList($resourceName, $permissionList) | ||
{ | ||
foreach ($permissionList as $permissionName => $roleList) { | ||
$this->loadRoleList($resourceName, $permissionName, $roleList); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* @copyright 2013 Instaclick Inc. | ||
*/ | ||
|
||
namespace IC\Bundle\Base\SecurityBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* This is the class that validates and merges configuration from your app/config files | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} | ||
* | ||
* @author Anthon Pang <[email protected]> | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('ic_base_security'); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace IC\Bundle\Base\SecurityBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
* | ||
* @author Anthon Pang <[email protected]> | ||
*/ | ||
class ICBaseSecurityExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.xml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* @copyright 2012 Instaclick Inc. | ||
*/ | ||
|
||
namespace IC\Bundle\Base\SecurityBundle\Entity; | ||
|
||
/** | ||
* Entity of Password | ||
* | ||
* @author Juti Noppornpitak <[email protected]> | ||
* @author Guilherme Blanco <[email protected]> | ||
* @author Oleksii Strutsynskyi <[email protected]> | ||
*/ | ||
class Password | ||
{ | ||
/** | ||
* @var string Password hash | ||
*/ | ||
protected $hash; | ||
|
||
/** | ||
* @var string Password salt | ||
*/ | ||
protected $salt; | ||
|
||
/** | ||
* Construct | ||
* | ||
* @param string $hash | ||
* @param string $salt | ||
*/ | ||
public function __construct($hash, $salt) | ||
{ | ||
$this->hash = $hash; | ||
$this->salt = $salt; | ||
} | ||
|
||
/** | ||
* Get the password hash. | ||
* | ||
* @return string | ||
*/ | ||
public function getHash() | ||
{ | ||
return $this->hash; | ||
} | ||
|
||
/** | ||
* Get the password salt. | ||
* | ||
* @return string | ||
*/ | ||
public function getSalt() | ||
{ | ||
return $this->salt; | ||
} | ||
} |
Oops, something went wrong.