You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2015/05/09 15:11:55 UTC
[3/8] airavata-php-gateway git commit: wrapping Airavata and WSIS
code as laravel library component and service providers
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/3ca02155/app/libraries/Wsis/Wsis.php
----------------------------------------------------------------------
diff --git a/app/libraries/Wsis/Wsis.php b/app/libraries/Wsis/Wsis.php
new file mode 100755
index 0000000..ede9774
--- /dev/null
+++ b/app/libraries/Wsis/Wsis.php
@@ -0,0 +1,280 @@
+<?php
+
+namespace Wsis;
+
+use Illuminate\Support\Facades\Config;
+use Wsis\Stubs\UserStoreManager;
+
+class Wsis {
+
+ /**
+ * @var UserStoreManager
+ * @access private
+ */
+ private $userStoreManager;
+
+ /**
+ * @var string
+ * @access private
+ */
+ private $server;
+
+ /**
+ * @var string
+ * @access private
+ */
+ private $service_url;
+
+
+ /**
+ * Constructor
+ *
+ * @param string $admin_username
+ * @param string $admin_password
+ * @param string $server
+ * @param string $service_url
+ * @param string $cafile_path
+ * @param bool $verify_peer
+ * @param bool $allow_selfsigned_cer
+ * @throws Exception
+ */
+ public function __construct($admin_username, $admin_password = null, $server,
+ $service_url,$cafile_path, $verify_peer, $allow_selfsigned_cert) {
+
+ $context = stream_context_create(array(
+ 'ssl' => array(
+ 'verify_peer' => $verify_peer,
+ "allow_self_signed"=> $allow_selfsigned_cert,
+ 'cafile' => $cafile_path,
+ 'CN_match' => $server,
+ )
+ ));
+
+ $parameters = array(
+ 'login' => $admin_username,
+ 'password' => $admin_password,
+ 'stream_context' => $context,
+ 'trace' => 1,
+ 'features' => SOAP_WAIT_ONE_WAY_CALLS
+ );
+
+ $this->server = $server;
+ $this->service_url = $service_url;
+
+ try {
+ $this->userStoreManager = new UserStoreManager($service_url, $parameters);
+ } catch (Exception $ex) {
+ print_r( $ex); exit;
+ throw new Exception("Unable to instantiate client", 0, $ex);
+ }
+ }
+
+
+ /**
+ * Function to add new user
+ *
+ * @param string $userName
+ * @param string $password
+ * @return void
+ * @throws Exception
+ */
+ public function addUser($userName, $password, $fullName) {
+ try {
+ $this->userStoreManager->addUser($userName, $password, $fullName);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to add new user", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to delete existing user
+ *
+ * @param string $username
+ * @return void
+ * @throws Exception
+ */
+ public function deleteUser($username) {
+ try {
+ $this->userStoreManager->deleteUser($username);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to delete user", 0, $ex);
+ }
+ }
+
+
+ /**
+ * Function to authenticate user
+ *
+ * @param string $username
+ * @param string $password
+ * @return boolean
+ * @throws Exception
+ */
+ public function authenticate($username, $password){
+ try {
+ return $this->userStoreManager->authenticate($username, $password);
+ } catch (Exception $ex) {
+ var_dump( $ex); exit;
+ throw new Exception("Unable to authenticate user", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to check whether username exists
+ *
+ * @param string $username
+ * @return boolean
+ * @throws Exception
+ */
+ public function username_exists($username){
+ try {
+ return $this->userStoreManager->isExistingUser($username);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to verify username exists", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to check whether a role is existing
+ *
+ * @param string $roleName
+ * @return IsExistingRoleResponse
+ */
+ public function is_existing_role( $roleName){
+ try {
+ return $this->userStoreManager->isExistingRole( $roleName);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to check if the role exists", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to add new role by providing the role name.
+ *
+ * @param string $roleName
+ */
+ public function add_role($roleName){
+ try {
+ return $this->userStoreManager->addRole( $roleName);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to add this role", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to delete existing role
+ *
+ * @param string $roleName
+ * @return void
+ * @throws Exception
+ */
+ public function delete_role($roleName) {
+ try {
+ $this->userStoreManager->deleteRole($roleName);
+ } catch (Exception $ex) {
+ 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
+ */
+ public function get_all_roles(){
+ try {
+ return $this->userStoreManager->getRoleNames();
+ } catch (Exception $ex) {
+ throw new Exception("Unable to get all roles", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to get role of a user
+ *
+ * @return user role
+ */
+ public function get_user_roles( $username){
+ try {
+ return $this->userStoreManager->getRoleListOfUser( $username);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to get User roles.", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to get the user list of role
+ *
+ * @param GetUserListOfRole $parameters
+ * @return GetUserListOfRoleResponse
+ */
+ public function get_userlist_of_role( $role){
+ try {
+ return $this->userStoreManager->getUserListOfRole( $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
+ *
+ * @param UpdateRoleListOfUser $parameters
+ * @return void
+ */
+ public function update_user_roles( $username, $roles){
+ try {
+ return $this->userStoreManager->updateRoleListOfUser( $username, $roles);
+ } catch (Exception $ex) {
+ throw new Exception("Unable to update role of the user.", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to list users
+ *
+ * @param void
+ * @return void
+ */
+ public function list_users(){
+ try {
+ return $this->userStoreManager->listUsers();
+ } catch (Exception $ex) {
+ var_dump( $ex->debug_message);
+ throw new Exception("Unable to list users.", 0, $ex);
+ }
+ }
+
+ /**
+ * Function to get the tenant id
+ *
+ * @param GetTenantId $parameters
+ * @return GetTenantIdResponse
+ */
+ public function get_tenant_id(){
+ try {
+ return $this->userStoreManager->getTenantId();
+ } catch (Exception $ex) {
+ 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
+ */
+ public function create_tenant( $inputs){
+ try {
+ return $this->userStoreManager->createTenant( $inputs);
+ } catch (Exception $ex) {
+ var_dump( $ex);
+ throw new Exception("Unable to create Tenant.", 0, $ex);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/3ca02155/app/libraries/Wsis/WsisServiceProvider.php
----------------------------------------------------------------------
diff --git a/app/libraries/Wsis/WsisServiceProvider.php b/app/libraries/Wsis/WsisServiceProvider.php
new file mode 100755
index 0000000..b3533a4
--- /dev/null
+++ b/app/libraries/Wsis/WsisServiceProvider.php
@@ -0,0 +1,64 @@
+<?php namespace Wsis;
+
+use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\Config;
+
+class WsisServiceProvider extends ServiceProvider {
+
+ /**
+ * Indicates if loading of the provider is deferred.
+ *
+ * @var bool
+ */
+ protected $defer = false;
+
+ /**
+ * Bootstrap the application events.
+ *
+ * @return void
+ */
+ public function boot()
+ {
+ $this->package('wsis/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('pga_config.wsis')['admin-username'],
+ Config::get('pga_config.wsis')['admin-password'],
+ Config::get('pga_config.wsis')['server'],
+ Config::get('pga_config.wsis')['service-url'],
+ Config::get('pga_config.wsis')['cafile-path'],
+ Config::get('pga_config.wsis')['verify-peer'],
+ Config::get('pga_config.wsis')['allow-self-signed-cert']
+ );
+ });
+
+ //registering alis
+ $this->app->booting(function()
+ {
+ $loader = \Illuminate\Foundation\AliasLoader::getInstance();
+ $loader->alias('WSIS', 'Wsis\Facades\Wsis');
+ });
+ }
+
+ /**
+ * Get the services provided by the provider.
+ *
+ * @return array
+ */
+ public function provides()
+ {
+ return array('wsis');
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/3ca02155/app/libraries/XmlIdUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/XmlIdUtilities.php b/app/libraries/XmlIdUtilities.php
new file mode 100755
index 0000000..5580796
--- /dev/null
+++ b/app/libraries/XmlIdUtilities.php
@@ -0,0 +1,292 @@
+<?php
+/**
+ * Utilities for ID management with an XML file
+ */
+
+class XmlIdUtilities implements IdUtilities
+{
+ const DB_PATH = 'users.xml';
+
+ /**
+ * Connect to the user database.
+ * @return mixed|void
+ */
+ public function connect()
+ {
+ global $db;
+
+
+ try
+ {
+ if (file_exists(self::DB_PATH))
+ {
+ $db = simplexml_load_file(self::DB_PATH);
+ }
+ else
+ {
+ throw new Exception("Error: Cannot connect to database!");
+ }
+
+
+ if (!$db)
+ {
+ throw new Exception('Error: Cannot open database!');
+ }
+ }
+ catch (Exception $e)
+ {
+ echo '<div>' . $e->getMessage() . '</div>';
+ }
+ }
+
+ /**
+ * Return true if the given username exists in the database.
+ * @param $username
+ * @return bool
+ */
+ public function username_exists($username)
+ {
+ global $db;
+
+ foreach($db->xpath('//username') as $db_username)
+ {
+ if ($db_username == $username)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Authenticate the user given username and password.
+ * @param $username
+ * @param $password
+ * @return int|mixed
+ */
+ public function authenticate($username, $password)
+ {
+ global $db;
+
+ $hashed_password = md5($password);
+
+ $user = $db->xpath('//user[username="' . $username . '"]');
+
+ if (sizeof($user) == 1)
+ {
+ return $user[0]->password_hash == $hashed_password;
+ }
+ elseif(sizeof($user) == 0)
+ {
+ return -1;
+ }
+ else // duplicate users in database
+ {
+ return -2;
+ }
+ }
+
+ /**
+ * Add a new user to the database.
+ * @param $username
+ * @param $password
+ * @return mixed|void
+ */
+ public function add_user($username, $password, $first_name, $last_name, $email, $organization,
+ $address, $country,$telephone, $mobile, $im, $url)
+ {
+ global $db;
+
+ $users = $db->xpath('//users');
+
+ $user = $users[0]->addChild('user');
+
+ $user->addChild('username', $username);
+ $user->addChild('password_hash', md5($password));
+
+ //Format XML to save indented tree rather than one line
+ $dom = new DOMDocument('1.0');
+ $dom->preserveWhiteSpace = false;
+ $dom->formatOutput = true;
+ $dom->loadXML($db->asXML());
+ $dom->save('users.xml');
+ }
+
+ /**
+ * Get the user profile
+ * @param $username
+ * @return mixed|void
+ */
+ public function get_user_profile($username)
+ {
+ // TODO: Implement get_user_profile() method.
+ }
+
+ /**
+ * 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)
+ {
+ // TODO: Implement update_user_profile() method.
+ }
+
+ /**
+ * Function to update user password
+ *
+ * @param $username
+ * @param $current_password
+ * @param $new_password
+ * @return mixed
+ */
+ public function change_password($username, $current_password, $new_password)
+ {
+ // TODO: Implement change_password() method.
+ }
+
+ /**
+ * Function to remove an existing user
+ *
+ * @param $username
+ * @return void
+ */
+ public function remove_user($username)
+ {
+ // TODO: Implement remove_user() method.
+ }
+
+ /**
+ * 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)
+ {
+ // TODO: Implement checkPermissionForUser() method.
+ }
+
+ /**
+ * Function to get all the permissions that a particular user has.
+ *
+ * @param $username
+ * @return mixed
+ */
+ public function getUserPermissions($username)
+ {
+ // TODO: Implement getUserPermissions() method.
+ }
+
+ /**
+ * Function to get the entire list of roles in the application
+ *
+ * @return mixed
+ */
+ public function getRoleList()
+ {
+ // TODO: Implement getRoleList() method.
+ }
+
+ /**
+ * Function to get the role list of a user
+ *
+ * @param $username
+ * @return mixed
+ */
+ public function getRoleListOfUser($username)
+ {
+ // TODO: Implement getRoleListOfUser() method.
+ }
+
+ /**
+ * Function to get the user list of a particular role
+ *
+ * @param $role
+ * @return mixed
+ */
+ public function getUserListOfRole($role)
+ {
+ // TODO: Implement getUserListOfRole() method.
+ }
+
+ /**
+ * Function to add a role to a user
+ *
+ * @param $username
+ * @param $role
+ * @return void
+ */
+ public function addUserToRole($username, $role)
+ {
+ // TODO: Implement addUserToRole() method.
+ }
+
+ /**
+ * Function to role from user
+ *
+ * @param $username
+ * @param $role
+ * @return void
+ */
+ 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.
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/3ca02155/app/libraries/id_utilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/id_utilities.php b/app/libraries/id_utilities.php
deleted file mode 100755
index 9db7450..0000000
--- a/app/libraries/id_utilities.php
+++ /dev/null
@@ -1,172 +0,0 @@
-<?php
-/**
- * Interface for ID management
- */
-
-interface IdUtilities
-{
- /**
- * Connect to the user database.
- * @return mixed|void
- */
- public function connect();
-
- /**
- * Return true if the given username exists in the database.
- * @param $username
- * @return bool
- */
- public function username_exists($username);
-
- /**
- * Authenticate user given username and password.
- * @param $username
- * @param $password
- * @return int|mixed
- */
- public function authenticate($username, $password);
-
- /**
- * Create new user
- *
- * @param $username
- * @param $password
- * @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 add_user($username, $password, $first_name, $last_name, $email, $organization,
- $address, $country,$telephone, $mobile, $im, $url);
-
- /**
- * Function to remove an existing user
- *
- * @param $username
- * @return void
- */
- public function remove_user($username);
-
- /**
- * Get the user profile
- * @param $username
- * @return mixed|void
- */
- public function get_user_profile($username);
-
- /**
- * 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);
-
- /**
- * Function to update user password
- *
- * @param $username
- * @param $current_password
- * @param $new_password
- * @return mixed
- */
- public function change_password($username, $current_password, $new_password);
-
- /**
- * 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);
-
- /**
- * Function to get all the permissions that a particular user has.
- *
- * @param $username
- * @return mixed
- */
- public function getUserPermissions($username);
-
- /**
- * Function to get the entire list of roles in the application
- *
- * @return mixed
- */
- public function getRoleNames();
-
- /**
- * Function to check whether a role is existing
- *
- * @param string $roleName
- * @return IsExistingRoleResponse
- */
- public function isExistingRole( $roleName);
-
- /**
- * Function to add new role by providing the role name.
- *
- * @param string $roleName
- */
- public function addRole($roleName);
-
- /**
- * Function to get the role list of a user
- *
- * @param $username
- * @return mixed
- */
- public function getRoleListOfUser($username);
- /**
- * Function to update role list of user
- *
- * @param UpdateRoleListOfUser $parameters
- * @return void
- */
- public function updateRoleListOfUser( $username, $roles);
-
- /**
- * Function to get the user list of a particular role
- *
- * @param $role
- * @return mixed
- */
- public function getUserListOfRole($role);
-
- /**
- * Function to add a role to a user
- *
- * @param $username
- * @param $role
- * @return void
- */
- public function addUserToRole($username, $role);
-
- /**
- * Function to role from user
- *
- * @param $username
- * @param $role
- * @return void
- */
- public function removeUserFromRole($username, $role);
-}
\ No newline at end of file