You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2017/06/23 13:25:53 UTC

airavata-php-gateway git commit: AIRAVATA-2403 Wrapping IamAdminServices calls in utility class

Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop ece3d216e -> 41e471b02


AIRAVATA-2403 Wrapping IamAdminServices calls in utility class


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/41e471b0
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/41e471b0
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/41e471b0

Branch: refs/heads/develop
Commit: 41e471b021f1a82bccc91c67fe82d8c404ae2270
Parents: ece3d21
Author: Marcus Christie <ma...@iu.edu>
Authored: Fri Jun 23 09:25:23 2017 -0400
Committer: Marcus Christie <ma...@iu.edu>
Committed: Fri Jun 23 09:25:23 2017 -0400

----------------------------------------------------------------------
 app/controllers/AccountController.php       | 26 +++---------------
 app/libraries/IamAdminServicesUtilities.php | 34 ++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/41e471b0/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index 6742fb2..425d71e 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -48,14 +48,10 @@ class AccountController extends BaseController
                 ->with("username_exists", true);
         } else {
 
-            $admin_authz_token = Keycloak::getAdminAuthzToken();
-
-            IamAdminServices::registerUser($admin_authz_token, $username, $email, $first_name, $last_name, $password);
-
-            /*add user to the initial role */
+            IamAdminServicesUtilities::registerUser($username, $email, $first_name, $last_name, $password);
 
             // add user to initial role
-            $this->addUserToInitialRole($username);
+            IamAdminServicesUtilities::addInitialRoleToUser($username);
             // Send account confirmation email
             EmailUtilities::sendVerifyEmailAccount($username, $first_name, $last_name, $email);
 
@@ -64,16 +60,6 @@ class AccountController extends BaseController
         }
     }
 
-    private function addUserToInitialRole($username) {
-
-        $admin_authz_token = Keycloak::getAdminAuthzToken();
-        $initialRoleName = CommonUtilities::getInitialRoleName();
-        IamAdminServices::addRoleToUser($admin_authz_token, $username, $initialRoleName);
-        if(  Config::get('pga_config.portal')['super-admin-portal'] == true ){
-            IamAdminServices::addRoleToUser($admin_authz_token, $username, "gateway-provider");
-        }
-    }
-
     public function loginView()
     {
         if(Config::get('pga_config.wsis')['oauth-grant-type'] == "authorization_code"){
@@ -350,8 +336,7 @@ class AccountController extends BaseController
                         . "you should be receiving soon.");
                     return View::make("home");
                 }
-                $admin_authz_token = Keycloak::getAdminAuthzToken();
-                $result = IamAdminServices::enableUser($admin_authz_token, $username);
+                $result = IamAdminServicesUtilities::enableUser($username);
                 if($result){
                     $this->sendAccountCreationNotification2Admin($username);
                     return Redirect::to("login")->with("account-created-success", "Your account has been successfully created. Please log in now.");
@@ -437,10 +422,7 @@ class AccountController extends BaseController
                 return Redirect::to("forgot-password")->with("password-reset-error", "Resetting user password operation failed. Please request to reset user password again.");
             }
 
-            $admin_authz_token = Keycloak::getAdminAuthzToken();
-            $tenant_id = Config::get('pga_config.wsis')['tenant-domain'];
-
-            $result = IamAdminServices::resetUserPassword($admin_authz_token, $tenant_id, $username, $new_password);
+            $result = IamAdminServicesUtilities::resetUserPassword($username, $new_password);
             if($result){
                 return Redirect::to("login")->with("password-reset-success", "User password was reset successfully");
             }else{

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/41e471b0/app/libraries/IamAdminServicesUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/IamAdminServicesUtilities.php b/app/libraries/IamAdminServicesUtilities.php
new file mode 100644
index 0000000..d5e20ea
--- /dev/null
+++ b/app/libraries/IamAdminServicesUtilities.php
@@ -0,0 +1,34 @@
+<?php
+
+class IamAdminServicesUtilities {
+
+    public static function registerUser($username, $email, $first_name, $last_name, $password) {
+
+        $admin_authz_token = IamAdminServicesUtilities::getAdminAuthzToken();
+        return IamAdminServices::registerUser($admin_authz_token, $username, $email, $first_name, $last_name, $password);
+    }
+
+    public static function addInitialRoleToUser($username) {
+
+        $admin_authz_token = IamAdminServicesUtilities::getAdminAuthzToken();
+        $initialRoleName = CommonUtilities::getInitialRoleName();
+        IamAdminServices::addRoleToUser($admin_authz_token, $username, $initialRoleName);
+    }
+
+    public static function enableUser($username) {
+
+        $admin_authz_token = IamAdminServicesUtilities::getAdminAuthzToken();
+        return IamAdminServices::enableUser($admin_authz_token, $username);
+    }
+
+    public static function resetUserPassword($username, $new_password) {
+
+        $admin_authz_token = IamAdminServicesUtilities::getAdminAuthzToken();
+        return IamAdminServices::resetUserPassword($admin_authz_token, $username, $new_password);
+    }
+
+    private static function getAdminAuthzToken() {
+        return Keycloak::getAdminAuthzToken();
+    }
+}
+ ?>
\ No newline at end of file