Пример #1
0
 /**
  * delete
  *
  * @param string $id id
  *
  * @return mixed|JsonModel
  */
 public function delete($id)
 {
     // ACCESS CHECK
     if (!$this->isAllowed(RcmUserAclResourceProvider::RESOURCE_ID_ACL, 'delete')) {
         return $this->getNotAllowedResponse();
     }
     $aclDataService = $this->getServiceLocator()->get('RcmUser\\Acl\\AclDataService');
     try {
         $data = json_decode($this->getRequest()->getContent(), true);
         //$data = json_decode(urldecode($id), true);
         $aclRule = new AclRule();
         $aclRule->populate($data);
         $result = $aclDataService->deleteRule($aclRule);
     } catch (\Exception $e) {
         return $this->getExceptionResponse($e);
     }
     return $this->getJsonResponse($result);
 }
Пример #2
0
 /**
  * read
  *
  * @param AclRule $aclRule the aclRule
  *
  * @return Result
  */
 public function read(AclRule $aclRule)
 {
     $rule = $aclRule->getRule();
     $roleId = $aclRule->getRoleId();
     $resourceId = $aclRule->getResourceId();
     $privileges = $aclRule->getPrivileges();
     // check required
     if (empty($rule) || empty($roleId) || empty($resourceId)) {
         return new Result(null, Result::CODE_FAIL, "Rule could not be found by rule, roleId and resourceId.");
     }
     $query = $this->getEntityManager()->createQuery('SELECT rule FROM ' . $this->getEntityClass() . ' rule ' . 'WHERE rule.rule = ?1 ' . 'AND rule.roleId = ?2 ' . 'AND rule.resourceId = ?3 ' . 'AND rule.privileges = ?4');
     $query->setParameter(1, $rule);
     $query->setParameter(2, $roleId);
     $query->setParameter(3, $resourceId);
     $query->setParameter(4, json_encode($privileges));
     $rules = $query->getResult();
     if (empty($rules[0])) {
         return new Result([]);
     }
     return new Result($rules[0]);
 }
 /**
  * getAclRule
  *
  * @param        $roleId
  * @param        $resourceId
  * @param string $allowDeny
  *
  * @return AclRule
  * @throws \RcmUser\Exception\RcmUserException
  */
 protected function getAclRule($roleId, $resourceId, $allowDeny = 'allow')
 {
     $rule = new AclRule();
     $rule->setRoleId($roleId);
     $rule->setRule($allowDeny);
     $rule->setResourceId($resourceId);
     $rule->setPrivilege('read');
     return $rule;
 }
Пример #4
0
 /**
  * testArrayIterator
  *
  * @covers \RcmUser\Acl\Entity\AclRule::getIterator
  *
  * @return void
  */
 public function testArrayIterator()
 {
     $aclRule = new AclRule();
     $rule = 'allow';
     $roleId = 'role';
     $resource = 'someresource';
     $privileges = ['someprivilege'];
     $aclRule->setRule($rule);
     $aclRule->setRoleId($roleId);
     $aclRule->setResourceId($resource);
     $aclRule->setPrivileges($privileges);
     $iter = $aclRule->getIterator();
     $array1 = iterator_to_array($aclRule);
     $array2 = iterator_to_array($iter);
     $this->assertTrue($array1 == $array2, 'Iterator failed work.');
     $this->assertTrue(is_array($array1), 'Iterator failed work.');
     $this->assertArrayHasKey('rule', $array1, 'Iterator did not populate correctly.');
 }
Пример #5
0
 /**
  * populate
  *
  * @param array|AclRule $data data
  *
  * @return void
  * @throws RcmUserException
  */
 public function populate($data = [])
 {
     if ($data instanceof AclRule) {
         $this->setRule($data->getRule());
         $this->setRoleId($data->getRoleId());
         $this->setResourceId($data->getResourceId());
         $this->setPrivileges($data->getPrivileges());
         $this->setAssertion($data->getAssertion());
         return;
     }
     if (is_array($data)) {
         if (isset($data['rule'])) {
             $this->setRule($data['rule']);
         }
         if (isset($data['roleId'])) {
             $this->setRoleId($data['roleId']);
         }
         if (isset($data['resourceId'])) {
             $this->setResourceId($data['resourceId']);
         }
         // @bc This is only here to support older versions
         if (isset($data['privilege'])) {
             $this->setPrivilege($data['privilege']);
         }
         if (isset($data['privileges'])) {
             $this->setPrivileges($data['privileges']);
         }
         if (isset($data['assertion'])) {
             $this->setAssertion($data['assertion']);
         }
         return;
     }
     throw new RcmUserException('Rule data could not be populated, data format not supported');
 }
Пример #6
0
 /**
  * createRule
  *
  * @param AclRule $aclRule aclRule
  *
  * @return Result
  */
 public function deleteRule(AclRule $aclRule)
 {
     $rule = $aclRule->getRule();
     $roleId = $aclRule->getRoleId();
     $resource = $aclRule->getResourceId();
     // check required
     if (empty($rule) || empty($roleId) || empty($resource)) {
         return new Result(null, Result::CODE_FAIL, "Rule requires: rule, roleId and resourceId.");
     }
     // check if exists and get valid id
     $result = $this->aclRuleDataMapper->read($aclRule);
     if (!$result->isSuccess()) {
         return $result;
     }
     return $this->aclRuleDataMapper->delete($result->getData());
 }