Repository: airavata-php-gateway Updated Branches: refs/heads/develop dfc40266b -> 11aa84d6a
AIRAVATA-2405 getUsersWithRole Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/11aa84d6 Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/11aa84d6 Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/11aa84d6 Branch: refs/heads/develop Commit: 11aa84d6a576fc27232fa67b6152243987e6d05d Parents: dfc4026 Author: Marcus Christie <machr...@iu.edu> Authored: Mon Jun 26 15:06:58 2017 -0400 Committer: Marcus Christie <machr...@iu.edu> Committed: Mon Jun 26 15:06:58 2017 -0400 ---------------------------------------------------------------------- app/controllers/AdminController.php | 14 +- .../Iam/Admin/Services/CPI/IamAdminServices.php | 322 +++++++++++++++++++ app/libraries/IamAdminServicesUtilities.php | 11 + 3 files changed, 335 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/11aa84d6/app/controllers/AdminController.php ---------------------------------------------------------------------- diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php index 3084b8b..0967cd7 100644 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -73,7 +73,7 @@ class AdminController extends BaseController { public function usersView(){ if( Input::has("role")) { - $users = AdminController::getUsersWithRole( Input::get("role")); + $users = IamAdminServicesUtilities::getUsersWithRole(Input::get("role")); } else $users = Keycloak::listUsers(); @@ -85,7 +85,7 @@ class AdminController extends BaseController { } public function getUserCountInRole(){ - $users = AdminController::getUsersWithRole( Input::get("role")); + $users = IamAdminServicesUtilities::getUsersWithRole(Input::get("role")); return count( $users); } @@ -409,16 +409,6 @@ class AdminController extends BaseController { } - public function getUsersWithRole( $role){ - $users = WSIS::getUserlistOfRole( $role); - if( isset( $users->return)) - $users = $users->return; - else - $users = array(); - - return $users; - } - /* ---- Super Admin Functions ------- */ http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/11aa84d6/app/libraries/Airavata/Service/Iam/Admin/Services/CPI/IamAdminServices.php ---------------------------------------------------------------------- diff --git a/app/libraries/Airavata/Service/Iam/Admin/Services/CPI/IamAdminServices.php b/app/libraries/Airavata/Service/Iam/Admin/Services/CPI/IamAdminServices.php index 0697595..963fc80 100644 --- a/app/libraries/Airavata/Service/Iam/Admin/Services/CPI/IamAdminServices.php +++ b/app/libraries/Airavata/Service/Iam/Admin/Services/CPI/IamAdminServices.php @@ -95,6 +95,14 @@ interface IamAdminServicesIf { * @throws \Airavata\API\Error\AuthorizationException */ public function removeRoleFromUser(\Airavata\Model\Security\AuthzToken $authzToken, $username, $roleName); + /** + * @param \Airavata\Model\Security\AuthzToken $authzToken + * @param string $roleName + * @return \Airavata\Model\User\UserProfile[] + * @throws \Airavata\Service\Iam\Admin\Services\CPI\Error\IamAdminServicesException + * @throws \Airavata\API\Error\AuthorizationException + */ + public function getUsersWithRole(\Airavata\Model\Security\AuthzToken $authzToken, $roleName); } class IamAdminServicesClient implements \Airavata\Service\Iam\Admin\Services\CPI\IamAdminServicesIf { @@ -634,6 +642,64 @@ class IamAdminServicesClient implements \Airavata\Service\Iam\Admin\Services\CPI throw new \Exception("removeRoleFromUser failed: unknown result"); } + public function getUsersWithRole(\Airavata\Model\Security\AuthzToken $authzToken, $roleName) + { + $this->send_getUsersWithRole($authzToken, $roleName); + return $this->recv_getUsersWithRole(); + } + + public function send_getUsersWithRole(\Airavata\Model\Security\AuthzToken $authzToken, $roleName) + { + $args = new \Airavata\Service\Iam\Admin\Services\CPI\IamAdminServices_getUsersWithRole_args(); + $args->authzToken = $authzToken; + $args->roleName = $roleName; + $bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) + { + thrift_protocol_write_binary($this->output_, 'getUsersWithRole', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite()); + } + else + { + $this->output_->writeMessageBegin('getUsersWithRole', TMessageType::CALL, $this->seqid_); + $args->write($this->output_); + $this->output_->writeMessageEnd(); + $this->output_->getTransport()->flush(); + } + } + + public function recv_getUsersWithRole() + { + $bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary'); + if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\Airavata\Service\Iam\Admin\Services\CPI\IamAdminServices_getUsersWithRole_result', $this->input_->isStrictRead()); + else + { + $rseqid = 0; + $fname = null; + $mtype = 0; + + $this->input_->readMessageBegin($fname, $mtype, $rseqid); + if ($mtype == TMessageType::EXCEPTION) { + $x = new TApplicationException(); + $x->read($this->input_); + $this->input_->readMessageEnd(); + throw $x; + } + $result = new \Airavata\Service\Iam\Admin\Services\CPI\IamAdminServices_getUsersWithRole_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + if ($result->Idse !== null) { + throw $result->Idse; + } + if ($result->ae !== null) { + throw $result->ae; + } + throw new \Exception("getUsersWithRole failed: unknown result"); + } + } // HELPER FUNCTIONS AND STRUCTURES @@ -2871,4 +2937,260 @@ class IamAdminServices_removeRoleFromUser_result { } +class IamAdminServices_getUsersWithRole_args { + static $_TSPEC; + + /** + * @var \Airavata\Model\Security\AuthzToken + */ + public $authzToken = null; + /** + * @var string + */ + public $roleName = null; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 1 => array( + 'var' => 'authzToken', + 'type' => TType::STRUCT, + 'class' => '\Airavata\Model\Security\AuthzToken', + ), + 2 => array( + 'var' => 'roleName', + 'type' => TType::STRING, + ), + ); + } + if (is_array($vals)) { + if (isset($vals['authzToken'])) { + $this->authzToken = $vals['authzToken']; + } + if (isset($vals['roleName'])) { + $this->roleName = $vals['roleName']; + } + } + } + + public function getName() { + return 'IamAdminServices_getUsersWithRole_args'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 1: + if ($ftype == TType::STRUCT) { + $this->authzToken = new \Airavata\Model\Security\AuthzToken(); + $xfer += $this->authzToken->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->roleName); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('IamAdminServices_getUsersWithRole_args'); + if ($this->authzToken !== null) { + if (!is_object($this->authzToken)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('authzToken', TType::STRUCT, 1); + $xfer += $this->authzToken->write($output); + $xfer += $output->writeFieldEnd(); + } + if ($this->roleName !== null) { + $xfer += $output->writeFieldBegin('roleName', TType::STRING, 2); + $xfer += $output->writeString($this->roleName); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + +class IamAdminServices_getUsersWithRole_result { + static $_TSPEC; + + /** + * @var \Airavata\Model\User\UserProfile[] + */ + public $success = null; + /** + * @var \Airavata\Service\Iam\Admin\Services\CPI\Error\IamAdminServicesException + */ + public $Idse = null; + /** + * @var \Airavata\API\Error\AuthorizationException + */ + public $ae = null; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 0 => array( + 'var' => 'success', + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => '\Airavata\Model\User\UserProfile', + ), + ), + 1 => array( + 'var' => 'Idse', + 'type' => TType::STRUCT, + 'class' => '\Airavata\Service\Iam\Admin\Services\CPI\Error\IamAdminServicesException', + ), + 2 => array( + 'var' => 'ae', + 'type' => TType::STRUCT, + 'class' => '\Airavata\API\Error\AuthorizationException', + ), + ); + } + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + if (isset($vals['Idse'])) { + $this->Idse = $vals['Idse']; + } + if (isset($vals['ae'])) { + $this->ae = $vals['ae']; + } + } + } + + public function getName() { + return 'IamAdminServices_getUsersWithRole_result'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 0: + if ($ftype == TType::LST) { + $this->success = array(); + $_size7 = 0; + $_etype10 = 0; + $xfer += $input->readListBegin($_etype10, $_size7); + for ($_i11 = 0; $_i11 < $_size7; ++$_i11) + { + $elem12 = null; + $elem12 = new \Airavata\Model\User\UserProfile(); + $xfer += $elem12->read($input); + $this->success []= $elem12; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 1: + if ($ftype == TType::STRUCT) { + $this->Idse = new \Airavata\Service\Iam\Admin\Services\CPI\Error\IamAdminServicesException(); + $xfer += $this->Idse->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRUCT) { + $this->ae = new \Airavata\API\Error\AuthorizationException(); + $xfer += $this->ae->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('IamAdminServices_getUsersWithRole_result'); + if ($this->success !== null) { + if (!is_array($this->success)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('success', TType::LST, 0); + { + $output->writeListBegin(TType::STRUCT, count($this->success)); + { + foreach ($this->success as $iter13) + { + $xfer += $iter13->write($output); + } + } + $output->writeListEnd(); + } + $xfer += $output->writeFieldEnd(); + } + if ($this->Idse !== null) { + $xfer += $output->writeFieldBegin('Idse', TType::STRUCT, 1); + $xfer += $this->Idse->write($output); + $xfer += $output->writeFieldEnd(); + } + if ($this->ae !== null) { + $xfer += $output->writeFieldBegin('ae', TType::STRUCT, 2); + $xfer += $this->ae->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/11aa84d6/app/libraries/IamAdminServicesUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/IamAdminServicesUtilities.php b/app/libraries/IamAdminServicesUtilities.php index d5e20ea..fbb208e 100644 --- a/app/libraries/IamAdminServicesUtilities.php +++ b/app/libraries/IamAdminServicesUtilities.php @@ -27,6 +27,17 @@ class IamAdminServicesUtilities { return IamAdminServices::resetUserPassword($admin_authz_token, $username, $new_password); } + public static function getUsersWithRole($role_name) { + + $authz_token = Session::get('authz-token'); + $user_profiles = IamAdminServices::getUsersWithRole($authz_token, $role_name); + $users = []; + foreach ($user_profiles as $user_profile) { + $users[] = $user_profile->userId; + } + return $users; + } + private static function getAdminAuthzToken() { return Keycloak::getAdminAuthzToken(); }