From 2040a6d4e69d80d297f26bf2374d218116190980 Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Sun, 3 May 2015 14:42:20 +0530 Subject: [PATCH 1/2] Wrapping Identitiy Server Code as a Laravel package --- app/config/app.php | 4 +- app/config/app_config.ini.template | 33 +- app/config/workbench.php | 4 +- app/controllers/AccountController.php | 3 +- app/controllers/AdminController.php | 4 +- app/libraries/CRUtilities.php | 3 +- app/libraries/userapi_config.ini | 14 - app/libraries/userapi_utilities.php | 394 ------------------ app/libraries/utilities.php | 3 - app/libraries/wsis_config.ini | 27 -- app/libraries/wsis_utilities.php | 88 +--- app/libraries/xml_id_utilities.php | 42 ++ workbench/airavata/wsis/.gitignore | 4 + workbench/airavata/wsis/.travis.yml | 13 + workbench/airavata/wsis/composer.json | 20 + workbench/airavata/wsis/phpunit.xml | 18 + .../wsis/src/Airavata/Wsis/Facades/Wsis.php | 16 + .../Airavata/Wsis/Stubs}/TenantManager.php | 3 +- .../Wsis/Stubs/TenantMgtAdminStub.php | 2 + .../Airavata/Wsis/Stubs}/UserStoreManager.php | 3 +- .../Wsis/Stubs/UserStoreManagerStub.php | 2 + .../airavata/wsis/src/Airavata/Wsis/Wsis.php | 92 ++-- .../src/Airavata/Wsis/WsisServiceProvider.php | 64 +++ workbench/airavata/wsis/src/config/config.php | 52 +++ workbench/airavata/wsis/tests/.gitkeep | 0 25 files changed, 313 insertions(+), 595 deletions(-) mode change 100644 => 100755 app/config/app_config.ini.template mode change 100644 => 100755 app/controllers/AdminController.php mode change 100644 => 100755 app/libraries/CRUtilities.php delete mode 100755 app/libraries/userapi_config.ini delete mode 100755 app/libraries/userapi_utilities.php delete mode 100755 app/libraries/wsis_config.ini create mode 100755 workbench/airavata/wsis/.gitignore create mode 100755 workbench/airavata/wsis/.travis.yml create mode 100755 workbench/airavata/wsis/composer.json create mode 100755 workbench/airavata/wsis/phpunit.xml create mode 100755 workbench/airavata/wsis/src/Airavata/Wsis/Facades/Wsis.php rename {app/libraries/UserStoreManager => workbench/airavata/wsis/src/Airavata/Wsis/Stubs}/TenantManager.php (98%) rename app/libraries/UserStoreManager/TenantMgtAdmin.stub.php => workbench/airavata/wsis/src/Airavata/Wsis/Stubs/TenantMgtAdminStub.php (99%) mode change 100644 => 100755 rename {app/libraries/UserStoreManager => workbench/airavata/wsis/src/Airavata/Wsis/Stubs}/UserStoreManager.php (98%) rename app/libraries/UserStoreManager/UserStoreManager.stub.php => workbench/airavata/wsis/src/Airavata/Wsis/Stubs/UserStoreManagerStub.php (99%) rename app/libraries/WSISClient.php => workbench/airavata/wsis/src/Airavata/Wsis/Wsis.php (87%) create mode 100755 workbench/airavata/wsis/src/Airavata/Wsis/WsisServiceProvider.php create mode 100644 workbench/airavata/wsis/src/config/config.php create mode 100755 workbench/airavata/wsis/tests/.gitkeep diff --git a/app/config/app.php b/app/config/app.php index 39aee3849..1b4c90f53 100755 --- a/app/config/app.php +++ b/app/config/app.php @@ -121,7 +121,7 @@ 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Illuminate\Workbench\WorkbenchServiceProvider', - + 'Airavata\Wsis\WsisServiceProvider', ), /* @@ -188,7 +188,7 @@ 'URL' => 'Illuminate\Support\Facades\URL', 'Validator' => 'Illuminate\Support\Facades\Validator', 'View' => 'Illuminate\Support\Facades\View', - + 'WSIS' => 'Airavata\Wsis\Facades\Wsis', ), ); diff --git a/app/config/app_config.ini.template b/app/config/app_config.ini.template old mode 100644 new mode 100755 index 3ec74f016..0d7c97be4 --- a/app/config/app_config.ini.template +++ b/app/config/app_config.ini.template @@ -1,34 +1,3 @@ -;--------------------------------------- Identity Server Constants ---------------------- - -;Admin Role Name -admin-role-name = "admin" -;Gateway User Role -gateway-admin = "Internal/everyone" - -;Tenant admin's username -admin-username = “$username” - -;Tenant admin's password -admin-password = “$password” - -;Identity server domain -server = "idp.scigap.org" - -;Identity server web services endpoint -service-url = "https://idp.scigap.org:7443/services/" - -;Gateway Domain Name -gateway-id = “$gatewayname” - -;Path the to server certificate file -cafile-path = "/resources/security/idp_scigap_org.pem" - -;Enable HTTPS server verification -verify-peer = true - -;Allow self signed server certificates -allow-self-signed = false - ;--------------------------------------- Airavata Constants ---------------------- @@ -45,7 +14,7 @@ experiment-data-root = '/../experimentData/' ssh-user = 'root' data-path = 'file://home/pga/production/experimentData/' experiment-data-root-absolute = '/var/www/experimentData/' -;USER_STORE = 'WSO2','XML','USER_API' +;USER_STORE = 'WSO2','XML' user-store = "WSO2" admin-role = "admin" gateway-admin-role = "gateway_admin" diff --git a/app/config/workbench.php b/app/config/workbench.php index 87c5e3879..f4a663b2a 100755 --- a/app/config/workbench.php +++ b/app/config/workbench.php @@ -13,7 +13,7 @@ | */ - 'name' => '', + 'name' => 'Apache Airavata', /* |-------------------------------------------------------------------------- @@ -26,6 +26,6 @@ | */ - 'email' => '', + 'email' => 'dev@airavata.apache.org', ); diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index c80672ff7..752c05de8 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -80,8 +80,7 @@ public function loginSubmit(){ Utilities::store_id_in_session($username); Utilities::print_success_message('Login successful! You will be redirected to your home page shortly.'); - $app_config = Utilities::read_config(); - Session::put("gateway_id", $app_config["gateway-id"]); + Session::put("gateway_id", Config::get('wsis::gateway-id')); //TODO::If this option is not safe, have to find a better method to send credentials to identity server on every connection. Session::put("password", $_POST["password"]); diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php old mode 100644 new mode 100755 index c55718ec5..5f0b51c65 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -73,9 +73,9 @@ public function addGatewayAdminSubmit(){ { //add user to admin role $app_config = Utilities::read_config(); - $idStore->updateRoleListOfUser( Input::get("username"), array( "new"=>array( $app_config["admin-role-name"]), "deleted"=>array() ) ); + $idStore->updateRoleListOfUser( Input::get("username"), array( "new"=>array( Config::get('wsis::admin-role-name')), "deleted"=>array() ) ); - return Redirect::to("admin/dashboard/users?role=" . $app_config["admin-role-name"])->with("Gateway Admin has been added."); + return Redirect::to("admin/dashboard/users?role=" . Config::get('wsis::admin-role-name'))->with("Gateway Admin has been added."); } else diff --git a/app/libraries/CRUtilities.php b/app/libraries/CRUtilities.php old mode 100644 new mode 100755 index 8f55099f3..98fa54e23 --- a/app/libraries/CRUtilities.php +++ b/app/libraries/CRUtilities.php @@ -406,8 +406,7 @@ public static function getAllGatewayProfilesData(){ $gateways = $airavataclient->getAllGateways(); else { - $app_config = Utilities::read_config(); - $gateways[0] = $airavataclient->getGateway( $app_config["gateway-id"]); + $gateways[0] = $airavataclient->getGateway( Config::get('wsis::gateway-id')); } $gatewayProfiles = $airavataclient->getAllGatewayComputeResources(); diff --git a/app/libraries/userapi_config.ini b/app/libraries/userapi_config.ini deleted file mode 100755 index ad96b5d4d..000000000 --- a/app/libraries/userapi_config.ini +++ /dev/null @@ -1,14 +0,0 @@ -;Tenant admin's username -admin-username = "admin@phprg.scigap.org" - -;Tenant admin's password -admin-password = "prodphprgadmin@scigap.org" - -;user api server host -server-host = "gw127.iu.xsede.org" - -;user api server port -server-port = "9930" - -;thrift transport timeout -thrift-timeout = "5000" diff --git a/app/libraries/userapi_utilities.php b/app/libraries/userapi_utilities.php deleted file mode 100755 index 31cf1f783..000000000 --- a/app/libraries/userapi_utilities.php +++ /dev/null @@ -1,394 +0,0 @@ -userapi_client_factory = new UserAPIClientFactory($properties); - $this->userapi_client = $this->userapi_client_factory->getUserAPIClient(); - //testing the API - $this->userapi_client->getAPIVersion(); - } catch (Exception $ex) { - print_r( $ex); exit; - throw new Exception('Unable to instantiate UserAPI client.', 0, NULL); - } - } - - /** - * Return true if the given username exists in the identity server. - * @param $username - * @return bool - */ - public function username_exists($username) { - try{ - return $this->userapi_client->checkUsernameExists($username,$this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to check whether username exists", 0, NULL); - } - - } - - /** - * authenticate a given user - * @param $username - * @param $password - * @return boolean - */ - public function authenticate($username, $password) { - try{ - $apiPermissions = $this->userapi_client->authenticateUser($username, $password, $this->getAPIToken()); - return true; - } catch (Exception $ex) { - throw new Exception("Unable to authenticate user", 0, NULL); - } - } - - /** - * Add a new user to the identity server. - * @param $username - * @param $password - * @return void - */ - public function add_user($username, $password, $first_name, $last_name, $email, $organization, - $address, $country,$telephone, $mobile, $im, $url) { - try{ - $profile = new UserProfile(); - $profile->firstName = $first_name; - $profile->lastName = $last_name; - $profile->emailAddress = $email; - $profile->organization = $organization; - $profile->address = $address; - $profile->country = $country; - $profile->telephone = $telephone; - $profile->mobile = $mobile; - $profile->im = $im; - $profile->url = $url; - - $this->userapi_client->createNewUser($username, $password, $profile, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to add new user", 0, NULL); - } - } - - /** - * Get the user profile - * @param $username - * @return mixed|void - */ - public function get_user_profile($username) - { - try{ - $profile_obj = $this->userapi_client->getUserProfile($username, $this->getAPIToken()); - $profile_arr = array(); - $profile_arr['first_name'] = $profile_obj->firstName; - $profile_arr['last_name'] = $profile_obj->lastName; - $profile_arr['email_address'] = $profile_obj->emailAddress; - $profile_arr['organization'] = $profile_obj->organization; - $profile_arr['address'] = $profile_obj->address; - $profile_arr['country'] = $profile_obj->country; - $profile_arr['telephone'] = $profile_obj->telephone; - $profile_arr['mobile'] = $profile_obj->mobile; - $profile_arr['im'] = $profile_obj->im; - $profile_arr['url'] = $profile_obj->url; - return $profile_arr; - } catch (Exception $ex) { - throw new Exception("Unable to get user profile", 0, NULL); - } - } - - /** - * Update the user profile - * - * @param $username - * @param $first_name - * @param $last_name - * @param $email - * @param $organization - * @param $address - * @param $country - * @param $telephone - * @param $mobile - * @param $im - * @param $url - * @return mixed - */ - public function update_user_profile($username, $first_name, $last_name, $email, $organization, $address, - $country, $telephone, $mobile, $im, $url) - { - try{ - $profile = new UserProfile(); - $profile->firstName = $first_name; - $profile->lastName = $last_name; - $profile->emailAddress = $email; - $profile->organization = $organization; - $profile->address = $address; - $profile->country = $country; - $profile->telephone = $telephone; - $profile->mobile = $mobile; - $profile->im = $im; - $profile->url = $url; - $this->userapi_client->updateUserProfile($username, $profile, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to update user profile", 0, NULL); - } - } - - /** - * Function to update user password - * - * @param $username - * @param $current_password - * @param $new_password - * @return mixed - */ - public function change_password($username, $current_password, $new_password) - { - try{ - $this->userapi_client->updateUserPassword($username, $new_password, $current_password, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to update user password", 0, NULL); - } - } - - /** - * Function to get the API token for the gateway - * @throws Exception - */ - private function getAPIToken(){ - $userapi_token_db = simplexml_load_file(self::USERAPI_TOKEN_DB_PATH); - $userapi_config = parse_ini_file(self::USER_API_CONFIG_PATH); - $token = $userapi_token_db->userapi_token[0]->token_string; - $issue_time = $userapi_token_db->userapi_token[0]->issue_time; - $life_time = $userapi_token_db->userapi_token[0]->life_time; - if (file_exists(self::USER_API_CONFIG_PATH)) { - if(empty($token) || (time()-$issue_time )>($life_time-5000)){ - $authenticationResponse = $this->userapi_client->authenticateGateway($userapi_config['admin-username'], - $userapi_config['admin-password']); - $userapi_token_db->userapi_token[0]->token_string = $authenticationResponse->accessToken; - $token = $authenticationResponse->accessToken; - $userapi_token_db->userapi_token[0]->issue_time = time(); - $userapi_token_db->userapi_token[0]->life_time = $authenticationResponse->expiresIn; - - //Format XML to save indented tree rather than one line - $dom = new DOMDocument('1.0'); - $dom->preserveWhiteSpace = false; - $dom->formatOutput = true; - $dom->loadXML($userapi_token_db->asXML()); - $dom->save(self::USERAPI_TOKEN_DB_PATH); - } - } else { - throw new Exception("Error: Cannot open userapi_config.xml file!"); - } - return $token; - } - - /** - * Function to remove an existing user - * - * @param $username - * @return void - */ - public function remove_user($username) - { - try{ - $this->userapi_client->removeUser($username, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to remove user", 0, NULL); - } - } - - /** - * Function to check whether a user has permission for a particular permission string(api method). - * - * @param $username - * @param $permission_string - * @return bool - */ - public function checkPermissionForUser($username, $permission_string) - { - try{ - return $this->userapi_client->checkPermission($username,$permission_string, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to check permission for user", 0, NULL); - } - } - - /** - * Function to get all the permissions that a particular user has. - * - * @param $username - * @return mixed - */ - public function getUserPermissions($username) - { - try{ - $apiPermissions = $this->userapi_client->getUserPermissions($username, $this->getAPIToken()); - $result['airavata-api'] = $apiPermissions->airavataAPIPermissions; - $result['app-catalog'] = $apiPermissions->airavataAppCatalogPermissions; - return $result; - } catch (Exception $ex) { - throw new Exception("Unable add user to role", 0, NULL); - } - } - - /** - * Function to get the entire list of roles in the application - * - * @return mixed - */ - public function getRoleList() - { - try{ - return $this->userapi_client->getAllRoleNames($this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to get roles list", 0, NULL); - } - } - - /** - * Function to get the role list of a user - * - * @param $username - * @return mixed - */ - public function getRoleListOfUser($username) - { - try{ - return $this->userapi_client->getRoleListOfUser($username, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to get role list of user", 0, NULL); - } - } - - /** - * Function to get the user list of a particular role - * - * @param $role - * @return mixed - */ - public function getUserListOfRole($role) - { - try{ - return $this->userapi_client->getUserListOfRole($role, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to get user list of role", 0, NULL); - } - } - - /** - * Function to add a role to a user - * - * @param $username - * @param $role - * @return mixed - */ - public function addUserToRole($username, $role) - { - try{ - return $this->userapi_client->addUserToRole($username,$role, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to add user to role", 0, NULL); - } - } - - /** - * Function to role from user - * - * @param $username - * @param $role - * @return mixed - */ - public function removeUserFromRole($username, $role) - { - try{ - return $this->userapi_client->removeUserFromRole($username,$role, $this->getAPIToken()); - } catch (Exception $ex) { - throw new Exception("Unable to remove user from role", 0, NULL); - } - } -} diff --git a/app/libraries/utilities.php b/app/libraries/utilities.php index a45667370..56d460e8a 100644 --- a/app/libraries/utilities.php +++ b/app/libraries/utilities.php @@ -207,9 +207,6 @@ public static function connect_to_id_store() case 'XML': $idStore = new XmlIdUtilities(); // XML user database break; - case 'USER_API': - $idStore = new UserAPIUtilities(); // Airavata UserAPI - break; } try diff --git a/app/libraries/wsis_config.ini b/app/libraries/wsis_config.ini deleted file mode 100755 index 6afe6389f..000000000 --- a/app/libraries/wsis_config.ini +++ /dev/null @@ -1,27 +0,0 @@ -;Tenant admin's username -;admin-username = "test@testphprg.scigap.org" -;Super Tenant Admin's username -admin-username = "scigap_admin" - -;Tenant admin's password -;admin-password = "testadmin@scigap.org" -;Super Tenant Admin's username -admin-password = "sci9067@min" - -;Identity server domain -server = "idp.scigap.org" - -;Identity server web services endpoint -service-url = "https://idp.scigap.org:7443/services/" - -;Gateway Domain Name -gateway-id = "airavata.org" - -;Path the to server certificate file -cafile-path = "/resources/security/idp_scigap_org.pem" - -;Enable HTTPS server verification -verify-peer = true - -;Allow self signed server certificates -allow-self-signed = false \ No newline at end of file diff --git a/app/libraries/wsis_utilities.php b/app/libraries/wsis_utilities.php index fbf90f87b..530fa52d8 100755 --- a/app/libraries/wsis_utilities.php +++ b/app/libraries/wsis_utilities.php @@ -1,65 +1,12 @@ wsis_client = new WSISClient( - $username, - $password, - $wsis_config['server'], - $wsis_config['service-url'], - $wsis_config['cafile-path'], - $wsis_config['verify-peer'], - $wsis_config['allow-self-signed'] - ); - } /** * Return true if the given username exists in the identity server. @@ -69,7 +16,7 @@ public function connect() { public function username_exists($username) { try{ //$this->wsis_client = new WSISClient( $username); - return $this->wsis_client->username_exists($username); + return WSIS::username_exists($username); } catch (Exception $ex) { print_r( $ex); throw new Exception("Unable to check whether username exists", 0, NULL); @@ -85,7 +32,7 @@ public function username_exists($username) { */ public function authenticate($username, $password) { try{ - return $this->wsis_client->authenticate($username, $password); + return WSIS::authenticate($username, $password); } catch (Exception $ex) { var_dump( $ex); throw new Exception("Unable to authenticate user", 0, NULL); @@ -101,7 +48,7 @@ public function authenticate($username, $password) { public function add_user($username, $password, $first_name, $last_name, $email, $organization, $address, $country,$telephone, $mobile, $im, $url) { try{ - $this->wsis_client->addUser($username, $password, $first_name . " " . $last_name); + WSIS::addUser($username, $password, $first_name . " " . $last_name); } catch (Exception $ex) { var_dump($ex); throw new Exception("Unable to add new user", 0, NULL); @@ -195,7 +142,7 @@ public function getUserPermissions($username) */ public function isExistingRole( $roleName){ try{ - return $this->wsis_client->is_existing_role( $roleName); + return WSIS::is_existing_role( $roleName); } catch (Exception $ex) { var_dump($ex); throw new Exception("Unable to check if role exists.", 0, $ex); @@ -209,7 +156,7 @@ public function isExistingRole( $roleName){ */ public function addRole($roleName){ try{ - return $this->wsis_client->add_role( $roleName); + return WSIS::add_role( $roleName); } catch (Exception $ex) { var_dump( $ex); throw new Exception("Unable to add role.", 0, $ex); @@ -225,7 +172,7 @@ public function addRole($roleName){ */ public function deleteRole($roleName) { try { - $this->wsis_client->delete_role($roleName); + WSIS::delete_role($roleName); } catch (Exception $ex) { throw new Exception("Unable to delete role", 0, $ex); } @@ -239,7 +186,7 @@ public function deleteRole($roleName) { public function getRoleNames() { try{ - return $this->wsis_client->get_all_roles(); + WSIS::get_all_roles(); } catch (Exception $ex) { var_dump($ex); throw new Exception("Unable to get roles.", 0, NULL); @@ -255,7 +202,7 @@ public function getRoleNames() public function getRoleListOfUser($username) { try{ - return $this->wsis_client->get_user_roles( $username); + return WSIS::get_user_roles( $username); } catch (Exception $ex) { var_dump($ex); throw new Exception("Unable to get roles.", 0, NULL); @@ -271,7 +218,7 @@ public function getRoleListOfUser($username) public function getUserListOfRole($role) { try{ - return $this->wsis_client->get_userlist_of_role( $role); + return WSIS::get_userlist_of_role( $role); } catch (Exception $ex) { var_dump( $ex); exit; throw new Exception("Unable to get users.", 0, NULL); @@ -307,7 +254,7 @@ public function addUserToRole($username, $role) public function updateRoleListOfUser($username, $roles) { try{ - return $this->wsis_client->update_user_roles( $username, $roles); + return WSIS::update_user_roles( $username, $roles); } catch (Exception $ex) { var_dump($ex); exit; throw new Exception("Unable to update User roles.", 0, NULL); @@ -326,7 +273,7 @@ public function removeUserFromRole($username, $role) */ public function listUsers(){ try { - return $this->wsis_client->list_users(); + return WSIS::list_users(); } catch (Exception $ex) { throw new Exception( "Unable to list users", 0, $ex); @@ -341,7 +288,7 @@ public function listUsers(){ */ public function getTenantId(){ try { - return $this->wsis_client->get_tenant_id(); + return WSIS::get_tenant_id(); } catch (Exception $ex) { var_dump( $ex->debug_message); throw new Exception("Unable to get the Tenant Id.", 0, $ex); @@ -355,10 +302,19 @@ public function getTenantId(){ */ public function createTenant( $inputs){ try { - return $this->wsis_client->create_tenant( $inputs); + return WSIS::create_tenant( $inputs); } catch (Exception $ex) { var_dump( $ex); //throw new Exception("Unable to create Tenant.", 0, $ex); } } + + /** + * Connect to the user database. + * @return mixed|void + */ + public function connect() + { + // TODO: Implement connect() method. + } } diff --git a/app/libraries/xml_id_utilities.php b/app/libraries/xml_id_utilities.php index 6b5476746..0ba976046 100755 --- a/app/libraries/xml_id_utilities.php +++ b/app/libraries/xml_id_utilities.php @@ -249,4 +249,46 @@ public function removeUserFromRole($username, $role) { // TODO: Implement removeUserFromRole() method. } + + /** + * Function to get the entire list of roles in the application + * + * @return mixed + */ + public function getRoleNames() + { + // TODO: Implement getRoleNames() method. + } + + /** + * Function to check whether a role is existing + * + * @param string $roleName + * @return IsExistingRoleResponse + */ + public function isExistingRole($roleName) + { + // TODO: Implement isExistingRole() method. + } + + /** + * Function to add new role by providing the role name. + * + * @param string $roleName + */ + public function addRole($roleName) + { + // TODO: Implement addRole() method. + } + + /** + * Function to update role list of user + * + * @param UpdateRoleListOfUser $parameters + * @return void + */ + public function updateRoleListOfUser($username, $roles) + { + // TODO: Implement updateRoleListOfUser() method. + } } diff --git a/workbench/airavata/wsis/.gitignore b/workbench/airavata/wsis/.gitignore new file mode 100755 index 000000000..582640226 --- /dev/null +++ b/workbench/airavata/wsis/.gitignore @@ -0,0 +1,4 @@ +/vendor +composer.phar +composer.lock +.DS_Store diff --git a/workbench/airavata/wsis/.travis.yml b/workbench/airavata/wsis/.travis.yml new file mode 100755 index 000000000..f60bbe00a --- /dev/null +++ b/workbench/airavata/wsis/.travis.yml @@ -0,0 +1,13 @@ +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - hhvm + +before_script: + - travis_retry composer self-update + - travis_retry composer install --prefer-source --no-interaction --dev + +script: phpunit diff --git a/workbench/airavata/wsis/composer.json b/workbench/airavata/wsis/composer.json new file mode 100755 index 000000000..2af236e8b --- /dev/null +++ b/workbench/airavata/wsis/composer.json @@ -0,0 +1,20 @@ +{ + "name": "airavata/wsis", + "description": "", + "authors": [ + { + "name": "Apache Airavata", + "email": "dev@airavata.apache.org" + } + ], + "require": { + "php": ">=5.4.0", + "illuminate/support": "4.2.*" + }, + "autoload": { + "psr-0": { + "Airavata\\Wsis": "src/" + } + }, + "minimum-stability": "stable" +} diff --git a/workbench/airavata/wsis/phpunit.xml b/workbench/airavata/wsis/phpunit.xml new file mode 100755 index 000000000..3347b75b7 --- /dev/null +++ b/workbench/airavata/wsis/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + diff --git a/workbench/airavata/wsis/src/Airavata/Wsis/Facades/Wsis.php b/workbench/airavata/wsis/src/Airavata/Wsis/Facades/Wsis.php new file mode 100755 index 000000000..d89bc7c4f --- /dev/null +++ b/workbench/airavata/wsis/src/Airavata/Wsis/Facades/Wsis.php @@ -0,0 +1,16 @@ + array( 'verify_peer' => $verify_peer, "allow_self_signed"=> $allow_selfsigned_cert, 'cafile' => $cafile_path, 'CN_match' => $server, - ))); + ) + )); $parameters = array( 'login' => $admin_username, @@ -62,7 +60,7 @@ public function __construct($admin_username, $admin_password = null, $server, $this->server = $server; $this->service_url = $service_url; - + try { $this->userStoreManager = new UserStoreManager($service_url, $parameters); } catch (Exception $ex) { @@ -71,10 +69,10 @@ public function __construct($admin_username, $admin_password = null, $server, } } - + /** * Function to add new user - * + * * @param string $userName * @param string $password * @return void @@ -87,10 +85,10 @@ public function addUser($userName, $password, $fullName) { throw new Exception("Unable to add new user", 0, $ex); } } - + /** * Function to delete existing user - * + * * @param string $username * @return void * @throws Exception @@ -103,10 +101,10 @@ public function deleteUser($username) { } } - + /** * Function to authenticate user - * + * * @param string $username * @param string $password * @return boolean @@ -120,10 +118,10 @@ public function authenticate($username, $password){ throw new Exception("Unable to authenticate user", 0, $ex); } } - + /** * Function to check whether username exists - * + * * @param string $username * @return boolean * @throws Exception @@ -137,9 +135,9 @@ public function username_exists($username){ } /** - * Function to check whether a role is existing + * Function to check whether a role is existing * - * @param string $roleName + * @param string $roleName * @return IsExistingRoleResponse */ public function is_existing_role( $roleName){ @@ -152,7 +150,7 @@ public function is_existing_role( $roleName){ /** * Function to add new role by providing the role name. - * + * * @param string $roleName */ public function add_role($roleName){ @@ -165,7 +163,7 @@ public function add_role($roleName){ /** * Function to delete existing role - * + * * @param string $roleName * @return void * @throws Exception @@ -174,17 +172,17 @@ public function delete_role($roleName) { try { $this->userStoreManager->deleteRole($roleName); } catch (Exception $ex) { - var_dump( $ex); exit; + var_dump( $ex); exit; throw new Exception("Unable to delete role", 0, $ex); } } - + /** - * Function to get the list of all existing roles - * - * @return roles list - */ + * Function to get the list of all existing roles + * + * @return roles list + */ public function get_all_roles(){ try { return $this->userStoreManager->getRoleNames(); @@ -194,10 +192,10 @@ public function get_all_roles(){ } /** - * Function to get role of a user - * - * @return user role - */ + * Function to get role of a user + * + * @return user role + */ public function get_user_roles( $username){ try { return $this->userStoreManager->getRoleListOfUser( $username); @@ -218,11 +216,11 @@ public function get_userlist_of_role( $role){ } catch (Exception $ex) { var_dump( $ex); exit; throw new Exception("Unable to get user list of roles.", 0, $ex); - } + } } /** - * Function to update role list of user + * Function to update role list of user * * @param UpdateRoleListOfUser $parameters * @return void @@ -245,7 +243,7 @@ public function list_users(){ try { return $this->userStoreManager->listUsers(); } catch (Exception $ex) { - var_dump( $ex->debug_message); + var_dump( $ex->debug_message); throw new Exception("Unable to list users.", 0, $ex); } } @@ -260,23 +258,23 @@ public function get_tenant_id(){ try { return $this->userStoreManager->getTenantId(); } catch (Exception $ex) { - var_dump( $ex->debug_message); + var_dump( $ex->debug_message); throw new Exception("Unable to get the tenant Id.", 0, $ex); } } /** - * Function create a new Tenant - * - * @param Tenant $parameters - * @return void - */ + * Function create a new Tenant + * + * @param Tenant $parameters + * @return void + */ public function create_tenant( $inputs){ try { return $this->userStoreManager->createTenant( $inputs); } catch (Exception $ex) { - var_dump( $ex); + var_dump( $ex); throw new Exception("Unable to create Tenant.", 0, $ex); } } -} +} \ No newline at end of file diff --git a/workbench/airavata/wsis/src/Airavata/Wsis/WsisServiceProvider.php b/workbench/airavata/wsis/src/Airavata/Wsis/WsisServiceProvider.php new file mode 100755 index 000000000..e5a2cf433 --- /dev/null +++ b/workbench/airavata/wsis/src/Airavata/Wsis/WsisServiceProvider.php @@ -0,0 +1,64 @@ +package('airavata/wsis'); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + //registering service provider + $this->app['wsis'] = $this->app->share(function($app) + { + return new Wsis( + Config::get('wsis::admin-username'), + Config::get('wsis::admin-password'), + Config::get('wsis::server'), + Config::get('wsis::service-url'), + Config::get('wsis::cafile-path'), + Config::get('wsis::verify-peer'), + Config::get('wsis::allow-selfsigned-cert') + ); + }); + + //registering alis + $this->app->booting(function() + { + $loader = \Illuminate\Foundation\AliasLoader::getInstance(); + $loader->alias('WSIS', 'Airavata\Wsis\Facades\Wsis'); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array('wsis'); + } + +} diff --git a/workbench/airavata/wsis/src/config/config.php b/workbench/airavata/wsis/src/config/config.php new file mode 100644 index 000000000..69f61cf7c --- /dev/null +++ b/workbench/airavata/wsis/src/config/config.php @@ -0,0 +1,52 @@ + 'admin', + + /** + * Gateway user role + */ + 'gateway-admin' => 'Internal/everyone', + + /** + * Tenant admin's username + */ + 'admin-username' => 'admin-username', + + /** + * Tenant admin's password + */ + 'admin-password' => 'admin-password', + + /** + * Identity server domain + */ + 'server' => 'idp.scigap.org', + + /** + * Identity server web services endpoint + */ + 'service-url' => 'https://idp.scigap.org:7443/services/', + + /** + * Gateway domain name + */ + 'gateway-id' => 'default', + + /** + * Path to the server certificate file + */ + 'cafile-path' => app_path() . '/resources/security/idp_scigap_org.pem', + + /** + * Enable HTTPS server verification + */ + 'verify-peer' => true, + + /** + * Allow self signed server certificates + */ + 'allow-self-signed' => false +); \ No newline at end of file diff --git a/workbench/airavata/wsis/tests/.gitkeep b/workbench/airavata/wsis/tests/.gitkeep new file mode 100755 index 000000000..e69de29bb From 244cb4b8f214c3a844a67d217207b5900f742678 Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Sun, 3 May 2015 14:43:29 +0530 Subject: [PATCH 2/2] adding package configurations --- app/config/packages/airavata/wsis/config.php | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/config/packages/airavata/wsis/config.php diff --git a/app/config/packages/airavata/wsis/config.php b/app/config/packages/airavata/wsis/config.php new file mode 100644 index 000000000..9041036b0 --- /dev/null +++ b/app/config/packages/airavata/wsis/config.php @@ -0,0 +1,52 @@ + 'admin', + + /** + * Gateway user role + */ + 'gateway-admin' => 'Internal/everyone', + + /** + * Tenant admin's username + */ + 'admin-username' => 'test@testphprg.scigap.org', + + /** + * Tenant admin's password + */ + 'admin-password' => 'testadmin@scigap.org', + + /** + * Identity server domain + */ + 'server' => 'idp.scigap.org', + + /** + * Identity server web services endpoint + */ + 'service-url' => 'https://idp.scigap.org:7443/services/', + + /** + * Gateway domain name + */ + 'gateway-id' => 'default', + + /** + * Path to the server certificate file + */ + 'cafile-path' => app_path() . '/resources/security/idp_scigap_org.pem', + + /** + * Enable HTTPS server verification + */ + 'verify-peer' => true, + + /** + * Allow self signed server certificates + */ + 'allow-self-signed' => false +); \ No newline at end of file