Esempio n. 1
0
 public function rulesInit()
 {
     $role = $this->roleService->getRoleName("admin");
     $rule = null;
     try {
         $rule = $this->ruleService->getUniqueRule($role);
     } catch (Exceptions\NoResultException $ex) {
         $this->logger->addDebug($ex->getMessage());
     }
     if ($rule === null) {
         $this->logger->addInfo("Security module initializer - AclRules - no godlike Rule for role {$role} found. New one is gonna be created.");
         $rule = new AclRule();
         $rule->setRole($role);
         $rule->setResource(null);
         $rule->setPrivilege(null);
         $rule->setMode(\App\Model\Misc\Enum\AclMode::PERMIT);
         $this->ruleService->createRule($rule);
     }
 }
Esempio n. 2
0
 public function updateRule(AclRule $arule)
 {
     if ($arule === null) {
         throw new Exceptions\NullPointerException("Argument AclRule cannot be null");
     }
     try {
         $this->entityManager->beginTransaction();
         $dbRule = $this->aclRuleDao->find($arule->getId());
         if ($dbRule !== null) {
             $dbRule->fromArray($arule->toArray());
             $this->roleTypeHandle($dbRule);
             $this->entityManager->merge($dbRule);
             $this->entityManager->flush();
         }
         $this->entityManager->commit();
         $this->invalidateEntityCache($dbRule);
         $this->onUpdate($dbRule);
     } catch (DuplicateEntryException $e) {
         $this->entityManager->rollback();
         $this->logWarning($e);
         throw new Exceptions\DuplicateEntryException($e->getMessage(), $e->getCode(), $e->getPrevious());
     } catch (\Exception $e) {
         $this->entityManager->rollback();
         $this->logError($e);
         throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }