setName('kekrozsak:security:init') ->setDescription('Initializes ACLs') ->setHelp(<<%command.full_name% command fills up the ACL tables with default ACLs. php %command.full_name% ACL lists are currently hard-coded. EOF ) ; } protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); $this->verbose = $input->getOption('verbose'); } /** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $securityContext = $container->get('security.context'); $aclProvider = $container->get('security.acl.provider'); $classNames = array( 'KekRozsak\\FrontBundle\\Entity\\News', 'KekRozsak\\FrontBundle\\Entity\\Articles', ); $securityIdentity = new RoleSecurityIdentity('ROLE_ADMIN'); foreach ($classNames as $className) { $objectIdentity = new ObjectIdentity('class', $className); try { $acl = $aclProvider->findAcl($objectIdentity, array($securityIdentity)); } catch (AclNotFoundException $e) { $acl = $aclProvider->createAcl($objectIdentity); } $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER); $aclProvider->updateAcl($acl); } } }