Пример #1
0
 public static function getRelatedFromAuth(Auth $auth)
 {
     $ret = array();
     $pm = new PolicyManager();
     $am = new ApiManager();
     $allPolicies = $pm->getAllPolicies(true);
     $relatedPolicies = array();
     $policyPropsArr = array();
     $allApis = $am->getAllApis(true);
     $relatedApiIds = array();
     $relatedApis = array();
     $apiPropsArr = array();
     foreach ($allPolicies as $policy) {
         /**
          * @var Policy $policy
          */
         foreach ($policy->getAuthIds() as $authBucket) {
             if ($authBucket && $authBucket->getAuthIds() && in_array($auth->getId(), $authBucket->getAuthIds())) {
                 $relatedPolicies[] = $policy;
             }
         }
         //            foreach($authIds as $authId){
         //                if($authId === $auth->getId()){
         //                }
         //            }
     }
     foreach ($relatedPolicies as $policy) {
         $props = $policy->getProperties();
         if (!empty($props)) {
             $policyPropsArr[$policy->getId()] = array_keys($props);
         }
         $relatedApiIds = array_unique(array_merge($relatedApiIds, $policy->getApiIds()));
     }
     foreach ($allApis as $api) {
         /**
          * @var $api Api
          */
         if (in_array($api->getId(), $relatedApiIds)) {
             $relatedApis[] = $api;
         }
     }
     foreach ($relatedApis as $api) {
         $props = $api->getProperties();
         if (!empty($props)) {
             if ($api->getDisplayName()) {
                 $apiPropsArr[$api->getDisplayName()] = array_keys($props);
             } else {
                 $apiPropsArr[$api->getId()] = array_keys($props);
             }
         }
     }
     if (!empty($policyPropsArr)) {
         $ret["policy"] = $policyPropsArr;
     }
     if (!empty($apiPropsArr)) {
         $ret["api"] = $apiPropsArr;
     }
     return json_encode($ret);
 }
Пример #2
0
         if ($policy === null) {
             $policy = $this->policyManager->getPolicy($id);
             $flowScope['isNew'] = false;
             $flowScope["relatedProperties"] = JsonPropertyPrinter::getRelatedFromPolicy($policy);
         }
     }
     /**
      * Put the policy in the flow scope for reference by other states and the views
      */
     $flowScope['policy'] = $policy;
 }
 /**
  * On-exit callback for the "form" state
  * it should take the form submission and deserialize it into a Policy object and
  * stick it on the flowScope.
  *
  * @param $action
  * @param $flowScope
  */
 public function deserializeForm($action, &$flowScope)
 {
     /**
      * @var Policy $policy
      */
     $policy = $flowScope['policy'];
     // Only accept the id if we are creating a new one
     if ($flowScope['isNew']) {
         $policy->id = $this->_getParam('policy_id');
     }
     $policy->setApiIds($this->getSelectedApis());
     $policy->setAuthIds($this->getSelectedAuths());
     $context = $this->getContextAndRates();
     if ($context != null) {
         $contexts[] = $context;
         $policy->setContexts($contexts);
     }
     $policy->headerTransformations = SharedViewUtility::deserializeHeaderTransformations($this->getRequest());
Пример #3
0
 /**
  * Callback function for the on-exit of the Auth subflow
  * We have already created the API and the Auth(s) so now we need to create a Policy
  * to hook them together
  * @param $action
  * @param $flowScope
  */
 public function postAuthSubflow($action, &$flowScope)
 {
     $registry = Zend_Registry::getInstance();
     $translate = $registry->get("Zend_Translate");
     $authIds = $flowScope['authIds'];
     /**  @var Api $api*/
     $api = $flowScope['api'];
     $policy = PolicyController::createBasicPolicy(null, array($api->id), $authIds);
     $pm = new PolicyManager();
     $result = $pm->createPolicy($policy);
     if ($result) {
         $this->_helper->FlashMessenger($translate->translate("Policy Created: ") . $policy->id);
     } else {
         $this->_helper->FlashMessenger($translate->translate("Error creating Policy"));
     }
 }
Пример #4
0
 /**
  * If no param, returns last error
  * If param is exception, logs exception and sets error
  * If param is String, sets error
  *
  * @static
  * @param null $err
  * @return mixed
  */
 public static function error($err = null)
 {
     if ($err == null) {
         return PolicyManager::$error;
     }
     if ($err instanceof Exception) {
         PolicyManager::$error = $err->getMessage();
         LoggerInterface::logException($err, LoggerInterface::ERROR);
     } else {
         PolicyManager::$error = $err;
         LoggerInterface::log($err, LoggerInterface::ERROR);
     }
 }